* [PATCH] KEYS: use memdup_user
@ 2017-05-13 3:15 Geliang Tang
2017-05-13 3:15 ` [PATCH] mmc: block: " Geliang Tang
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Geliang Tang @ 2017-05-13 3:15 UTC (permalink / raw)
To: David Howells, James Morris, Serge E. Hallyn
Cc: Geliang Tang, keyrings, linux-security-module, linux-kernel
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
security/keys/keyctl.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index dd0da25..ce1574a 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -326,14 +326,11 @@ long keyctl_update_key(key_serial_t id,
/* pull the payload in if one was supplied */
payload = NULL;
if (_payload) {
- ret = -ENOMEM;
- payload = kmalloc(plen, GFP_KERNEL);
- if (!payload)
+ payload = memdup_user(_payload, plen);
+ if (IS_ERR(payload)) {
+ ret = PTR_ERR(payload);
goto error;
-
- ret = -EFAULT;
- if (copy_from_user(payload, _payload, plen) != 0)
- goto error2;
+ }
}
/* find the target key (which must be writable) */
--
2.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] mmc: block: use memdup_user
2017-05-13 3:15 [PATCH] KEYS: use memdup_user Geliang Tang
@ 2017-05-13 3:15 ` Geliang Tang
2017-05-19 7:43 ` Ulf Hansson
2017-05-13 3:15 ` [PATCH] usb: gadget: f_fs: " Geliang Tang
2017-05-13 3:16 ` [PATCH] USB: iowarrior: " Geliang Tang
2 siblings, 1 reply; 9+ messages in thread
From: Geliang Tang @ 2017-05-13 3:15 UTC (permalink / raw)
To: Ulf Hansson, Linus Walleij, Adrian Hunter, Shawn Lin, Jens Axboe
Cc: Geliang Tang, linux-mmc, linux-kernel
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
drivers/mmc/core/block.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 8273b07..47ccb2a 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -342,21 +342,15 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
return idata;
}
- idata->buf = kmalloc(idata->buf_bytes, GFP_KERNEL);
- if (!idata->buf) {
- err = -ENOMEM;
+ idata->buf = memdup_user((void __user *)(unsigned long)
+ idata->ic.data_ptr, idata->buf_bytes);
+ if (IS_ERR(idata->buf)) {
+ err = PTR_ERR(idata->buf);
goto idata_err;
}
- if (copy_from_user(idata->buf, (void __user *)(unsigned long)
- idata->ic.data_ptr, idata->buf_bytes)) {
- err = -EFAULT;
- goto copy_err;
- }
-
return idata;
-copy_err:
kfree(idata->buf);
idata_err:
kfree(idata);
--
2.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] usb: gadget: f_fs: use memdup_user
2017-05-13 3:15 [PATCH] KEYS: use memdup_user Geliang Tang
2017-05-13 3:15 ` [PATCH] mmc: block: " Geliang Tang
@ 2017-05-13 3:15 ` Geliang Tang
2017-05-13 8:05 ` Dan Carpenter
2017-05-14 11:33 ` Michal Nazarewicz
2017-05-13 3:16 ` [PATCH] USB: iowarrior: " Geliang Tang
2 siblings, 2 replies; 9+ messages in thread
From: Geliang Tang @ 2017-05-13 3:15 UTC (permalink / raw)
To: Felipe Balbi, Greg Kroah-Hartman, Michal Nazarewicz,
Vincent Pelletier, Felix Hädicke, Dan Carpenter, Jim Lin
Cc: Geliang Tang, linux-usb, linux-kernel
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
drivers/usb/gadget/function/f_fs.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 71dd27c..5754538 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3692,14 +3692,9 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)
if (unlikely(!len))
return NULL;
- data = kmalloc(len, GFP_KERNEL);
- if (unlikely(!data))
- return ERR_PTR(-ENOMEM);
-
- if (unlikely(copy_from_user(data, buf, len))) {
- kfree(data);
- return ERR_PTR(-EFAULT);
- }
+ data = memdup_user(buf, len);
+ if (unlikely(IS_ERR(data)))
+ return data;
pr_vdebug("Buffer from user space:\n");
ffs_dump_mem("", data, len);
--
2.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] USB: iowarrior: use memdup_user
2017-05-13 3:15 [PATCH] KEYS: use memdup_user Geliang Tang
2017-05-13 3:15 ` [PATCH] mmc: block: " Geliang Tang
2017-05-13 3:15 ` [PATCH] usb: gadget: f_fs: " Geliang Tang
@ 2017-05-13 3:16 ` Geliang Tang
2017-05-15 10:14 ` Johan Hovold
2 siblings, 1 reply; 9+ messages in thread
From: Geliang Tang @ 2017-05-13 3:16 UTC (permalink / raw)
To: Greg Kroah-Hartman, Johan Hovold, Wolfram Sang
Cc: Geliang Tang, linux-usb, linux-kernel
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
drivers/usb/misc/iowarrior.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 7756953..816afad 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -368,14 +368,9 @@ static ssize_t iowarrior_write(struct file *file,
case USB_DEVICE_ID_CODEMERCS_IOWPV2:
case USB_DEVICE_ID_CODEMERCS_IOW40:
/* IOW24 and IOW40 use a synchronous call */
- buf = kmalloc(count, GFP_KERNEL);
- if (!buf) {
- retval = -ENOMEM;
- goto exit;
- }
- if (copy_from_user(buf, user_buffer, count)) {
- retval = -EFAULT;
- kfree(buf);
+ buf = memdup_user(user_buffer, count);
+ if (IS_ERR(buf)) {
+ retval = PTR_ERR(buf);
goto exit;
}
retval = usb_set_report(dev->interface, 2, 0, buf, count);
--
2.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: use memdup_user
2017-05-13 3:15 ` [PATCH] usb: gadget: f_fs: " Geliang Tang
@ 2017-05-13 8:05 ` Dan Carpenter
2017-05-21 3:25 ` Al Viro
2017-05-14 11:33 ` Michal Nazarewicz
1 sibling, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2017-05-13 8:05 UTC (permalink / raw)
To: Geliang Tang
Cc: Felipe Balbi, Greg Kroah-Hartman, Michal Nazarewicz,
Vincent Pelletier, Felix Hädicke, Jim Lin, linux-usb,
linux-kernel
On Sat, May 13, 2017 at 11:15:59AM +0800, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
> drivers/usb/gadget/function/f_fs.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 71dd27c..5754538 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3692,14 +3692,9 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)
> if (unlikely(!len))
> return NULL;
>
> - data = kmalloc(len, GFP_KERNEL);
> - if (unlikely(!data))
> - return ERR_PTR(-ENOMEM);
> -
> - if (unlikely(copy_from_user(data, buf, len))) {
> - kfree(data);
> - return ERR_PTR(-EFAULT);
> - }
> + data = memdup_user(buf, len);
> + if (unlikely(IS_ERR(data)))
Don't use likely/unlikely() here. It's not a fast path.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: use memdup_user
2017-05-13 3:15 ` [PATCH] usb: gadget: f_fs: " Geliang Tang
2017-05-13 8:05 ` Dan Carpenter
@ 2017-05-14 11:33 ` Michal Nazarewicz
1 sibling, 0 replies; 9+ messages in thread
From: Michal Nazarewicz @ 2017-05-14 11:33 UTC (permalink / raw)
To: Geliang Tang, Felipe Balbi, Greg Kroah-Hartman,
Vincent Pelletier, Felix Hädicke, Dan Carpenter, Jim Lin
Cc: Geliang Tang, linux-usb, linux-kernel
On Sat, May 13 2017, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
> ---
> drivers/usb/gadget/function/f_fs.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 71dd27c..5754538 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3692,14 +3692,9 @@ static char *ffs_prepare_buffer(const char __user *buf, size_t len)
> if (unlikely(!len))
> return NULL;
>
> - data = kmalloc(len, GFP_KERNEL);
> - if (unlikely(!data))
> - return ERR_PTR(-ENOMEM);
> -
> - if (unlikely(copy_from_user(data, buf, len))) {
> - kfree(data);
> - return ERR_PTR(-EFAULT);
> - }
> + data = memdup_user(buf, len);
> + if (unlikely(IS_ERR(data)))
> + return data;
>
> pr_vdebug("Buffer from user space:\n");
> ffs_dump_mem("", data, len);
--
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] USB: iowarrior: use memdup_user
2017-05-13 3:16 ` [PATCH] USB: iowarrior: " Geliang Tang
@ 2017-05-15 10:14 ` Johan Hovold
0 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2017-05-15 10:14 UTC (permalink / raw)
To: Geliang Tang
Cc: Greg Kroah-Hartman, Johan Hovold, Wolfram Sang, linux-usb, linux-kernel
On Sat, May 13, 2017 at 11:16:00AM +0800, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Looks good to me:
Reviewed-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/usb/misc/iowarrior.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
> index 7756953..816afad 100644
> --- a/drivers/usb/misc/iowarrior.c
> +++ b/drivers/usb/misc/iowarrior.c
> @@ -368,14 +368,9 @@ static ssize_t iowarrior_write(struct file *file,
> case USB_DEVICE_ID_CODEMERCS_IOWPV2:
> case USB_DEVICE_ID_CODEMERCS_IOW40:
> /* IOW24 and IOW40 use a synchronous call */
> - buf = kmalloc(count, GFP_KERNEL);
> - if (!buf) {
> - retval = -ENOMEM;
> - goto exit;
> - }
> - if (copy_from_user(buf, user_buffer, count)) {
> - retval = -EFAULT;
> - kfree(buf);
> + buf = memdup_user(user_buffer, count);
> + if (IS_ERR(buf)) {
> + retval = PTR_ERR(buf);
> goto exit;
> }
> retval = usb_set_report(dev->interface, 2, 0, buf, count);
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mmc: block: use memdup_user
2017-05-13 3:15 ` [PATCH] mmc: block: " Geliang Tang
@ 2017-05-19 7:43 ` Ulf Hansson
0 siblings, 0 replies; 9+ messages in thread
From: Ulf Hansson @ 2017-05-19 7:43 UTC (permalink / raw)
To: Geliang Tang
Cc: Linus Walleij, Adrian Hunter, Shawn Lin, Jens Axboe, linux-mmc,
linux-kernel
On 13 May 2017 at 05:15, Geliang Tang <geliangtang@gmail.com> wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
> drivers/mmc/core/block.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 8273b07..47ccb2a 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -342,21 +342,15 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
> return idata;
> }
>
> - idata->buf = kmalloc(idata->buf_bytes, GFP_KERNEL);
> - if (!idata->buf) {
> - err = -ENOMEM;
> + idata->buf = memdup_user((void __user *)(unsigned long)
> + idata->ic.data_ptr, idata->buf_bytes);
> + if (IS_ERR(idata->buf)) {
> + err = PTR_ERR(idata->buf);
> goto idata_err;
> }
>
> - if (copy_from_user(idata->buf, (void __user *)(unsigned long)
> - idata->ic.data_ptr, idata->buf_bytes)) {
> - err = -EFAULT;
> - goto copy_err;
> - }
> -
> return idata;
>
> -copy_err:
> kfree(idata->buf);
As we aren't using the copy_err label no more, you can also remove the
above line.
> idata_err:
> kfree(idata);
> --
> 2.9.3
>
Kind regards
Uffe
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: use memdup_user
2017-05-13 8:05 ` Dan Carpenter
@ 2017-05-21 3:25 ` Al Viro
0 siblings, 0 replies; 9+ messages in thread
From: Al Viro @ 2017-05-21 3:25 UTC (permalink / raw)
To: Dan Carpenter
Cc: Geliang Tang, Felipe Balbi, Greg Kroah-Hartman,
Michal Nazarewicz, Vincent Pelletier, Felix Hädicke,
Jim Lin, linux-usb, linux-kernel
On Sat, May 13, 2017 at 11:05:30AM +0300, Dan Carpenter wrote:
> > + data = memdup_user(buf, len);
> > + if (unlikely(IS_ERR(data)))
>
> Don't use likely/unlikely() here. It's not a fast path.
More to the point,
#define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
static inline bool __must_check IS_ERR(__force const void *ptr)
{
return IS_ERR_VALUE((unsigned long)ptr);
}
IOW, IS_ERR() already produces unlikely(....), fast path or not.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-05-21 3:26 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-13 3:15 [PATCH] KEYS: use memdup_user Geliang Tang
2017-05-13 3:15 ` [PATCH] mmc: block: " Geliang Tang
2017-05-19 7:43 ` Ulf Hansson
2017-05-13 3:15 ` [PATCH] usb: gadget: f_fs: " Geliang Tang
2017-05-13 8:05 ` Dan Carpenter
2017-05-21 3:25 ` Al Viro
2017-05-14 11:33 ` Michal Nazarewicz
2017-05-13 3:16 ` [PATCH] USB: iowarrior: " Geliang Tang
2017-05-15 10:14 ` Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).