Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17521275ybl; Thu, 2 Jan 2020 07:03:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwxSLzdg8FCAlJIliKRDbEjq7KkFpU5+5iQ3yqk9UPyZYjzyyRHnRZDBnpC/CbF9cilO3Ej X-Received: by 2002:aca:a9c5:: with SMTP id s188mr2325034oie.154.1577977399051; Thu, 02 Jan 2020 07:03:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577977399; cv=none; d=google.com; s=arc-20160816; b=FaZfb+ghcwhbKGeXA5mJCR1KYceNeu9m8e9sk3vU5a9TPnaWmpYNuAa4ztSSrIQE2k aEBTyJV/E9VIm9fQCmvs1FuuDd1tQqWtHQYUR5LaOzW7GB1OZTM/mEQSERDh4qXD/sjW DBDDngtgkfLTj97U7EIBw9z8Lhxex4YBQYaCAk7r0XDqFKtMxZv+AHYYiWb3kY7p9xWK dk1KlQtWKGqgv0kuRmCToM6OnhgQQkdHMpyla/Je+rluRjUOGYZVxmq6C3OmJ2zauONU S0XhV00FSK6dP0L7w8B6H/Cw/ecQQS+AOuzWM7D6E/o4C/8n0sX7H9EuUZHh4aJQZmLu Er2Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=us+w3iHtU+h67w93/BGs4FIsO/d5hasiW8dMKpheK6I=; b=RVqR10rmMWw23fyVRkV9US9yVM3XoI+ODiqjMPLSE9VgLBEFEuu/zRlOPwQ2dUX3QF DRDDVys4EpsgC5x3MtazJ8CTdKp4eCX6b1i1Ynwb5pcAiF2+AW0W8h6SYN4nh2yr4Z6/ 75ww1OpWQbZvmNiq7Zrf9u4QfkzRqkDSIWZ2mzFuZgMtD5cvJREKQ/TgL3gfBlp99zTH wWrelgPnP96Bw/Y7Ac0cOyqvyC3wHkZWARzd/2gnQMI4ZAaF5DM5hPRLft2lJQrIu2QM twdT11e+9Lux1oT+737q+bk8ny1zhqdHiyXiI+JALha6V/BBvyo87WH8H9rI0UGLNRPE e7/g== 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 i65si26011194oif.15.2020.01.02.07.03.07; Thu, 02 Jan 2020 07:03:19 -0800 (PST) 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 S1728693AbgABPCZ (ORCPT + 99 others); Thu, 2 Jan 2020 10:02:25 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:55343 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728595AbgABPCY (ORCPT ); Thu, 2 Jan 2020 10:02:24 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1MfHQp-1jOJja3KQN-00gnxw; Thu, 02 Jan 2020 16:01:49 +0100 From: Arnd Bergmann To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Arnd Bergmann , Jens Axboe , Alexander Viro , Martin Wilck , David Howells , "Darrick J. Wong" , "Theodore Ts'o" , Gao Xiang , Phillip Potter , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 14/22] compat_ioctl: move sys_compat_ioctl() to ioctl.c Date: Thu, 2 Jan 2020 15:55:32 +0100 Message-Id: <20200102145552.1853992-15-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20200102145552.1853992-1-arnd@arndb.de> References: <20200102145552.1853992-1-arnd@arndb.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:QHW26qoZu7BFOLY294SQCDAdYS+0LermWcmWpuZcCs1uu3ygnuv o7yXMPGUgodpJydzENgx8LxWBx25o6BxiYCvPny319dmjTgRx3wYYT08P3JX6GkwJPdF9Fv uTGqxsO8Oi2yjHAK0GmswsnVYNnaJTVnLlycdPQvfZBCOsHny1TQi6zBU/4Nm/gN4adJEcM QfsIzZQzDJpkVSQ8QcANA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:o4Y9FEc7lmM=:FQzkxK5zPiq0iQsTxqM13f Zbrvxtvh6EyBo2ubdbPy+9B0cTbLhK4uRVtQaXlx0OSds661k1ptv1bN4I/FttEvINcwSqVmC U4RtO1HnQUnMdYaPoO5emXKtb329TqemuRcKxqr2X6Sq9gHsaVgxycAcr8+bvqeDC+OPnaOvw AWT5t08j27I1pahKYrts7dafLHbA2MlalQmUW/EgQnoccEs5lN4DFbgpAh/bjTwiQOrYgl4dz e37F0L1cmLiUXWkxzmplJUX9pLfuE279NlzQoaAs3JD1MCnk1I/mVc5X1isLVU4ZT3bv4i8AG T3xwBpDaexQCASS43vdn+GRqhtGaAOuR5EqmAoaCNsBz5J4xj8SC9smxVp/PwPRYcItIRV7LB vIqQsyCRT7EUky08cPguYbYajeKnLoTBgc/QwZlZUPuQsj9+8OuOS7Lp7UcRSVImgAGi+h9j2 /dKWFJRjPBjRWAc+uaX8Ftjq4fC8fOd+He6LIe8L9/aPCCviqTAuuZjf8Udm7RUV0pU2byQtF 5rS9pvbxf67gbNWnIsnxUdQRjut/dfDcOl06yWIO45vwu0aZwV9Lgew0CjwuXGdPBMlXjqSEc L94ufpzZ4op6UvW3e3fyzyJFE9ExIzyu6LTUMxIMh2oHMxfTCmp2RI4VOdRVjv736etSXyctU fORl2tWlEytlTlW7xDPBSGF/FQxCE8tti0cRPQviQXkk9l1J6d359h/jgDkXWjTLk5i0vG5c9 I2lRlUatZW8fRkrKPe/Gxb+uPtSm3k43mICXElFl1t68SC6Z3tJzP/nYcoIbRgPy23f60/g+E a4E7wOx7+hTyEqg/fnkZs8nhC08/GNEILnz4SPSleIXlOEbUJ+3KJepIDkANsNqFPRODSP6jG p06GILZr5NMNAyTKHejQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The rest of the fs/compat_ioctl.c file is no longer useful now, so move the actual syscall as planned. Signed-off-by: Arnd Bergmann --- drivers/scsi/sr.c | 2 +- fs/Makefile | 2 +- fs/compat_ioctl.c | 133 ---------------------------------------------- fs/ioctl.c | 90 +++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 135 deletions(-) delete mode 100644 fs/compat_ioctl.c diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 6033a886c42c..f1e7aab00ce3 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -634,7 +634,7 @@ static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsign */ ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); if (ret != -ENOTTY) - return ret; + goto put; ret = scsi_compat_ioctl(sdev, cmd, argp); diff --git a/fs/Makefile b/fs/Makefile index 1148c555c4d3..98be354fdb61 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -37,7 +37,7 @@ obj-$(CONFIG_FS_DAX) += dax.o obj-$(CONFIG_FS_ENCRYPTION) += crypto/ obj-$(CONFIG_FS_VERITY) += verity/ obj-$(CONFIG_FILE_LOCKING) += locks.o -obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o +obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o obj-$(CONFIG_BINFMT_EM86) += binfmt_em86.o obj-$(CONFIG_BINFMT_MISC) += binfmt_misc.o diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c deleted file mode 100644 index ab4471f469e6..000000000000 --- a/fs/compat_ioctl.c +++ /dev/null @@ -1,133 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * ioctl32.c: Conversion between 32bit and 64bit native ioctls. - * - * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com) - * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) - * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs - * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz) - * - * These routines maintain argument size conversion between 32bit and 64bit - * ioctls. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "internal.h" - -#include -#include - -#include - -COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, - compat_ulong_t, arg32) -{ - unsigned long arg = arg32; - struct fd f = fdget(fd); - int error = -EBADF; - if (!f.file) - goto out; - - /* RED-PEN how should LSM module know it's handling 32bit? */ - error = security_file_ioctl(f.file, cmd, arg); - if (error) - goto out_fput; - - switch (cmd) { - /* these are never seen by ->ioctl(), no argument or int argument */ - case FIOCLEX: - case FIONCLEX: - case FIFREEZE: - case FITHAW: - case FICLONE: - goto do_ioctl; - /* these are never seen by ->ioctl(), pointer argument */ - case FIONBIO: - case FIOASYNC: - case FIOQSIZE: - case FS_IOC_FIEMAP: - case FIGETBSZ: - case FICLONERANGE: - case FIDEDUPERANGE: - goto found_handler; - /* - * The next group is the stuff handled inside file_ioctl(). - * For regular files these never reach ->ioctl(); for - * devices, sockets, etc. they do and one (FIONREAD) is - * even accepted in some cases. In all those cases - * argument has the same type, so we can handle these - * here, shunting them towards do_vfs_ioctl(). - * ->compat_ioctl() will never see any of those. - */ - /* pointer argument, never actually handled by ->ioctl() */ - case FIBMAP: - goto found_handler; - /* handled by some ->ioctl(); always a pointer to int */ - case FIONREAD: - goto found_handler; - /* these get messy on amd64 due to alignment differences */ -#if defined(CONFIG_X86_64) - case FS_IOC_RESVSP_32: - case FS_IOC_RESVSP64_32: - error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg)); - goto out_fput; - case FS_IOC_UNRESVSP_32: - case FS_IOC_UNRESVSP64_32: - error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE, - compat_ptr(arg)); - goto out_fput; - case FS_IOC_ZERO_RANGE_32: - error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE, - compat_ptr(arg)); - goto out_fput; -#else - case FS_IOC_RESVSP: - case FS_IOC_RESVSP64: - case FS_IOC_UNRESVSP: - case FS_IOC_UNRESVSP64: - case FS_IOC_ZERO_RANGE: - goto found_handler; -#endif - - default: - if (f.file->f_op->compat_ioctl) { - error = f.file->f_op->compat_ioctl(f.file, cmd, arg); - if (error != -ENOIOCTLCMD) - goto out_fput; - } - - error = -ENOTTY; - goto out_fput; - } - - found_handler: - arg = (unsigned long)compat_ptr(arg); - do_ioctl: - error = do_vfs_ioctl(f.file, fd, cmd, arg); - out_fput: - fdput(f); - out: - return error; -} diff --git a/fs/ioctl.c b/fs/ioctl.c index 2f5e4e5b97e1..8f22f7817edb 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -788,4 +788,94 @@ long compat_ptr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return file->f_op->unlocked_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); } EXPORT_SYMBOL(compat_ptr_ioctl); + +COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, + compat_ulong_t, arg32) +{ + unsigned long arg = arg32; + struct fd f = fdget(fd); + int error = -EBADF; + if (!f.file) + goto out; + + /* RED-PEN how should LSM module know it's handling 32bit? */ + error = security_file_ioctl(f.file, cmd, arg); + if (error) + goto out_fput; + + switch (cmd) { + /* these are never seen by ->ioctl(), no argument or int argument */ + case FIOCLEX: + case FIONCLEX: + case FIFREEZE: + case FITHAW: + case FICLONE: + goto do_ioctl; + /* these are never seen by ->ioctl(), pointer argument */ + case FIONBIO: + case FIOASYNC: + case FIOQSIZE: + case FS_IOC_FIEMAP: + case FIGETBSZ: + case FICLONERANGE: + case FIDEDUPERANGE: + goto found_handler; + /* + * The next group is the stuff handled inside file_ioctl(). + * For regular files these never reach ->ioctl(); for + * devices, sockets, etc. they do and one (FIONREAD) is + * even accepted in some cases. In all those cases + * argument has the same type, so we can handle these + * here, shunting them towards do_vfs_ioctl(). + * ->compat_ioctl() will never see any of those. + */ + /* pointer argument, never actually handled by ->ioctl() */ + case FIBMAP: + goto found_handler; + /* handled by some ->ioctl(); always a pointer to int */ + case FIONREAD: + goto found_handler; + /* these get messy on amd64 due to alignment differences */ +#if defined(CONFIG_X86_64) + case FS_IOC_RESVSP_32: + case FS_IOC_RESVSP64_32: + error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg)); + goto out_fput; + case FS_IOC_UNRESVSP_32: + case FS_IOC_UNRESVSP64_32: + error = compat_ioctl_preallocate(f.file, FALLOC_FL_PUNCH_HOLE, + compat_ptr(arg)); + goto out_fput; + case FS_IOC_ZERO_RANGE_32: + error = compat_ioctl_preallocate(f.file, FALLOC_FL_ZERO_RANGE, + compat_ptr(arg)); + goto out_fput; +#else + case FS_IOC_RESVSP: + case FS_IOC_RESVSP64: + case FS_IOC_UNRESVSP: + case FS_IOC_UNRESVSP64: + case FS_IOC_ZERO_RANGE: + goto found_handler; +#endif + + default: + if (f.file->f_op->compat_ioctl) { + error = f.file->f_op->compat_ioctl(f.file, cmd, arg); + if (error != -ENOIOCTLCMD) + goto out_fput; + } + error = -ENOTTY; + goto out_fput; + } + + found_handler: + arg = (unsigned long)compat_ptr(arg); + do_ioctl: + error = do_vfs_ioctl(f.file, fd, cmd, arg); + out_fput: + fdput(f); + out: + return error; +} #endif -- 2.20.0