Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5507553imm; Wed, 12 Sep 2018 07:03:42 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaHBxCicXtiCoGO7sTMzxuwCKmVmDquCH7VUqWx8llpH9oO0DeFAicZUvGTzZNhOjvUrWpz X-Received: by 2002:a63:2906:: with SMTP id p6-v6mr2505583pgp.204.1536761022772; Wed, 12 Sep 2018 07:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536761022; cv=none; d=google.com; s=arc-20160816; b=zRl8TNSiVUtCXRDsf4wGNov/7yWQqLZmaXLMARD87fB+Vmc1Sw/LhioTppDcMNgtg+ p1XgjCN1iY/R7WkvQZT2e+Fg/zUOeClqKPqfIgQxUwwFMkOZTCmHHSi3a76La7DMETkn ixx+xd/S8tW6w9F40SZlCcDDwgSCRo5e9XsOPc7wJDQfR+7ezmhEcQ/BlpFOPVeyqKwE vC7/S8ploX48vFmFWHEGLQ0I/uxno51Dsh2kdcf6tI1LLhctJv0vAUOyXTYDWWK9rBJ6 BO27G/+lSfmJBavBHmnnV/HMQmE3Wir7A43TAmto4Bt2Ssd4Yp/bqDkvPcY7bKtMwR2Q ugNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=8lV/UqnuqRHDU0staNgFvRQDud1dwez67gcAXgd0IAE=; b=honAZBgGTFrJJY8ZV2p8CkD9eHaD/3Z6lF1gy8GjxpZZ/Vn5tqrQqPNqaGvSCid3G/ YXOpbGZQMujO8pz4dr0t2ReIvpg91MmUOzC1nHa8DGu0yjrP++6XFHOlTed8cyB5h8+5 fzsANx25OiqLjQDX2+LMBBicJkj6gaNAidzLwHBgzMEDLCuWzAaDtaBIEdQO2P8Kg2XX rn08t5oD1RM555OyVYZ/dRwfu/zokxTUDCjkbxFjeNc4Vy8SYHM2LlV9vJkJqlCtIM3i +WEkcff0gDtKHqD23DHlex04ZYocJ4++142hlcNDpwxwuNMyvsgkzfBBote0cBcf8N0s ijWw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j135-v6si1037889pfd.207.2018.09.12.07.03.20; Wed, 12 Sep 2018 07:03:42 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727773AbeILTHh (ORCPT + 99 others); Wed, 12 Sep 2018 15:07:37 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:40178 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726836AbeILTHh (ORCPT ); Wed, 12 Sep 2018 15:07:37 -0400 Received: by mail-qk1-f195.google.com with SMTP id c126-v6so1158404qkd.7; Wed, 12 Sep 2018 07:02:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8lV/UqnuqRHDU0staNgFvRQDud1dwez67gcAXgd0IAE=; b=ii1qn/UlzkuQ8/E+WqWmKNMpppOjGIal53YE9+kpQe5Wz4kSK6j/4qKctJF1Azj2iQ 7lb95+hu3UvTnUfjYwVeDYsHdkPA9snM0C3r1OnBivN7alDq2j6HeMCZDfOm4eiGHTBE 6J8PvXHjwXqTt1W1eF4yxs4Gd3eLUgNG3ZVKkLBY4JqzEgmP3dMKupDoH98q2aiQ1Vd9 m+H8aLb96XBqvzokq+fQE5IpWOCurKG4L/ei35J9+s5RgtZv1zrTkkX06wMBx7WVVxXK aZidhFdXmlZuXKck8znXEM4X0CuhFgzKqmw/7a1ttrmRnVAk5GBXhq3f5nPnNMoCW3V6 rUfg== X-Gm-Message-State: APzg51Ce5lAIfn6f6LKWcLS0TnvbtCc+eIctAtgmKiDqqmqo91GCMryV f84eCeZ41WU6qu6KhC/Vuwj7BT7zDmyXMXej+ho= X-Received: by 2002:a37:7347:: with SMTP id o68-v6mr1511338qkc.291.1536760976598; Wed, 12 Sep 2018 07:02:56 -0700 (PDT) MIME-Version: 1.0 References: <20180908142837.2819693-1-arnd@arndb.de> <20180908142837.2819693-6-arnd@arndb.de> <20180909041114.GD19965@ZenIV.linux.org.uk> <20180912072854.13b4c3b8@mschwideX1> In-Reply-To: <20180912072854.13b4c3b8@mschwideX1> From: Arnd Bergmann Date: Wed, 12 Sep 2018 16:02:40 +0200 Message-ID: Subject: Re: [PATCH 06/11] compat_ioctl: remove /dev/random commands To: Martin Schwidefsky Cc: Al Viro , "Theodore Ts'o" , gregkh , Linux Kernel Mailing List , Linux FS-devel Mailing List , linux-s390 , Heiko Carstens Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 12, 2018 at 7:29 AM Martin Schwidefsky wrote: > On Tue, 11 Sep 2018 22:26:54 +0200 Arnd Bergmann wrote: > > On Sun, Sep 9, 2018 at 6:12 AM Al Viro wrote: > > Out of those, there are only a few that may get used on s390, > > in particular at most infiniband/uverbs, nvme, nvdimm, > > btrfs, ceph, fuse, fanotify and userfaultfd. > > [Note: there are three s390 drivers in the list, which use > > a different method: they check in_compat_syscall() from > > a shared handler to decide whether to do compat_ptr(). > > Using in_compat_syscall() seems to be a good solution, no? It works fine for you, but wouldn't work on architecture-independent code, since 32-bit architectures generally don't provide a compat_ptr() implementation. This could of course be changed easily, but after this change it, your drivers work just as well with a couple few lines, and more consistent with other drivers: --- a/drivers/s390/char/sclp_ctl.c +++ b/drivers/s390/char/sclp_ctl.c @@ -93,12 +93,8 @@ static int sclp_ctl_ioctl_sccb(void __user *user_area) static long sclp_ctl_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - void __user *argp; + void __user *argp = (void __user *)arg; - if (is_compat_task()) - argp = compat_ptr(arg); - else - argp = (void __user *) arg; switch (cmd) { case SCLP_CTL_SCCB: return sclp_ctl_ioctl_sccb(argp); @@ -114,7 +110,7 @@ static const struct file_operations sclp_ctl_fops = { .owner = THIS_MODULE, .open = nonseekable_open, .unlocked_ioctl = sclp_ctl_ioctl, - .compat_ioctl = sclp_ctl_ioctl, + .compat_ioctl = generic_compat_ioctl_ptrarg, .llseek = no_llseek, }; This should probably be separate from the change to using compat_ptr() in all other drivers, and I could easily drop this change if you prefer, it is meant only as a cosmetic change. > > According to my memory from when I last worked on this, > > the compat_ptr() is mainly a safeguard for legacy binaries > > that got created with ancient C compilers (or compilers for > > something other than C) and might leave the high bit set > > in a pointer, but modern C compilers (gcc-3+) won't ever > > do that. > > And compat_ptr clears the upper 32-bit of the register. If > the register is loaded to e.g. "lr" or "l" there will be > junk in the 4 upper bytes. I don't think we hit that problem anywhere: in the ioctl argument we pass an 'unsigned long' that has already been zero-extended by the compat_sys_ioctl() wrapper, while any other usage would get extended by the compiler when casting from compat_uptr_t to a 64-bit type. This would be different if you had a function call with the wrong prototype, i.e. calling a function declared as taking an compat_uptr_t, but defining it as taking a void __user*. (I suppose that is undefined behavior). Unless I'm missing something, compat_ptr() should always just clear bit 31. What I'd like to confirm is whether you have encountered any code that actually passes a pointer with that bit set by a user application in the past 15 years. As Al said, it's probably best to just always apply the compat_ptr() conversion in each case that s390 needs it even for drivers that don't run on s390, but I'd also like to understand how much it matters in practice. (A separate question would be how long we expect to need 32 bit compat mode on arch/s390 at all, but for the moment I assume this is not up for debate at all). Arnd