From: David Laight <David.Laight@ACULAB.COM>
To: 'Arnd Bergmann' <arnd@kernel.org>,
harshal chaudhari <harshalchau04@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] char: ppdev: check if ioctl argument is present and valid
Date: Sat, 24 Oct 2020 21:22:20 +0000 [thread overview]
Message-ID: <4b1b1656d0be452a80f2f81f98e79e24@AcuMS.aculab.com> (raw)
In-Reply-To: <CAK8P3a0y5MjP7AXOpmqc7xpGFCSvTGWHPT_eev5OpJJGVcRVdA@mail.gmail.com>
From: Arnd Bergmann
> Sent: 24 October 2020 20:21
> To: harshal chaudhari <harshalchau04@gmail.com>
> Cc: David Laight <David.Laight@ACULAB.COM>; Greg KH <gregkh@linuxfoundation.org>; Sudip Mukherjee
> <sudipm.mukherjee@gmail.com>; linux-kernel <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH] char: ppdev: check if ioctl argument is present and valid
>
> On Sat, Oct 24, 2020 at 5:54 PM harshal chaudhari
> <harshalchau04@gmail.com> wrote:
> > On Tue, Oct 13, 2020 at 4:42 PM David Laight <David.Laight@aculab.com> wrote:
>
> > So I am a little bit confused about this check whether it's required or not
> > Please could you point me in the right direction?
> >
> > In any case, thanks for your help ...
> >
> > Here is a driver source located in: linux/drivers/misc/xilinx_sdfec.c
> >
> > 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;
> >
> > 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;
> > }
> >
>
> All of this can be removed, and replaced with unconditional
>
> void __user *arg = (void __user *)data;
> int rval;
>
> with an "rval = -ENOTTY" added in the 'default' case. This will
> make it behave more like other drivers, returning -ENOTTY for
> any unknown ioctl command, and returning -EFAULT for all
> invalid pointers, including NULL.
Yep, the thing to remember is that even if you actually
verified that the user buffer could be accessed on entry
to the ioctl code another application thread could unmap
the memory area before you do a later access.
What you may want to do is copy the user buffer into a
kernel buffer at the top of the ioctl code and write it
back at the bottom.
But do make absolutely sure you don't overflow the kernel
buffer of access beyond its end.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2020-10-24 21:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-08 18:27 Harshal Chaudhari
2020-10-08 19:35 ` Arnd Bergmann
2020-10-09 4:57 ` Greg KH
2020-10-10 0:08 ` Sudip Mukherjee
2020-10-10 9:10 ` Sudip Mukherjee
2020-10-13 9:01 ` harshal chaudhari
2020-10-13 10:58 ` Greg KH
2020-10-13 11:12 ` David Laight
[not found] ` <CAFEvwu=76mPtXSEgpwSoRC0rC0tkU5BiEx1X5O2VwVSPJ7m4Rw@mail.gmail.com>
2020-10-24 19:21 ` Arnd Bergmann
2020-10-24 20:16 ` harshal chaudhari
2020-10-24 21:22 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4b1b1656d0be452a80f2f81f98e79e24@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=arnd@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=harshalchau04@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sudipm.mukherjee@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome