Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1264855imm; Sat, 8 Sep 2018 21:14:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY779P8phTREU/W3s75H1R5LIcwiXaWNDintVXzyz89sKI7JdwSNPmF1NEnHBzwhJByfoOH X-Received: by 2002:a62:9e08:: with SMTP id s8-v6mr16794441pfd.23.1536466480018; Sat, 08 Sep 2018 21:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536466479; cv=none; d=google.com; s=arc-20160816; b=0Ol7WykiiN3LtbrL3zabRPp+pTjlqzdf2fYMk9mlU/sgTmEuHvjgGdrx+U8D59wF+L 9XfM2XOOTzGY0MYI91dM5hBm4pPSIoXHTmpPRtnD9iSHflSWjJqs+AyNT3sMgtEtDLM7 CLm6IgCFRY4vDmjs66u/jAD5Rstfnhwl4Ya5dw2FoDNIwxUevSGBJniIlOj0mRpCmzZS PwOY7+Qih6738NmgqwJ1HA/ptqeh7En1fm4uW+S9gn6ELshyP55yOqiIB5pK720BGyq2 1B3xqoiWKDqspBsSqjhJMIdWcojI1TVidSoLYIKwqR7AOgGamOEnk0itEGmANgRrElKr Ygwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=UO6FVBkSCq/NB/G3/2H9QALPJ0W58Zv4meoogt27g8E=; b=Kc1PAKoMmay05b54fKKOTswKNDyrvzFaYvaWk3gIP0YC+pEAo3Vap3bpjlszFP50Yb xAM4AL4hoXzi3QNSZ9p/JhBMEe4Q9wSTmqm7+LOg6Oudzi5OF+pcxmwvX1ac0J6Zx2P0 5luaoP086SwNU/wroLiy2rmw9BfAlV1Ub2yNuAxNURU9gI+CRhzkU0IwQ7qhowxxdHoR C4hoIkOA73aZh0JFb1O55icocHVhOr1fWFEl3k1Kp+pWkD7zQcZzaf8LJaHVwWFR1TCZ W4qsKdRKZpanS+rt3ODHoLubF8S92faIk5YygVEX0gvbHmVI1zXal7tW9P9M4c6SAZLw ALyQ== 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 n64-v6si13689645pgn.247.2018.09.08.21.14.11; Sat, 08 Sep 2018 21:14:39 -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 S1726614AbeIIJAa (ORCPT + 99 others); Sun, 9 Sep 2018 05:00:30 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:42934 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726152AbeIIJAa (ORCPT ); Sun, 9 Sep 2018 05:00:30 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fyr4F-0004NB-Kp; Sun, 09 Sep 2018 04:11:33 +0000 Date: Sun, 9 Sep 2018 05:11:23 +0100 From: Al Viro To: Arnd Bergmann Cc: Theodore Ts'o , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 06/11] compat_ioctl: remove /dev/random commands Message-ID: <20180909041114.GD19965@ZenIV.linux.org.uk> References: <20180908142837.2819693-1-arnd@arndb.de> <20180908142837.2819693-6-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180908142837.2819693-6-arnd@arndb.de> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 08, 2018 at 04:28:12PM +0200, Arnd Bergmann wrote: > These are all handled by the random driver, so instead of listing > each ioctl, we can just use the same function to deal with both > native and compat commands. Umm... I don't think it's right - > .unlocked_ioctl = random_ioctl, > + .compat_ioctl = random_ioctl, ->compat_ioctl() gets called in error = f.file->f_op->compat_ioctl(f.file, cmd, arg); so you do *NOT* get compat_ptr() for those - they have to do it on their own. It's not hard to provide a proper compat_ioctl() instance for that one, but this is not it. What you need in drivers/char/random.c part of that one is something like diff --git a/drivers/char/random.c b/drivers/char/random.c index bf5f99fc36f1..1de75c784cf6 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1954,10 +1954,9 @@ static ssize_t random_write(struct file *file, const char __user *buffer, return (ssize_t)count; } -static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) +static long __random_ioctl(struct file *f, unsigned int cmd, int __user *p) { int size, ent_count; - int __user *p = (int __user *)arg; int retval; switch (cmd) { @@ -2011,6 +2010,18 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) } } +static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) +{ + return __random_ioctl(f, cmd, (int __user *)arg); +} + +#ifdef CONFIG_COMPAT +static long compat_random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) +{ + return __random_ioctl(f, cmd, compat_ptr(arg)); +} +#endif + static int random_fasync(int fd, struct file *filp, int on) { return fasync_helper(fd, filp, on, &fasync); @@ -2021,6 +2032,9 @@ const struct file_operations random_fops = { .write = random_write, .poll = random_poll, .unlocked_ioctl = random_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = compat_random_ioctl, +#endif .fasync = random_fasync, .llseek = noop_llseek, };