From patchwork Thu Jan 2 14:55:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11315891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A13D139A for ; Thu, 2 Jan 2020 14:58:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72B8F20848 for ; Thu, 2 Jan 2020 14:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728559AbgABO6r (ORCPT ); Thu, 2 Jan 2020 09:58:47 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:38545 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728544AbgABO6q (ORCPT ); Thu, 2 Jan 2020 09:58:46 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1Ml6Zo-1jRu2Z2XTo-00lSv9; Thu, 02 Jan 2020 15:58:03 +0100 From: Arnd Bergmann To: "James E.J. Bottomley" , "Martin K. Petersen" , Jens Axboe Cc: Arnd Bergmann , Jan Kara , Stefan Haberland , Dmitry Fomichev , Ajay Joshi , Damien Le Moal , Ming Lei , Chaitanya Kulkarni , Bart Van Assche , Pavel Begunkov , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/22] compat_ioctl: block: add blkdev_compat_ptr_ioctl Date: Thu, 2 Jan 2020 15:55:22 +0100 Message-Id: <20200102145552.1853992-5-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 X-Provags-ID: V03:K1:KgLrT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7pWUmODhPKA8 1v0yzafUNyvPRH8jvHtL2i/QY5R4ZUJfUdT5s6J4DzukGwp1iEu4On0wPmyq+6HpMmpGNIeVW GZS+P8C4HMsApTc0z9lQ== Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org A lot of block drivers need only a trivial .compat_ioctl callback. Add a helper function that can be set as the callback pointer to only convert the argument using the compat_ptr() conversion and otherwise assume all input and output data is compatible, or handled using in_compat_syscall() checks. This mirrors the compat_ptr_ioctl() helper function used in character devices. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 21 +++++++++++++++++++++ include/linux/blkdev.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index 5de98b97af2a..e728331d1a5b 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include @@ -285,6 +286,26 @@ int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, */ EXPORT_SYMBOL_GPL(__blkdev_driver_ioctl); +#ifdef CONFIG_COMPAT +/* + * This is the equivalent of compat_ptr_ioctl(), to be used by block + * drivers that implement only commands that are completely compatible + * between 32-bit and 64-bit user space + */ +int blkdev_compat_ptr_ioctl(struct block_device *bdev, fmode_t mode, + unsigned cmd, unsigned long arg) +{ + struct gendisk *disk = bdev->bd_disk; + + if (disk->fops->ioctl) + return disk->fops->ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + + return -ENOIOCTLCMD; +} +EXPORT_SYMBOL(blkdev_compat_ptr_ioctl); +#endif + static int blkdev_pr_register(struct block_device *bdev, struct pr_registration __user *arg) { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 47eb22a3b7f9..3e0408618da7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1711,6 +1711,13 @@ struct block_device_operations { const struct pr_ops *pr_ops; }; +#ifdef CONFIG_COMPAT +extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t, + unsigned int, unsigned long); +#else +#define blkdev_compat_ptr_ioctl NULL +#endif + extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int, unsigned long); extern int bdev_read_page(struct block_device *, sector_t, struct page *);