Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1633219 > unrolled thread
| Started by | Geliang Tang <geliangtang@gmail.com> |
|---|---|
| First post | 2017-04-29 03:50 +0200 |
| Last post | 2017-04-29 07:20 +0200 |
| Articles | 3 — 3 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.
[PATCH] staging: comedi: use memdup_user Geliang Tang <geliangtang@gmail.com> - 2017-04-29 03:50 +0200
Re: [PATCH] staging: comedi: use memdup_user Joe Perches <joe@perches.com> - 2017-04-29 04:00 +0200
Re: [PATCH] staging: comedi: use memdup_user Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-29 07:20 +0200
| From | Geliang Tang <geliangtang@gmail.com> |
|---|---|
| Date | 2017-04-29 03:50 +0200 |
| Subject | [PATCH] staging: comedi: use memdup_user |
| Message-ID | <tBpGh-7H8-3@gated-at.bofh.it> |
Use memdup_user() helper instead of open-coding to simplify the code.
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
drivers/staging/comedi/comedi_fops.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index f191c2a..4797c8f 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1450,22 +1450,14 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
return -EFAULT;
data = kmalloc_array(MAX_SAMPLES, sizeof(unsigned int), GFP_KERNEL);
- if (!data) {
- ret = -ENOMEM;
- goto error;
- }
-
- insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL);
- if (!insns) {
- ret = -ENOMEM;
- goto error;
- }
+ if (!data)
+ return -ENOMEM;
- if (copy_from_user(insns, insnlist.insns,
- sizeof(*insns) * insnlist.n_insns)) {
- dev_dbg(dev->class_dev, "copy_from_user failed\n");
- ret = -EFAULT;
- goto error;
+ insns = memdup_user(insnlist.insns, sizeof(*insns) * insnlist.n_insns);
+ if (IS_ERR(insns)) {
+ dev_dbg(dev->class_dev, "memdup_user failed\n");
+ kfree(data);
+ return PTR_ERR(insns);
}
for (i = 0; i < insnlist.n_insns; i++) {
--
2.9.3
[toc] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2017-04-29 04:00 +0200 |
| Message-ID | <tBpPX-7Lk-3@gated-at.bofh.it> |
| In reply to | #1633219 |
On Sat, 2017-04-29 at 09:45 +0800, Geliang Tang wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
While I doubt this is a problem, this loses
the multiplication overflow check for
sizeof(*insns) * insnlist.n_isns
> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
[]
> @@ -1450,22 +1450,14 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
> return -EFAULT;
>
> data = kmalloc_array(MAX_SAMPLES, sizeof(unsigned int), GFP_KERNEL);
> - if (!data) {
> - ret = -ENOMEM;
> - goto error;
> - }
> -
> - insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL);
> - if (!insns) {
> - ret = -ENOMEM;
> - goto error;
> - }
> + if (!data)
> + return -ENOMEM;
>
> - if (copy_from_user(insns, insnlist.insns,
> - sizeof(*insns) * insnlist.n_insns)) {
> - dev_dbg(dev->class_dev, "copy_from_user failed\n");
> - ret = -EFAULT;
> - goto error;
> + insns = memdup_user(insnlist.insns, sizeof(*insns) * insnlist.n_insns);
> + if (IS_ERR(insns)) {
> + dev_dbg(dev->class_dev, "memdup_user failed\n");
> + kfree(data);
> + return PTR_ERR(insns);
> }
>
> for (i = 0; i < insnlist.n_insns; i++) {
[toc] | [prev] | [next] | [standalone]
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2017-04-29 07:20 +0200 |
| Message-ID | <tBsXv-1PB-1@gated-at.bofh.it> |
| In reply to | #1633229 |
On Fri, Apr 28, 2017 at 06:53:32PM -0700, Joe Perches wrote: > On Sat, 2017-04-29 at 09:45 +0800, Geliang Tang wrote: > > Use memdup_user() helper instead of open-coding to simplify the code. > > While I doubt this is a problem, this loses > the multiplication overflow check for > sizeof(*insns) * insnlist.n_isns Yes it is a problem, we need that check. thanks, greg k-h
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web