Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1284852ybg; Fri, 18 Oct 2019 15:13:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzONRlMIlnocqFGKajsPTAPGZ/XNdHA+vcqCTdLgUyfNUbC3yHpaQgpyCKOsbz0Jl/MtAIj X-Received: by 2002:a17:906:27c5:: with SMTP id k5mr10812005ejc.173.1571436789670; Fri, 18 Oct 2019 15:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571436789; cv=none; d=google.com; s=arc-20160816; b=cBWJqbISLMuJwT/8i81F4Yqwjtep/+umbAS6g06vyDp2Is8Kfvu0Avpg0sMgChvuUh HFxeUG1lEeoc1dKFfWOrzZWslu+njCLGr4KlxjhOnt2U+fCGMDfR44+OJIufQ28CCDPD J1P3p6qIs6Tj1azaCKdy23kH18MjcDTuPNrgOJouG6j4rYp0u4VXXeRK+7SgMRUIBnaJ 5kt+PTmv6sbPEZH7Maof0YdZQQjOue2LDMCF9PMpc6/2AcCIRAz5dKhQJf4MVGbDHj57 OXXhcsLYrx8lZcG3Gv2r8LD9xMi3BQuJN2EqFvFkwB8EMCVL2AEQoQ7A+5FPtNlpRjiG nZxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=VCbiSuFrkHNATS5J4IPWCyPHwDVFMSHwm3wWXQPQRMo=; b=QPFoJRvf2++miniKmXCI3IosNUr8ADk438qkgpszvIbQ7K2c1aGTSfXA4TveAiEJQP 9g72rghwmJr4nCOXs2IJKhGuAEREJhzvrgZyiQ418qDXcyh/UZvl6UMnZspBb3GN/zBK hCkqY4/pWlSxrzwk2ZWeCZU6yxtGx7LwW1FhrOKZVqVynyCMe4PX4UiY5ZfRtsSltKtp hZu9jiT/60M5yZUUQ4aAT6oWLMCi1pTVH4Bm6KnS0n4TBrNha8ppiAerTAxV+N1AHD1K y40Vzyr+DURzUZyXB0cHG4X22MQs0set0TwDzyWuhlMlwI+GXDkdsfXE1r5RuLSR3s/A SsiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si4378859ejs.401.2019.10.18.15.12.46; Fri, 18 Oct 2019 15:13:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2441270AbfJQSTc (ORCPT + 99 others); Thu, 17 Oct 2019 14:19:32 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:38543 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438684AbfJQSTc (ORCPT ); Thu, 17 Oct 2019 14:19:32 -0400 Received: from [167.98.27.226] (helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1iLAMw-0006vd-SL; Thu, 17 Oct 2019 19:19:27 +0100 Message-ID: <52d2fdbd514d93cdd901c18afbb83be13145de6f.camel@codethink.co.uk> Subject: Re: [Y2038] [PATCH v6 10/43] compat_ioctl: move rtc handling into rtc-dev.c From: Ben Hutchings To: Arnd Bergmann Cc: Al Viro , y2038 Mailman List , Linux FS-devel Mailing List , Alexandre Belloni , "linux-kernel@vger.kernel.org" Date: Thu, 17 Oct 2019 19:19:26 +0100 In-Reply-To: References: <20191009190853.245077-1-arnd@arndb.de> <20191009191044.308087-10-arnd@arndb.de> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2019-10-17 at 16:33 +0200, Arnd Bergmann wrote: > On Thu, Oct 17, 2019 at 3:42 PM Ben Hutchings > 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 > 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