From: Ben Hutchings <ben.hutchings@codethink.co.uk>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
y2038 Mailman List <y2038@lists.linaro.org>,
Linux FS-devel Mailing List <linux-fsdevel@vger.kernel.org>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [Y2038] [PATCH v6 10/43] compat_ioctl: move rtc handling into rtc-dev.c
Date: Thu, 17 Oct 2019 19:19:26 +0100 [thread overview]
Message-ID: <52d2fdbd514d93cdd901c18afbb83be13145de6f.camel@codethink.co.uk> (raw)
In-Reply-To: <CAK8P3a0BYkPTSnQUmde2k+HVcg7XNihzWTEzrCD4d8G8ecO9-w@mail.gmail.com>
On Thu, 2019-10-17 at 16:33 +0200, Arnd Bergmann wrote:
> On Thu, Oct 17, 2019 at 3:42 PM Ben Hutchings
> <ben.hutchings@codethink.co.uk> wrote:
> > On Wed, 2019-10-09 at 21:10 +0200, Arnd Bergmann wrote:
> > > We no longer need the rtc compat handling to be in common code, now that
> > > all drivers are either moved to the rtc-class framework, or (rarely)
> > > exist in drivers/char for architectures without compat mode (m68k,
> > > alpha and ia64, respectively).
> > >
> > > I checked the list of ioctl commands in drivers, and the ones that are
> > > not already handled are all compatible, again with the one exception of
> > > m68k driver, which implements RTC_PLL_GET and RTC_PLL_SET, but has no
> > > compat mode.
> > >
> > > Since the ioctl commands are either compatible or differ in both structure
> > > and command code between 32-bit and 64-bit, we can merge the compat
> > > handler into the native one and just implement the two common compat
> > > commands (RTC_IRQP_READ, RTC_IRQP_SET) there.
> > [...]
> >
> > I don't think this can work properly on s390, because some of them take
> > integers and some take pointers.
>
> Thanks a lot for taking a look at the patch and pointing this out!
>
> I don't remember how I got to this, either I missed the problem or I
> decided that it was ok, since it will still do the right thing:
> On s390 only the highest bit is cleared in a pointer value, and we
> ensure that the RTC_IRQP_SET argument is between 1 and 8192.
>
> Passing a value of (0x80000000 + n) where n is in the valid range
> would lead to the call succeeding unexpectedly on compat s390
> (if it had an RTC, which it does not) which is clearly not good but
> mostly harmless. I certainly had not considered this case.
>
> However, looking at this again after your comment I found a rather
> more serious bug in my new RTC_IRQP_SET handling: Any 64-bit
> machine can now bypass the permission check for RTC_IRQP_SET by
> calling RTC_IRQP_SET32 instead.
>
> I'll fix it both issues by adding a rtc_compat_dev_ioctl() to handle
> RTC_IRQP_SET32/RTC_IRQP_READ32:
Reviewed-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
> diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c
> index 1dc5063f78c9..9e4fd5088ead 100644
> --- a/drivers/rtc/dev.c
> +++ b/drivers/rtc/dev.c
> @@ -358,16 +358,6 @@ static long rtc_dev_ioctl(struct file *file,
> mutex_unlock(&rtc->ops_lock);
> return rtc_update_irq_enable(rtc, 0);
>
> -#ifdef CONFIG_64BIT
> -#define RTC_IRQP_SET32 _IOW('p', 0x0c, __u32)
> -#define RTC_IRQP_READ32 _IOR('p', 0x0b, __u32)
> - case RTC_IRQP_SET32:
> - err = rtc_irq_set_freq(rtc, arg);
> - break;
> - case RTC_IRQP_READ32:
> - err = put_user(rtc->irq_freq, (unsigned int __user *)uarg);
> - break;
> -#endif
> case RTC_IRQP_SET:
> err = rtc_irq_set_freq(rtc, arg);
> break;
> @@ -409,6 +399,29 @@ static long rtc_dev_ioctl(struct file *file,
> return err;
> }
>
> +#ifdef CONFIG_COMPAT
> +#define RTC_IRQP_SET32 _IOW('p', 0x0c, __u32)
> +#define RTC_IRQP_READ32 _IOR('p', 0x0b, __u32)
> +
> +static long rtc_dev_compat_ioctl(struct file *file,
> + unsigned int cmd, unsigned long arg)
> +{
> + struct rtc_device *rtc = file->private_data;
> + void __user *uarg = compat_ptr(arg);
> +
> + switch (cmd) {
> + case RTC_IRQP_READ32:
> + return put_user(rtc->irq_freq, (__u32 __user *)uarg);
> +
> + case RTC_IRQP_SET32:
> + /* arg is a plain integer, not pointer */
> + return rtc_dev_ioctl(file, RTC_IRQP_SET, arg);
> + }
> +
> + return rtc_dev_ioctl(file, cmd, (unsigned long)uarg);
> +}
> +#endif
> +
> static int rtc_dev_fasync(int fd, struct file *file, int on)
> {
> struct rtc_device *rtc = file->private_data;
> @@ -444,7 +457,7 @@ static const struct file_operations rtc_dev_fops = {
> .read = rtc_dev_read,
> .poll = rtc_dev_poll,
> .unlocked_ioctl = rtc_dev_ioctl,
> - .compat_ioctl = compat_ptr_ioctl,
> + .compat_ioctl = rtc_dev_compat_ioctl,
> .open = rtc_dev_open,
> .release = rtc_dev_release,
> .fasync = rtc_dev_fasync,
>
> If you and Alexandre are both happy with this version, I'll fold it into
> my original patch.
>
> Arnd
>
--
Ben Hutchings, Software Developer Codethink Ltd
https://www.codethink.co.uk/ Dale House, 35 Dale Street
Manchester, M1 2HF, United Kingdom
next prev parent reply other threads:[~2019-10-17 18:19 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 19:08 [PATCH v6 00/43] compat_ioctl: remove most of fs/compat_ioctl.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 01/43] fix compat handling of FICLONERANGE, FIDEDUPERANGE and FS_IOC_FIEMAP Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 02/43] FIGETBSZ: fix compat Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 03/43] compat: itanic doesn't have one Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 04/43] do_vfs_ioctl(): use saner types Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 05/43] compat: move FS_IOC_RESVSP_32 handling to fs/ioctl.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 06/43] compat_sys_ioctl(): make parallel to do_vfs_ioctl() Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 07/43] ceph: fix compat_ioctl for ceph_dir_operations Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 08/43] compat_ioctl: drop FIOQSIZE table entry Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 09/43] compat_ioctl: add compat_ptr_ioctl() Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 10/43] compat_ioctl: move rtc handling into rtc-dev.c Arnd Bergmann
2019-10-09 19:25 ` Alexandre Belloni
2019-10-09 19:31 ` Arnd Bergmann
2019-10-17 13:42 ` [Y2038] " Ben Hutchings
2019-10-17 14:33 ` Arnd Bergmann
2019-10-17 18:19 ` Ben Hutchings [this message]
2019-10-22 4:30 ` Al Viro
2019-10-22 12:14 ` Arnd Bergmann
2019-10-23 10:29 ` Alexandre Belloni
2019-10-23 14:28 ` Arnd Bergmann
2019-10-23 14:34 ` Alexandre Belloni
2019-10-23 15:02 ` Arnd Bergmann
2019-10-23 10:32 ` Alexandre Belloni
2019-10-09 19:10 ` [PATCH v6 11/43] compat_ioctl: move drivers to compat_ptr_ioctl Arnd Bergmann
2019-10-14 19:30 ` Jarkko Sakkinen
2019-10-22 4:34 ` Al Viro
2019-10-22 10:26 ` Arnd Bergmann
2019-10-23 3:17 ` Al Viro
2019-10-23 15:26 ` Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 12/43] compat_ioctl: move more " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 13/43] compat_ioctl: use correct compat_ptr() translation in drivers Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 14/43] compat_ioctl: move tape handling into drivers Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 15/43] compat_ioctl: move ATYFB_CLK handling to atyfb driver Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 16/43] compat_ioctl: move isdn/capi ioctl translation into driver Arnd Bergmann
2019-10-17 18:25 ` [Y2038] " Ben Hutchings
2019-10-18 14:18 ` Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 17/43] compat_ioctl: move rfcomm handlers " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 18/43] compat_ioctl: move hci_sock " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 19/43] compat_ioctl: remove HCIUART handling Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 20/43] compat_ioctl: remove HIDIO translation Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 21/43] compat_ioctl: remove translation for sound ioctls Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 22/43] compat_ioctl: remove IGNORE_IOCTL() Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 23/43] compat_ioctl: remove /dev/random commands Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 24/43] compat_ioctl: remove joystick ioctl translation Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 25/43] compat_ioctl: remove PCI " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 26/43] compat_ioctl: remove /dev/raw " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 27/43] compat_ioctl: remove last RAID handling code Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 28/43] compat_ioctl: remove unused convert_in_user macro Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 29/43] gfs2: add compat_ioctl support Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 29/43] REPLACE " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 30/43] fs: compat_ioctl: move FITRIM emulation into file systems Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 31/43] compat_ioctl: move WDIOC handling into wdt drivers Arnd Bergmann
2019-10-18 12:49 ` [Y2038] " Ben Hutchings
2019-10-18 13:31 ` Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 32/43] compat_ioctl: reimplement SG_IO handling Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 33/43] af_unix: add compat_ioctl support Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 34/43] compat_ioctl: handle SIOCOUTQNSD Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 35/43] compat_ioctl: move SIOCOUTQ out of compat_ioctl.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 36/43] tty: handle compat PPP ioctls Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 37/43] compat_ioctl: unify copy-in of ppp filters Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 38/43] compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 39/43] compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 40/43] compat_ioctl: ppp: move simple commands into ppp_generic.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 41/43] compat_ioctl: move SG_GET_REQUEST_TABLE handling Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 42/43] pktcdvd: add compat_ioctl handler Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 43/43] scsi: sd: enable compat ioctls for sed-opal Arnd Bergmann
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=52d2fdbd514d93cdd901c18afbb83be13145de6f.camel@codethink.co.uk \
--to=ben.hutchings@codethink.co.uk \
--cc=alexandre.belloni@bootlin.com \
--cc=arnd@arndb.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=y2038@lists.linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).