Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1238266 > unrolled thread

[PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space

Started byJavier Martinez Canillas <javier@osg.samsung.com>
First post2015-10-02 15:50 +0200
Last post2015-10-02 20:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space Javier Martinez Canillas <javier@osg.samsung.com> - 2015-10-02 15:50 +0200
    Re: [PATCH 01/18] Input: joydev - use memdup_user() to duplicate  memory from user-space Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2015-10-02 20:30 +0200

#1238266 — [PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space

FromJavier Martinez Canillas <javier@osg.samsung.com>
Date2015-10-02 15:50 +0200
Subject[PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space
Message-ID<qf8SM-4YE-67@gated-at.bofh.it>
The memdup_user() helper function can be used to duplicate a memory region
from user-space to kernel-space. There is no need to open code the same
logic using kmalloc() and copy_from_user() instead. This was found with
make coccicheck that reported the following warning:

drivers/input/joydev.c:447:10-17: WARNING opportunity for memdup_user
drivers/input/joydev.c:483:10-17: WARNING opportunity for memdup_user

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
---

 drivers/input/joydev.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 6cb5a3e5f9a1..e3dcd4abae18 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -444,12 +444,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
 	len = min(len, sizeof(joydev->abspam));
 
 	/* Validate the map. */
-	abspam = kmalloc(len, GFP_KERNEL);
-	if (!abspam)
-		return -ENOMEM;
-
-	if (copy_from_user(abspam, argp, len)) {
-		retval = -EFAULT;
+	abspam = memdup_user(argp, len);
+	if (IS_ERR(abspam)) {
+		retval = PTR_ERR(abspam);
 		goto out;
 	}
 
@@ -480,12 +477,9 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
 	len = min(len, sizeof(joydev->keypam));
 
 	/* Validate the map. */
-	keypam = kmalloc(len, GFP_KERNEL);
-	if (!keypam)
-		return -ENOMEM;
-
-	if (copy_from_user(keypam, argp, len)) {
-		retval = -EFAULT;
+	keypam = memdup_user(argp, len);
+	if (IS_ERR(keypam)) {
+		retval = PTR_ERR(keypam);
 		goto out;
 	}
 
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1238509 — Re: [PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space

FromDmitry Torokhov <dmitry.torokhov@gmail.com>
Date2015-10-02 20:30 +0200
SubjectRe: [PATCH 01/18] Input: joydev - use memdup_user() to duplicate memory from user-space
Message-ID<qfdfH-2Wl-9@gated-at.bofh.it>
In reply to#1238266
On Fri, Oct 02, 2015 at 03:40:12PM +0200, Javier Martinez Canillas wrote:
> The memdup_user() helper function can be used to duplicate a memory region
> from user-space to kernel-space. There is no need to open code the same
> logic using kmalloc() and copy_from_user() instead. This was found with
> make coccicheck that reported the following warning:
> 
> drivers/input/joydev.c:447:10-17: WARNING opportunity for memdup_user
> drivers/input/joydev.c:483:10-17: WARNING opportunity for memdup_user
> 
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>

Applied, thank you.

> ---
> 
>  drivers/input/joydev.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
> index 6cb5a3e5f9a1..e3dcd4abae18 100644
> --- a/drivers/input/joydev.c
> +++ b/drivers/input/joydev.c
> @@ -444,12 +444,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
>  	len = min(len, sizeof(joydev->abspam));
>  
>  	/* Validate the map. */
> -	abspam = kmalloc(len, GFP_KERNEL);
> -	if (!abspam)
> -		return -ENOMEM;
> -
> -	if (copy_from_user(abspam, argp, len)) {
> -		retval = -EFAULT;
> +	abspam = memdup_user(argp, len);
> +	if (IS_ERR(abspam)) {
> +		retval = PTR_ERR(abspam);
>  		goto out;
>  	}
>  
> @@ -480,12 +477,9 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
>  	len = min(len, sizeof(joydev->keypam));
>  
>  	/* Validate the map. */
> -	keypam = kmalloc(len, GFP_KERNEL);
> -	if (!keypam)
> -		return -ENOMEM;
> -
> -	if (copy_from_user(keypam, argp, len)) {
> -		retval = -EFAULT;
> +	keypam = memdup_user(argp, len);
> +	if (IS_ERR(keypam)) {
> +		retval = PTR_ERR(keypam);
>  		goto out;
>  	}
>  
> -- 
> 2.4.3
> 

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web