From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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, };