Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1466683 > unrolled thread
| Started by | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| First post | 2016-08-19 23:10 +0200 |
| Last post | 2016-08-19 23:20 +0200 |
| Articles | 4 — 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.
[PATCH 0/2] mmc-block: Fine-tuning for mmc_blk_ioctl_copy_from_user() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-19 23:10 +0200
[PATCH 1/2] mmc-block: Use memdup_user() rather than duplicating its implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-19 23:20 +0200
Re: [PATCH 1/2] mmc-block: Use memdup_user() rather than duplicating its implementation walter harms <wharms@bfs.de> - 2016-08-20 11:30 +0200
[PATCH 2/2] mmc-block: Rename jump labels in mmc_blk_ioctl_copy_from_user() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-19 23:20 +0200
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-08-19 23:10 +0200 |
| Subject | [PATCH 0/2] mmc-block: Fine-tuning for mmc_blk_ioctl_copy_from_user() |
| Message-ID | <s7Zd8-2kq-35@gated-at.bofh.it> |
From: Markus Elfring <elfring@users.sourceforge.net> Date: Fri, 19 Aug 2016 23:00:23 +0200 A few update suggestions were taken into account from static source code analysis. Markus Elfring (2): Use memdup_user() Rename jump labels drivers/mmc/card/block.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) -- 2.9.3
[toc] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-08-19 23:20 +0200 |
| Subject | [PATCH 1/2] mmc-block: Use memdup_user() rather than duplicating its implementation |
| Message-ID | <s7ZmN-2og-5@gated-at.bofh.it> |
| In reply to | #1466683 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 19 Aug 2016 22:46:38 +0200
* Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.
This issue was detected by using the Coccinelle software.
* Delete the integer variable "err" then because the pointer
variable "idata" should be sufficient to handle return values alone
in this function.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/mmc/card/block.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 48a5dd7..6ce9492 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -337,22 +337,21 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
struct mmc_ioc_cmd __user *user)
{
struct mmc_blk_ioc_data *idata;
- int err;
idata = kmalloc(sizeof(*idata), GFP_KERNEL);
if (!idata) {
- err = -ENOMEM;
+ idata = ERR_PTR(-ENOMEM);
goto out;
}
if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
- err = -EFAULT;
+ idata = ERR_PTR(-EFAULT);
goto idata_err;
}
idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
- err = -EOVERFLOW;
+ idata = ERR_PTR(-EOVERFLOW);
goto idata_err;
}
@@ -361,26 +360,19 @@ 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)) {
+ idata = (void *) 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);
out:
- return ERR_PTR(err);
+ return idata;
}
static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
--
2.9.3
[toc] | [prev] | [next] | [standalone]
| From | walter harms <wharms@bfs.de> |
|---|---|
| Date | 2016-08-20 11:30 +0200 |
| Subject | Re: [PATCH 1/2] mmc-block: Use memdup_user() rather than duplicating its implementation |
| Message-ID | <s8aLf-16W-9@gated-at.bofh.it> |
| In reply to | #1466685 |
Am 19.08.2016 23:10, schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 19 Aug 2016 22:46:38 +0200
>
> * Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> This issue was detected by using the Coccinelle software.
>
> * Delete the integer variable "err" then because the pointer
> variable "idata" should be sufficient to handle return values alone
> in this function.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/mmc/card/block.c | 26 +++++++++-----------------
> 1 file changed, 9 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 48a5dd7..6ce9492 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -337,22 +337,21 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
> struct mmc_ioc_cmd __user *user)
> {
> struct mmc_blk_ioc_data *idata;
> - int err;
>
> idata = kmalloc(sizeof(*idata), GFP_KERNEL);
> if (!idata) {
> - err = -ENOMEM;
> + idata = ERR_PTR(-ENOMEM);
> goto out;
> }
>
> if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
> - err = -EFAULT;
> + idata = ERR_PTR(-EFAULT);
> goto idata_err;
> }
>
> idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
> if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
> - err = -EOVERFLOW;
> + idata = ERR_PTR(-EOVERFLOW);
> goto idata_err;
> }
>
> @@ -361,26 +360,19 @@ 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)) {
> + idata = (void *) 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);
> out:
> - return ERR_PTR(err);
> + return idata;
> }
This looks strange, returning a freed pointer is a bad idea. I suggest a
idata=NULL after kfree().
re,
wh
>
> static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-08-19 23:20 +0200 |
| Subject | [PATCH 2/2] mmc-block: Rename jump labels in mmc_blk_ioctl_copy_from_user() |
| Message-ID | <s7ZmN-2og-25@gated-at.bofh.it> |
| In reply to | #1466683 |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 19 Aug 2016 22:52:50 +0200
Adjust jump targets according to the Linux coding style convention.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/mmc/card/block.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 6ce9492..0d83c56 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -346,13 +346,13 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
idata = ERR_PTR(-EFAULT);
- goto idata_err;
+ goto free_idata;
}
idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
idata = ERR_PTR(-EOVERFLOW);
- goto idata_err;
+ goto free_idata;
}
if (!idata->buf_bytes) {
@@ -365,11 +365,11 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
idata->buf_bytes);
if (IS_ERR(idata->buf)) {
idata = (void *) idata->buf;
- goto idata_err;
+ goto free_idata;
}
return idata;
-idata_err:
+free_idata:
kfree(idata);
out:
return idata;
--
2.9.3
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web