|
| 1 | +From 413bcc259f0cf49b838dec8a6fdcaf7b9bfd663a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Zhen Kong < [email protected]> |
| 3 | +Date: Tue, 31 Jan 2017 12:07:10 -0800 |
| 4 | +Subject: [PATCH] crypto: msm: check length before copying to buf in |
| 5 | + _debug_stats_read |
| 6 | + |
| 7 | +Make sure that `len` is not larger than `count` before copying data |
| 8 | +to userspace `buf` in _debug_stats_read(). |
| 9 | + |
| 10 | +Change-Id: Ibea429889629916424f0e0a6e07c475f13de32c3 |
| 11 | +Signed-off-by: Zhen Kong < [email protected]> |
| 12 | +--- |
| 13 | + drivers/crypto/msm/ota_crypto.c | 8 ++++---- |
| 14 | + drivers/crypto/msm/qcedev.c | 4 ++-- |
| 15 | + drivers/crypto/msm/qcrypto.c | 6 +++--- |
| 16 | + 3 files changed, 9 insertions(+), 9 deletions(-) |
| 17 | + |
| 18 | +diff --git a/drivers/crypto/msm/ota_crypto.c b/drivers/crypto/msm/ota_crypto.c |
| 19 | +index 6ecf5b2b4cce..3f73c0b594d2 100644 |
| 20 | +--- a/drivers/crypto/msm/ota_crypto.c |
| 21 | ++++ b/drivers/crypto/msm/ota_crypto.c |
| 22 | +@@ -1,4 +1,4 @@ |
| 23 | +-/* Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. |
| 24 | ++/* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved. |
| 25 | + * |
| 26 | + * This program is free software; you can redistribute it and/or modify |
| 27 | + * it under the terms of the GNU General Public License version 2 and |
| 28 | +@@ -743,9 +743,9 @@ static ssize_t _debug_stats_read(struct file *file, char __user *buf, |
| 29 | + int rc = -EINVAL; |
| 30 | + int len; |
| 31 | + |
| 32 | +- len = _disp_stats(); |
| 33 | +- |
| 34 | +- rc = simple_read_from_buffer((void __user *) buf, len, |
| 35 | ++ len = _disp_stats(qcota); |
| 36 | ++ if (len <= count) |
| 37 | ++ rc = simple_read_from_buffer((void __user *) buf, len, |
| 38 | + ppos, (void *) _debug_read_buf, len); |
| 39 | + |
| 40 | + return rc; |
| 41 | +diff --git a/drivers/crypto/msm/qcedev.c b/drivers/crypto/msm/qcedev.c |
| 42 | +index 2c3eae74e2e8..e9dddaa377ea 100644 |
| 43 | +--- a/drivers/crypto/msm/qcedev.c |
| 44 | ++++ b/drivers/crypto/msm/qcedev.c |
| 45 | +@@ -2236,9 +2236,9 @@ static ssize_t _debug_stats_read(struct file *file, char __user *buf, |
| 46 | + |
| 47 | + len = _disp_stats(qcedev); |
| 48 | + |
| 49 | +- rc = simple_read_from_buffer((void __user *) buf, len, |
| 50 | ++ if (len <= count) |
| 51 | ++ rc = simple_read_from_buffer((void __user *) buf, len, |
| 52 | + ppos, (void *) _debug_read_buf, len); |
| 53 | +- |
| 54 | + return rc; |
| 55 | + } |
| 56 | + |
| 57 | +diff --git a/drivers/crypto/msm/qcrypto.c b/drivers/crypto/msm/qcrypto.c |
| 58 | +index eb4cb3a8a775..1bb06ea15cae 100644 |
| 59 | +--- a/drivers/crypto/msm/qcrypto.c |
| 60 | ++++ b/drivers/crypto/msm/qcrypto.c |
| 61 | +@@ -1,6 +1,6 @@ |
| 62 | + /* Qualcomm Crypto driver |
| 63 | + * |
| 64 | +- * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. |
| 65 | ++ * Copyright (c) 2010-2017, The Linux Foundation. All rights reserved. |
| 66 | + * |
| 67 | + * This program is free software; you can redistribute it and/or modify |
| 68 | + * it under the terms of the GNU General Public License version 2 and |
| 69 | +@@ -4771,9 +4771,9 @@ static ssize_t _debug_stats_read(struct file *file, char __user *buf, |
| 70 | + |
| 71 | + len = _disp_stats(qcrypto); |
| 72 | + |
| 73 | +- rc = simple_read_from_buffer((void __user *) buf, len, |
| 74 | ++ if (len <= count) |
| 75 | ++ rc = simple_read_from_buffer((void __user *) buf, len, |
| 76 | + ppos, (void *) _debug_read_buf, len); |
| 77 | +- |
| 78 | + return rc; |
| 79 | + } |
| 80 | + |
| 81 | +-- |
| 82 | +2.13.3 |
| 83 | + |
0 commit comments