From patchwork Wed Dec 11 20:42:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181336 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp403ile; Wed, 11 Dec 2019 12:52:48 -0800 (PST) X-Google-Smtp-Source: APXvYqwYmNQqK1w7NlznrL00Tky9/CAR2kyK794rYq+ZDBes2aMDFHSa1N6/uLMAPAKPMJfSLBaV X-Received: by 2002:a9d:7d8e:: with SMTP id j14mr3664650otn.227.1576097568230; Wed, 11 Dec 2019 12:52:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097568; cv=none; d=google.com; s=arc-20160816; b=dv6MWb0jUjfS6r8Zi0XyFjVSwrtcs+ImwO0S4nDruwz6/7Nj7Nhc1dckqcTcOe0yCg jOfZDGiQuxwWUlF0qp11X8rJiXayMsX8FIept1ZVsIi6c4oe3A79RX9j3yWxBBB2HJ6p bP4L1BWqOlonAqeE3iMIdRjtPrXDwsti/XekHH5pa1RQFdSIx3s2tV9w+hEVVa3J/26P KUIuQZXgYF7NQK/AbKAHwc3wCZB9Q9h10Kr7pf+h4LXL6WwcQrTfa+qYvfiZq6b9A7oU 2KbQyiIeyiBG4zKDfR0bMs6TyXsKgr3orHPI9omd2ikQna9DJA3Rq03ipOtPJmHK4to3 6pvw== 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=RO+4rLuP3Qtq7ZVXpL08umXRb0uRS8Hf9o+iee3dLgE=; b=C2NZ6S+fyCsYq2V9HRIjFGvTaFfT605+4OOqVXOB01gHILOcwZ4pWXZHHf2Ulc3t6+ BMbvR+ogHATDhpAA6/HPkYpS6FPpuowvJIfWp/qsi+By9BhfACqZ1ENLUCnsmX0a97fM t76zKXGU3FNI4M1y0LRKTFTgtdFjCwhWRQYGf7jp5Z7LdHWRmlci7T3kLSU4BrYQkhLU NzRNMTCEY0CZpKF9iGi2nz2AVnBDyKvhHvHIjxQvqPIofPh/FhfVFmjuw58HMqhm5Xbm CGi7qGT9P3ljaNagCGu42HK/u1pJmou2um8ikW3nxLJtiL3uZ+Z4D47CxUSca5/lmBuk GZAg== 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 e190si1863373oib.113.2019.12.11.12.52.47; Wed, 11 Dec 2019 12:52:48 -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 S1727047AbfLKUwr (ORCPT + 27 others); Wed, 11 Dec 2019 15:52:47 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:34987 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUwq (ORCPT ); Wed, 11 Dec 2019 15:52:46 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MkpnF-1i0tY73E6R-00mONm; Wed, 11 Dec 2019 21:52:32 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Jan Kara , Keith Busch , Hans Holmberg , Ajay Joshi , linux-block@vger.kernel.org Subject: [PATCH 22/24] compat_ioctl: block: simplify compat_blkpg_ioctl() Date: Wed, 11 Dec 2019 21:42:56 +0100 Message-Id: <20191211204306.1207817-23-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191211204306.1207817-1-arnd@arndb.de> References: <20191211204306.1207817-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BbWzZIYxlkvkGnmBtN0ziB6S5/uESa+bJrxblk1rX616Ql4YYLK 5MK3lyq7Jym7f9Cmi7sW5LYeFVgNlPHDELBXZQAruWnP+9jCcHBQx8Geltv9K6mixksBnrY xrZbEeXFSAL7VL3NkEJysUQo07KPAfKwOWVS3xoELkgAHEUQux6H06XX9GL6AS6s0rCdRmT yzOSN0G7rYmA+yuznFnDw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:FjE7ay0x2Rc=:pmtBqh/ZmwAP8NTZfyRKoI uYwmPxZfNw2/ejLudLUcqZR6VtOSAJF38BBr8LwhIBuycO95G17wr3h7ekst//npcdCcz7y8X xId0UVOKQNTkWrszDX7WSY2yrboWo+c8gLocLEbHOmcp1n4q8zHlMVmrEIFKiWyFYlEwBrRg6 bv8xTGdnW9gsFpsoWEIJS3VK4t1iaruWHjPOK3PId5hxoMutlPzeD+8DvQC9XTUSM4fj2wAOA mo9KbIxSkKdj8x2bl9sOlkjDGvtmbQoHMR+To7Wmt9iniXZnSkQivpg1ZEohNKd/mWbZsqUyL ip7xe9Lj4MCim0+Uwt3gvJ/1YzSOGFmgz2ohzJ5mMO1k5wUXQ11oMb1HTwmjadR1bAJtg+OaU ky6DqnxOwwPDMDkYpnEyHklOyP1haKOT+wlj1Ls6BActccSq9LKyJgl/NHUddO6IAxS5OEdqJ o34sCDgieBh+dBIqYRt6thks/RiGnlobOPKjkmqnBIvWIIXRw1ZuM1yjlrNoyd1UyLidTtbzf nG3OxH0a1/V8SJfu73m5b9kmNtgMpYN0wfUa3bz6CqPTwrzUPzmA0XRvLGaSdkz16XgOGOTFX J+MIPFfqDU3dGnJCnSHrkgZmWcXLXd8rutpOIQ5/sJ8V2Sof7OS1PTh1Vziz4V7tfdu204pKL PkLfr3BbE0kiNJNxR79fGTJ55odCAi1x3oNU2nePjpamXpKdhRTyJAHRhakK+GjxxtYC7hgxp L8bwqgNd/etV0V3tEOQRMFVEkw+ZrCY4E7HUTMixWmK/6GUqIOYnn3/rf9TBeatrMhKISlsAi kh9KpfBHAOUabKAoNfsu2CCA22d7cADUOk38jI45tdc6Ui5g17mj1P271pp4jfHVcaoV+CUyT 9CEtqy0P9F3mfCAIcNRg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no need to go through a compat_alloc_user_space() copy any more, just wrap the function in a small helper that works the same way for native and compat mode. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 74 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) -- 2.20.0 diff --git a/block/ioctl.c b/block/ioctl.c index f8c4e2649335..d6911a1149f5 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -12,12 +12,12 @@ #include #include -static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user *arg) +static int blkpg_do_ioctl(struct block_device *bdev, + struct blkpg_partition __user *upart, int op) { struct block_device *bdevp; struct gendisk *disk; struct hd_struct *part, *lpart; - struct blkpg_ioctl_arg a; struct blkpg_partition p; struct disk_part_iter piter; long long start, length; @@ -25,9 +25,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user if (!capable(CAP_SYS_ADMIN)) return -EACCES; - if (copy_from_user(&a, arg, sizeof(struct blkpg_ioctl_arg))) - return -EFAULT; - if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition))) + if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) return -EFAULT; disk = bdev->bd_disk; if (bdev != bdev->bd_contains) @@ -35,7 +33,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user partno = p.pno; if (partno <= 0) return -EINVAL; - switch (a.op) { + switch (op) { case BLKPG_ADD_PARTITION: start = p.start >> 9; length = p.length >> 9; @@ -156,6 +154,39 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user } } +static int blkpg_ioctl(struct block_device *bdev, + struct blkpg_ioctl_arg __user *arg) +{ + struct blkpg_partition __user *udata; + int op; + + if (get_user(op, &arg->op) || get_user(udata, &arg->data)) + return -EFAULT; + + return blkpg_do_ioctl(bdev, udata, op); +} + +#ifdef CONFIG_COMPAT +struct compat_blkpg_ioctl_arg { + compat_int_t op; + compat_int_t flags; + compat_int_t datalen; + compat_caddr_t data; +}; + +static int compat_blkpg_ioctl(struct block_device *bdev, + struct compat_blkpg_ioctl_arg __user *arg) +{ + compat_caddr_t udata; + int op; + + if (get_user(op, &arg->op) || get_user(udata, &arg->data)) + return -EFAULT; + + return blkpg_do_ioctl(bdev, compat_ptr(udata), op); +} +#endif + static int blkdev_reread_part(struct block_device *bdev) { int ret; @@ -676,35 +707,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, EXPORT_SYMBOL_GPL(blkdev_ioctl); #ifdef CONFIG_COMPAT -struct compat_blkpg_ioctl_arg { - compat_int_t op; - compat_int_t flags; - compat_int_t datalen; - compat_caddr_t data; -}; - -static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) -{ - struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); - compat_caddr_t udata; - compat_int_t n; - int err; - - err = get_user(n, &ua32->op); - err |= put_user(n, &a->op); - err |= get_user(n, &ua32->flags); - err |= put_user(n, &a->flags); - err |= get_user(n, &ua32->datalen); - err |= put_user(n, &a->datalen); - err |= get_user(udata, &ua32->data); - err |= put_user(compat_ptr(udata), &a->data); - if (err) - return err; - - return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a); -} - #define BLKBSZGET_32 _IOR(0x12, 112, int) #define BLKBSZSET_32 _IOW(0x12, 113, int) #define BLKGETSIZE64_32 _IOR(0x12, 114, int) @@ -767,7 +769,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) return blkdev_ioctl(bdev, mode, BLKBSZSET, (unsigned long)compat_ptr(arg)); case BLKPG: - return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); + return compat_blkpg_ioctl(bdev, compat_ptr(arg)); case BLKRAGET: case BLKFRAGET: if (!arg)