* [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument.
@ 2020-11-01 17:09 Harshal Chaudhari
2020-11-01 19:49 ` Arnd Bergmann
2020-11-09 17:12 ` Dragan Cvetic
0 siblings, 2 replies; 3+ messages in thread
From: Harshal Chaudhari @ 2020-11-01 17:09 UTC (permalink / raw)
To: gregkh, dragan.cvetic
Cc: derek.kiernan, arnd, michal.simek, linux-arm-kernel, linux-kernel
if (_IOC_TYPE(cmd) != PP_IOCTL)
return -ENOTTY;
Invalid ioctl command check normally performs by “default” case.
if (_IOC_DIR(cmd) != _IOC_NONE) {
argp = (void __user *)arg;
if (!argp)
return -EINVAL; }
And for checking ioctl arguments, copy_from_user()/copy_to_user()
checks are enough.
Signed-off-by: Harshal Chaudhari <harshalchau04@gmail.com>
---
drivers/misc/xilinx_sdfec.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index 92291292756a..ff104c894b3b 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -944,8 +944,8 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
unsigned long data)
{
struct xsdfec_dev *xsdfec;
- void __user *arg = NULL;
- int rval = -EINVAL;
+ void __user *arg = (void __user *)data;
+ int rval;
xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev);
@@ -956,16 +956,6 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
return -EPERM;
}
- if (_IOC_TYPE(cmd) != XSDFEC_MAGIC)
- return -ENOTTY;
-
- /* check if ioctl argument is present and valid */
- if (_IOC_DIR(cmd) != _IOC_NONE) {
- arg = (void __user *)data;
- if (!arg)
- return rval;
- }
-
switch (cmd) {
case XSDFEC_START_DEV:
rval = xsdfec_start(xsdfec);
@@ -1010,7 +1000,7 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
rval = xsdfec_is_active(xsdfec, (bool __user *)arg);
break;
default:
- /* Should not get here */
+ rval = -ENOTTY;
break;
}
return rval;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument.
2020-11-01 17:09 [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument Harshal Chaudhari
@ 2020-11-01 19:49 ` Arnd Bergmann
2020-11-09 17:12 ` Dragan Cvetic
1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2020-11-01 19:49 UTC (permalink / raw)
To: Harshal Chaudhari
Cc: gregkh, Dragan Cvetic, Derek Kiernan, Arnd Bergmann,
Michal Simek, Linux ARM, linux-kernel
On Sun, Nov 1, 2020 at 6:09 PM Harshal Chaudhari
<harshalchau04@gmail.com> wrote:
>
> if (_IOC_TYPE(cmd) != PP_IOCTL)
> return -ENOTTY;
>
> Invalid ioctl command check normally performs by “default” case.
>
> if (_IOC_DIR(cmd) != _IOC_NONE) {
> argp = (void __user *)arg;
> if (!argp)
> return -EINVAL; }
>
> And for checking ioctl arguments, copy_from_user()/copy_to_user()
> checks are enough.
>
> Signed-off-by: Harshal Chaudhari <harshalchau04@gmail.com>
Thanks for following up on this,
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument.
2020-11-01 17:09 [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument Harshal Chaudhari
2020-11-01 19:49 ` Arnd Bergmann
@ 2020-11-09 17:12 ` Dragan Cvetic
1 sibling, 0 replies; 3+ messages in thread
From: Dragan Cvetic @ 2020-11-09 17:12 UTC (permalink / raw)
To: Harshal Chaudhari, gregkh
Cc: Derek Kiernan, arnd, Michal Simek, linux-arm-kernel, linux-kernel
> -----Original Message-----
> From: Harshal Chaudhari <harshalchau04@gmail.com>
> Sent: Sunday 1 November 2020 17:10
> To: gregkh@linuxfoundation.org; Dragan Cvetic <draganc@xilinx.com>
> Cc: Derek Kiernan <dkiernan@xilinx.com>; arnd@arndb.de; Michal Simek <michals@xilinx.com>; linux-arm-
> kernel@lists.infradead.org; linux-kernel@vger.kernel.org
> Subject: [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument.
>
> if (_IOC_TYPE(cmd) != PP_IOCTL)
> return -ENOTTY;
>
> Invalid ioctl command check normally performs by “default” case.
>
> if (_IOC_DIR(cmd) != _IOC_NONE) {
> argp = (void __user *)arg;
> if (!argp)
> return -EINVAL; }
>
> And for checking ioctl arguments, copy_from_user()/copy_to_user()
> checks are enough.
>
> Signed-off-by: Harshal Chaudhari <harshalchau04@gmail.com>
> ---
> drivers/misc/xilinx_sdfec.c | 16 +++-------------
> 1 file changed, 3 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
> index 92291292756a..ff104c894b3b 100644
> --- a/drivers/misc/xilinx_sdfec.c
> +++ b/drivers/misc/xilinx_sdfec.c
> @@ -944,8 +944,8 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
> unsigned long data)
> {
> struct xsdfec_dev *xsdfec;
> - void __user *arg = NULL;
> - int rval = -EINVAL;
> + void __user *arg = (void __user *)data;
> + int rval;
>
> xsdfec = container_of(fptr->private_data, struct xsdfec_dev, miscdev);
>
> @@ -956,16 +956,6 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
> return -EPERM;
> }
>
> - if (_IOC_TYPE(cmd) != XSDFEC_MAGIC)
> - return -ENOTTY;
> -
> - /* check if ioctl argument is present and valid */
> - if (_IOC_DIR(cmd) != _IOC_NONE) {
> - arg = (void __user *)data;
> - if (!arg)
> - return rval;
> - }
> -
> switch (cmd) {
> case XSDFEC_START_DEV:
> rval = xsdfec_start(xsdfec);
> @@ -1010,7 +1000,7 @@ static long xsdfec_dev_ioctl(struct file *fptr, unsigned int cmd,
> rval = xsdfec_is_active(xsdfec, (bool __user *)arg);
> break;
> default:
> - /* Should not get here */
> + rval = -ENOTTY;
> break;
> }
> return rval;
> --
> 2.17.1
Acked-by: Dragan Cvetic <dragan.cvetic@xilinx.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-09 17:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01 17:09 [PATCH] misc: xilinx-sdfec: remove check for ioctl cmd and argument Harshal Chaudhari
2020-11-01 19:49 ` Arnd Bergmann
2020-11-09 17:12 ` Dragan Cvetic
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).