[1/3] nvmem: fix the out-of-range leak in read/write()
diff mbox

Message ID 1439176963-8969-2-git-send-email-zhengsq@rock-chips.com
State New
Headers show

Commit Message

Shunqian Zheng Aug. 10, 2015, 3:22 a.m. UTC
From: ZhengShunQian <zhengsq@rock-chips.com>

The position to read/write must be less than max
register size.

Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
---
 drivers/nvmem/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Srinivas Kandagatla Aug. 10, 2015, 8:49 a.m. UTC | #1
On 10/08/15 04:22, Shunqian Zheng wrote:
> From: ZhengShunQian <zhengsq@rock-chips.com>
>
> The position to read/write must be less than max
> register size.

>
> Signed-off-by: ZhengShunQian <zhengsq@rock-chips.com>
> ---
>   drivers/nvmem/core.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index d3c6676..f4af8e5 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -67,7 +67,7 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
>   	int rc;
>
>   	/* Stop the user from reading */
> -	if (pos > nvmem->size)
> +	if (pos >= nvmem->size)
>   		return 0;
>
>   	if (pos + count > nvmem->size)
> @@ -92,7 +92,7 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
>   	int rc;
>
>   	/* Stop the user from writing */
> -	if (pos > nvmem->size)
> +	if (pos >= nvmem->size)
>   		return 0;
>
>   	if (pos + count > nvmem->size)
>

This looks good,

Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

Patch
diff mbox

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index d3c6676..f4af8e5 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -67,7 +67,7 @@  static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
 	int rc;
 
 	/* Stop the user from reading */
-	if (pos > nvmem->size)
+	if (pos >= nvmem->size)
 		return 0;
 
 	if (pos + count > nvmem->size)
@@ -92,7 +92,7 @@  static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 	int rc;
 
 	/* Stop the user from writing */
-	if (pos > nvmem->size)
+	if (pos >= nvmem->size)
 		return 0;
 
 	if (pos + count > nvmem->size)