From patchwork Wed Dec 11 20:42:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181315 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1041868ile; Wed, 11 Dec 2019 12:45:32 -0800 (PST) X-Google-Smtp-Source: APXvYqySqtZIrVMBe4Ealt9OIpACodemmlF4IoycCQEKZB4kzESRcVplyMboLUhJpeGX/NyJ/Mln X-Received: by 2002:a9d:39a5:: with SMTP id y34mr3627967otb.146.1576097132852; Wed, 11 Dec 2019 12:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097132; cv=none; d=google.com; s=arc-20160816; b=yV4NEygfF9Apsm2Di6pqjQ4ijRGyBTVlr69KFO6CJ/8muDQqfRoauXbUSUHxDmRSRy TuXIwA/tMhPNb4JbPjC4diSmkIkZOeQOfxNoNc3lP1jJb05k1XjndTahDnM2X4iQGeUR QKHJjRTjSOqTHkxbq+S9VqATPWbuEzDJop/T6kHI/pD4dJ3U85O/myQNexm3pxZ9jzLR 4ZjCmfq9zmiBRgA6rnjYpYTYvGB+3jAWdIRRQL6R2bkKE7zWiYt+eidDOOa6ETLkvAFk wJpErQU7Y261Og6uLsxmjldeLIsLuV5AK4RzXOVGjE5GVKbW0y1pqEGn7tDDJAyxfdVm VScA== 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=mK6Xfbo1V2hpB+m0R8ORXIdoEzu2hwjVARUBZgQ0crA=; b=xe8ETGNzgDhRm2IlQKNeCpACZeXAqnUI78ugLZ42XI5FWq5sg2sDuuKH9R3/Sgqgs3 9cCvSR2B8rlhj9ywqS2AU5THn+vs7Gu0suNYBx2EaPNf8LB5D0KJk1VVcEe4YAJXOoBE UrG7XRl719NBfrFCFAFIEjb0ZuU0gSMEsVz/w8vX/r5QYrP9boL+mpab6N2YXcAtlaAK pRG6gF2QvKrYneA/ifkeMh1rEfXoSZTOrXEiBT+dUCpWJtAIkVR0QoHHtvTsXM2qOhm9 QgpXd4vDarmAwFHemhmaRwjMXvWbLgEPFCd7sxNKLOsDyhEUfLlTxwLa8oG3F18Mn7HP 5Bhw== 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 c6si1787061oto.283.2019.12.11.12.45.32; Wed, 11 Dec 2019 12:45:32 -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 S1726613AbfLKUp1 (ORCPT + 27 others); Wed, 11 Dec 2019 15:45:27 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:59995 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbfLKUo1 (ORCPT ); Wed, 11 Dec 2019 15:44:27 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M8hR1-1iaRs43tkf-004kEW; Wed, 11 Dec 2019 21:44:06 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Catalin Marinas , Will Deacon Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , linux-arm-kernel@lists.infradead.org Subject: [PATCH 01/24] compat: ARM64: always include asm-generic/compat.h Date: Wed, 11 Dec 2019 21:42:35 +0100 Message-Id: <20191211204306.1207817-2-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:mz5wMeP1mI7KLnX+L9TZUVo6MIfdhwfA5AkmOs+OaphdklUbCnv X7MrRZI2R9VJWf66NRTLnVoMD6/5RMLHE3sUWVfolxdjEhWoRD3hstmd5OvxofRbJrFFUNM U0inFOTcxWdr9e0WR63XsUOuZLnDnhZ1/cLHTwAuxz2imLLI2AkfpqGZDH2tXHJueqlDJrw WzwJOQaA0tpR0khCs2klQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:5jcoHq9nJuQ=:BcHub+UBDAq7thiTpDno2w hSkCw8JTpuGlDJ57SmOUvV7vYHfSYEnIJSeWHWCp+bdDSoMCLrwMoJ7odEpI7WPtvB/ScsCvX VeNcQSKHIGcbiNr6/sqYv0LUIPEo7hppvFJSEtqOF37EVMjvgPUKUtF4HBXCpk0Qv2gnFmh91 Q5AnpgUNMu7WOZYqE9pKT2CGY1GEijsATykSiXwT1JyYR87rhdQZcEhx1tuppOD1KC0MDCJK5 x1wrBONVLyazD0Q/wnklpJPW2Mms4LzT3Ort5hQVmp/MItiaBcxs85dOHOFiDvuob622PfNOV PEDjts6WgUADfTCBpFPWOcw7WwWbSDqRM3PmRgqEGkxmu5bKOMfVqbq6n9+3N4dptgwE6fDOn /A4T6BKSblu+oPkGFGBZQjDyC1SMwpWBPHvrOdyPnIPMfIs5ULnIkxOJBty5xLKC0e0meDH9+ b4tf89eeCRcctW9EV6YKAfobJs2SwCW83Tslrp46TVUCeQz4qUEPW3KwdgALLQ5tSZRT2r2hK Tbsc9JsabSWTA+wBNM/jL/actcRW5K9G+qn2EDyqMD4Xkf57Y0GRmBpmX+YUXOr5//J6q5O3P i8mzTH1iwJ78Ki3iKyPadTRxzutFG4fEZc9C9WpSjQSU9PGBW9Wdd+YaY565zaJFLYICgy/IG sYzvlRm9IEK780kxN1oEFgawAcIXTryC1iAO4mWE1E+146mOi7CPZOufM4oztTZtaRV0Q7HHr /LiW6o/Juxdn0noEDDvQ3Br5nYMzuo6xUUfowN5iAd8VF+A3ACDBsRdAgeWsRBDRdCwDTjHr2 wDcgxTwXMlZAe8sjLiqZVYp2RC5Krc9DwXkwsg1nmKODL7eO+4vgb38hZWP/qBtq1KbRCaAit lAicoBqmZ4Snql/Awy/Q== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to use compat_* type defininitions in device drivers outside of CONFIG_COMPAT, move the inclusion of asm-generic/compat.h ahead of the #ifdef. All other architectures already do this. Signed-off-by: Arnd Bergmann --- arch/arm64/include/asm/compat.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.20.0 Acked-by: Will Deacon diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index b0d53a265f1d..7b4172ce497c 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -4,6 +4,9 @@ */ #ifndef __ASM_COMPAT_H #define __ASM_COMPAT_H + +#include + #ifdef CONFIG_COMPAT /* @@ -13,8 +16,6 @@ #include #include -#include - #define COMPAT_USER_HZ 100 #ifdef __AARCH64EB__ #define COMPAT_UTS_MACHINE "armv8b\0\0" From patchwork Wed Dec 11 20:42:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181320 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042515ile; Wed, 11 Dec 2019 12:46:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxe8pdmigNHLtFEZe4yw8U0jsbeo0WUvmDiuGKCbrZnqYdcZp78P3GAJWELZFT4YcjV0Lwv X-Received: by 2002:aca:4dd3:: with SMTP id a202mr4377095oib.3.1576097169351; Wed, 11 Dec 2019 12:46:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097169; cv=none; d=google.com; s=arc-20160816; b=oKLW4ZK381NAinxwE+yuT1sO0W5kiPw0ZeJH05SH1auUydNY6ktkBG9umP7mKBNPww 6B+VjL8jZq6+pmcKE7nGIbZ9ESzY+/OWHtYN0U+vS3bCis/3ahOL5OOcJDZ5Zau8/DS4 eLHe/w3k1TDczhuGwWAUGVDw0FFVXoEjUwsXuuxeFC2wX9T7/VJPXdPJqDKg1X5Mpmfk hXKr6llFcWP0nM0S3iocgXFpW87blpqmv0rvqLDYaeCjXCGb07ZgMbwqKwve0quHeiUk j8d0/QqMEe1fRohsAqXphcwLmDKYB8J7bXM4dNnEet3X0e/+ZjzP9Oe4jlJKdFsVFr77 SujA== 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=DvwhaYYov/KMqvr9Xb8eSXzSyR2n17YridJLkvS5Ym4=; b=wyqZqDTshLpfmm/dcvE2ys/9f+bThh/ohsxsNTf2P1pr0gNoSomU7tBta5PIgn3Y9l bNriIq/DdUOZUC0x3kJDhhzsrekCZyou+hx2bIPs546Zhwyc49ouoTiSWmBksZFc9SK8 QOJxCIXWZ79CL7tGDzxy7WDHD1GlP1sQRMNwHFos3+2WFuuAjUIqllyKKzly/a73+kHG e+QZo56fJCfP5oyIpVWBxjoMmdTeZE6+fE6d9nj6JtRjQPAFJvNp0xx7T9UyGkePsyTi 0QO+K83hW2NmRTMALkrjGksnwV4S91CGFBUnWW6vlKvroYdUbDmD5+UMqpyduhSEoglh jjAA== 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 j71si1856935oib.213.2019.12.11.12.46.09; Wed, 11 Dec 2019 12:46:09 -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 S1726930AbfLKUqI (ORCPT + 27 others); Wed, 11 Dec 2019 15:46:08 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:40797 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726890AbfLKUqE (ORCPT ); Wed, 11 Dec 2019 15:46:04 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mzhf5-1hjio20Ph3-00vbw4; Wed, 11 Dec 2019 21:44:23 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Douglas Gilbert , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Steffen Maier , linux-scsi@vger.kernel.org, Chaitanya Kulkarni , Greg Kroah-Hartman , Thomas Gleixner , linux-block@vger.kernel.org Subject: [PATCH 02/24] compat: scsi: sg: fix v3 compat read/write interface Date: Wed, 11 Dec 2019 21:42:36 +0100 Message-Id: <20191211204306.1207817-3-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:DlM8/RSZOaYg5JzO7DSn/knKPUvnvQmVJDNmgl9LouBnU4D8Xp1 /K/nZQCkejcMwqd34K2Q2OBGVdjrDhpVh8FPdUh0byRt9SW3BLbCX0oUB4xrMRk2xwLEfnB RlZHYWzNGZ9YtHMdiUUn1opDUpu7tCIjKc27WFY9HYeiSanGdlq9NRJjwNv7rVKJxk32BCY AE8eyDTr8OCkKgIhZDYog== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:57TTBnsP064=:xol5gk1SJmTe2qSSdWnL0w 3a3nqIlxgWVtGDMKinfkP6M90bf9xUBEtxuQBD88/UGfqgJAYOiM7L3PPdvTmo9lkvzTpZQu0 aUTZ4eiVwRshqensZ4GKhfWdBPld8QbYTSY9AVe0TMeyObvH+y9LetKeAUGCABADtnS5Qkw5G EcSoZvnK5Lh3Epls01CDs91roWqGa/ZaB1C5nZLdrpsVFCSavlzMrMmw9kK5LCanpNY/QQACE obCPL+eBF62x1XXEBpYGO8jj61UjgoLj5JcB1en4jh6StDSuF4kmBkDPiRKfFH/4Ny7uCuau9 IBq38vB01H0aEfl268UwWIhsAkmlYXh5yab5jslBPHtuXVZSHql+g6klZ2QWwISYO+TIbWmIG 5g9r0L3ulEJvK/xWDYygijvQo87e6JaMDPWEfVegNznVpasGpwDFZbpn6jq6BKlAee1nL/Aee F8iDOJ6oHpHeDJ+Eu+Z39lV64O9xRSJnuwiFTjIA0agfWveVlmVDoAE8X1t9EcG48N0TRFAqQ Gboa2XdlGNmU4keGeZkZmppSFyE43e/M2U4qftHy1xXmF8xIVVmLRIPp80G1F1A7JvaYLKCCq exaZWu1X5Bj8e8K5pTct5soi2v5F6KiJSu0rOxoIqd4Wvntn9bIrtn8sYFqtnYMphzH6FmHUB XY0X4+deX3vRvsf8L5WE89BH8edm6St/YYxJM2hqRjUIg4Y1x/H+vfQx01oxzSZSpRrExc8v4 L3VXA8er+Zo+OFOvu4LSXOhlYxpXUf/nzl2mA8g6uFBRVQJIxz9vpVSXs9O7Csk/l762+jDUa JAewa1xpYzvxig7e+Gw4SqhYNWc2KYC3u7/Amh+SzvE+r0Zdg4ZchYXdUubg2vH0DZ5gAGXr6 zbeTPLkZhfhYLYWMIQfQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the v5.4 merge window, a cleanup patch from Al Viro conflicted with my rework of the compat handling for sg.c read(). Linus Torvalds did a correct merge but pointed out that the resulting code is still unsatisfactory. I later noticed that the sg_new_read() function still gets the compat mode wrong, when the 'count' argument is large enough to pass a compat_sg_io_hdr object, but not a nativ sg_io_hdr. To address both of these, move the definition of compat_sg_io_hdr into a scsi/sg.h to make it visible to sg.c and rewrite the logic for reading req_pack_id as well as the size check to a simpler version that gets the expected results. Fixes: c35a5cfb4150 ("scsi: sg: sg_read(): simplify reading ->pack_id of userland sg_io_hdr_t") Fixes: 98aaaec4a150 ("compat_ioctl: reimplement SG_IO handling") Signed-off-by: Arnd Bergmann --- block/scsi_ioctl.c | 29 +---------- drivers/scsi/sg.c | 125 +++++++++++++++++++++------------------------ include/scsi/sg.h | 30 +++++++++++ 3 files changed, 89 insertions(+), 95 deletions(-) -- 2.20.0 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 650bade5ea5a..b61dbf4d8443 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -20,6 +20,7 @@ #include #include #include +#include struct blk_cmd_filter { unsigned long read_ok[BLK_SCSI_CMD_PER_LONG]; @@ -550,34 +551,6 @@ static inline int blk_send_start_stop(struct request_queue *q, return __blk_send_generic(q, bd_disk, GPCMD_START_STOP_UNIT, data); } -#ifdef CONFIG_COMPAT -struct compat_sg_io_hdr { - compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ - compat_int_t dxfer_direction; /* [i] data transfer direction */ - unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ - unsigned char mx_sb_len; /* [i] max length to write to sbp */ - unsigned short iovec_count; /* [i] 0 implies no scatter gather */ - compat_uint_t dxfer_len; /* [i] byte count of data transfer */ - compat_uint_t dxferp; /* [i], [*io] points to data transfer memory - or scatter gather list */ - compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ - compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ - compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ - compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ - compat_int_t pack_id; /* [i->o] unused internally (normally) */ - compat_uptr_t usr_ptr; /* [i->o] unused internally */ - unsigned char status; /* [o] scsi status */ - unsigned char masked_status; /* [o] shifted, masked scsi status */ - unsigned char msg_status; /* [o] messaging level data (optional) */ - unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ - unsigned short host_status; /* [o] errors from host adapter */ - unsigned short driver_status; /* [o] errors from software driver */ - compat_int_t resid; /* [o] dxfer_len - actual_transferred */ - compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ - compat_uint_t info; /* [o] auxiliary information */ -}; -#endif - int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp) { #ifdef CONFIG_COMPAT diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 160748ad9c0f..985546aac236 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -198,6 +198,7 @@ static void sg_device_destroy(struct kref *kref); #define SZ_SG_HEADER sizeof(struct sg_header) #define SZ_SG_IO_HDR sizeof(sg_io_hdr_t) +#define SZ_COMPAT_SG_IO_HDR sizeof(struct compat_sg_io_hdr) #define SZ_SG_IOVEC sizeof(sg_iovec_t) #define SZ_SG_REQ_INFO sizeof(sg_req_info_t) @@ -405,6 +406,36 @@ sg_release(struct inode *inode, struct file *filp) return 0; } +static int get_sg_io_pack_id(int *pack_id, void __user *buf, size_t count) +{ + struct sg_header __user *old_hdr = buf; + int reply_len; + + if (count < SZ_SG_HEADER) + goto unknown_id; + + /* negative reply_len means v3 format, otherwise v1/v2 */ + if (get_user(reply_len, &old_hdr->reply_len)) + return -EFAULT; + if (reply_len >= 0) + return get_user(*pack_id, &old_hdr->pack_id); + + if (in_compat_syscall() && count >= SZ_COMPAT_SG_IO_HDR) { + struct compat_sg_io_hdr __user *hp = buf; + return get_user(*pack_id, &hp->pack_id); + } + + if (count >= SZ_SG_IO_HDR) { + struct sg_io_hdr __user *hp = buf; + return get_user(*pack_id, &hp->pack_id); + } + +unknown_id: + /* no valid header was passed, so ignore the pack_id */ + *pack_id = -1; + return 0; +} + static ssize_t sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) { @@ -413,8 +444,8 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) Sg_request *srp; int req_pack_id = -1; sg_io_hdr_t *hp; - struct sg_header *old_hdr = NULL; - int retval = 0; + struct sg_header *old_hdr; + int retval; /* * This could cause a response to be stranded. Close the associated @@ -429,79 +460,34 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_read: count=%d\n", (int) count)); - if (sfp->force_packid && (count >= SZ_SG_HEADER)) { - old_hdr = memdup_user(buf, SZ_SG_HEADER); - if (IS_ERR(old_hdr)) - return PTR_ERR(old_hdr); - if (old_hdr->reply_len < 0) { - if (count >= SZ_SG_IO_HDR) { - /* - * This is stupid. - * - * We're copying the whole sg_io_hdr_t from user - * space just to get the 'pack_id' field. But the - * field is at different offsets for the compat - * case, so we'll use "get_sg_io_hdr()" to copy - * the whole thing and convert it. - * - * We could do something like just calculating the - * offset based of 'in_compat_syscall()', but the - * 'compat_sg_io_hdr' definition is in the wrong - * place for that. - */ - sg_io_hdr_t *new_hdr; - new_hdr = kmalloc(SZ_SG_IO_HDR, GFP_KERNEL); - if (!new_hdr) { - retval = -ENOMEM; - goto free_old_hdr; - } - retval = get_sg_io_hdr(new_hdr, buf); - req_pack_id = new_hdr->pack_id; - kfree(new_hdr); - if (retval) { - retval = -EFAULT; - goto free_old_hdr; - } - } - } else - req_pack_id = old_hdr->pack_id; - } + if (sfp->force_packid) + retval = get_sg_io_pack_id(&req_pack_id, buf, count); + if (retval) + return retval; + srp = sg_get_rq_mark(sfp, req_pack_id); if (!srp) { /* now wait on packet to arrive */ - if (atomic_read(&sdp->detaching)) { - retval = -ENODEV; - goto free_old_hdr; - } - if (filp->f_flags & O_NONBLOCK) { - retval = -EAGAIN; - goto free_old_hdr; - } + if (atomic_read(&sdp->detaching)) + return -ENODEV; + if (filp->f_flags & O_NONBLOCK) + return -EAGAIN; retval = wait_event_interruptible(sfp->read_wait, (atomic_read(&sdp->detaching) || (srp = sg_get_rq_mark(sfp, req_pack_id)))); - if (atomic_read(&sdp->detaching)) { - retval = -ENODEV; - goto free_old_hdr; - } - if (retval) { + if (atomic_read(&sdp->detaching)) + return -ENODEV; + if (retval) /* -ERESTARTSYS as signal hit process */ - goto free_old_hdr; - } - } - if (srp->header.interface_id != '\0') { - retval = sg_new_read(sfp, buf, count, srp); - goto free_old_hdr; + return retval; } + if (srp->header.interface_id != '\0') + return sg_new_read(sfp, buf, count, srp); hp = &srp->header; - if (old_hdr == NULL) { - old_hdr = kmalloc(SZ_SG_HEADER, GFP_KERNEL); - if (! old_hdr) { - retval = -ENOMEM; - goto free_old_hdr; - } - } - memset(old_hdr, 0, SZ_SG_HEADER); + old_hdr = kzalloc(SZ_SG_HEADER, GFP_KERNEL); + if (!old_hdr) + return -ENOMEM; + old_hdr->reply_len = (int) hp->timeout; old_hdr->pack_len = old_hdr->reply_len; /* old, strange behaviour */ old_hdr->pack_id = hp->pack_id; @@ -575,7 +561,12 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp) int err = 0, err2; int len; - if (count < SZ_SG_IO_HDR) { + if (in_compat_syscall()) { + if (count < SZ_COMPAT_SG_IO_HDR) { + err = -EINVAL; + goto err_out; + } + } else if (count < SZ_SG_IO_HDR) { err = -EINVAL; goto err_out; } diff --git a/include/scsi/sg.h b/include/scsi/sg.h index f91bcca604e4..29c7ad04d2e2 100644 --- a/include/scsi/sg.h +++ b/include/scsi/sg.h @@ -68,6 +68,36 @@ typedef struct sg_io_hdr unsigned int info; /* [o] auxiliary information */ } sg_io_hdr_t; /* 64 bytes long (on i386) */ +#if defined(__KERNEL__) +#include + +struct compat_sg_io_hdr { + compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ + compat_int_t dxfer_direction; /* [i] data transfer direction */ + unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ + unsigned char mx_sb_len; /* [i] max length to write to sbp */ + unsigned short iovec_count; /* [i] 0 implies no scatter gather */ + compat_uint_t dxfer_len; /* [i] byte count of data transfer */ + compat_uint_t dxferp; /* [i], [*io] points to data transfer memory + or scatter gather list */ + compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ + compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ + compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ + compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ + compat_int_t pack_id; /* [i->o] unused internally (normally) */ + compat_uptr_t usr_ptr; /* [i->o] unused internally */ + unsigned char status; /* [o] scsi status */ + unsigned char masked_status; /* [o] shifted, masked scsi status */ + unsigned char msg_status; /* [o] messaging level data (optional) */ + unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ + unsigned short host_status; /* [o] errors from host adapter */ + unsigned short driver_status; /* [o] errors from software driver */ + compat_int_t resid; /* [o] dxfer_len - actual_transferred */ + compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ + compat_uint_t info; /* [o] auxiliary information */ +}; +#endif + #define SG_INTERFACE_ID_ORIG 'S' /* Use negative values to flag difference from original sg_header structure */ From patchwork Wed Dec 11 20:42:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181319 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042434ile; Wed, 11 Dec 2019 12:46:05 -0800 (PST) X-Google-Smtp-Source: APXvYqxIkqbiy9gaav0UQzfmmqQCFsDcn5flJkYua0bZYOybD8xNyaabMacw7Ppeg/Al6IkmP2V3 X-Received: by 2002:aca:220c:: with SMTP id b12mr4113269oic.55.1576097165165; Wed, 11 Dec 2019 12:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097165; cv=none; d=google.com; s=arc-20160816; b=i8T3+AFYmgAHALDJ6qMyhqfOm4EbPHyFegKJ4sdwrMmzYeCHZeLwppQidUNgqmVNbO 6KubJPhNJDLjWuOiZAfVdafgTZoqbhrHY4KWT87wOQLtgUmPsvlV6RONOpO1nZwQOoJ1 v+8Pgpcq+SfiobzjU0HQyVxZItEgSXLaDmISFt+8IRMn8YBvfwC+vu7uE1w/j2RfSm8x KntOPjfgzdOtoN9UYabVlNQZWN8Sr7HWWByjqY/wf34W1IGZ2F8zkh6Hub8i/sVCYfIU +ApQ28Wfy8h1+wpEpyM9T38zh+i8Ca7KfcnPohopbcfeqWWMmINDLRtPKQ06M0UzLKNU /5Ow== 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=P4TuptZhDN4tYex45+sla69Z3qAiFmunScTMGOFSxHA=; b=kbWe20HFAr1JzkVQb+Yv347+KYGpoTmOT1yJwOl2IHBZJMc9vfwdYx41/vMYhpJkwf kMW/Dy1CB5Nw6bSekNookN0inM1cMM8RYibO1VjiGVY5kd+f7N7mHpTALId3SmT0IsoZ qvLScunuANVHmDxT3l87Jzbo1odSnYkLr7M3+9sU5ACYNPnqMFSaeHCPNOkOjV9USndd UkIST6Cl1LZXltdjgCGmWfIS/4JA3nImyl3BadLP33rwdGbKVBd6UOL6YxTLV2ooEctl bItMCk5XDGqpQ3Dvk4HAze1a7D/wXAlhmChjdnYGHDCrTkSowdIff+s8laNSTuAAiUK2 rxwg== 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 q10si1955023otn.53.2019.12.11.12.46.04; Wed, 11 Dec 2019 12:46:05 -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 S1726884AbfLKUqD (ORCPT + 27 others); Wed, 11 Dec 2019 15:46:03 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:54949 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726824AbfLKUqA (ORCPT ); Wed, 11 Dec 2019 15:46:00 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MtfVx-1hrzjx1qbH-00v5Yw; Wed, 11 Dec 2019 21:44:34 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Jens Axboe , Hannes Reinecke , Damien Le Moal , Shaun Tancheff Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , stable@vger.kernel.org, Shaun Tancheff , Christoph Hellwig , linux-block@vger.kernel.org Subject: [PATCH 03/24] compat_ioctl: block: handle BLKREPORTZONE/BLKRESETZONE Date: Wed, 11 Dec 2019 21:42:37 +0100 Message-Id: <20191211204306.1207817-4-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:tUHZTqYugYCYUwAQZWPackACXJTSUKL9x3lbDrGZrX999DK9Asp TVe964nJnMAgtKxNZszDAtDuKLzdq2+bKOi/TqfobbZHHI8sJXCBGqZU/QHvOzN+d6zOfS/ Zr8LsXc41Dvhge0/mLw1M78GQTOdVLa+/8mbuDopq13rvC8A8dLivfsUuc3sqFq2hbpqt+a 2T7gy1fgYL0l6KRKhCfjQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:8Ca/Kaw5pJ0=:pX2Fj/FOn33vjECxD2DR3C gSxWY/h8Xl8vHByOcl7R6E0JSiBUsjc+vyap3TL0a6nyiYl2MU9J0aP3apJ/rSnZYrPZpnkPS W2Xj8SOJv52EZqY82PIfqVHzu/QYq/aFoZZEcTlkXKLxoDtvGqLzsuU1mQbE4bGkv7gV4QZRV GPFKQ9MhGGRABXA+ROegxW6pu7ZPeqmyRkIWjVUZrT6b4HWFU94AmaKqkUpUaMmMWdu5+/ixQ /Ul+joTcYsyc0l3f4EYl5USyRrjUhx9vmA0dn2K/SihYox24fWdJFg2bOZnUpJunQtAVjGO+s x/ZhligRpVhEpCI26y5LCJ8Gjkv8oy88jk75CvLFAUaN8RhX4rGmElV6Wa91PBzA7r1K29LYM lyJS4JJ+tV/5KzKmkkuQDhdgZXSzwbp76MIz9OdCKazzUDU+rOqmJEiQtworObbgI3mQauy8o Who5zGuZvHCwG5zcIF1tzTs+hoEVYsXSKQZquno2ai4gncriNKnh4br+M3OcioyNTgSZa6xrQ eF1lVZzXvPqtkSK5Rrwibef0ucVGO/lE+u7Mq9FsNgSuuYLHZAjDsDG+lda0sX6lD3i9ZHAEW fvrpdrl+fRORccEuDSkXTWZtcGTpP2zm2nFZE++CcLXGIQQVmfg/Ba9bA4/rrg3+tdoBI9MVw g/65hRQfWlwg/JC86yDbUxiFSbif0nzxXhhJV+8nZFklGG6ufyXvmACSOAF4BpOCTQJacgbzU dQ/QhZ2biI9H+kwB0zcwO1iGxGAaRX8eStw11rJRX8C+rfEAGLHbMJ8axdDWZoMEpMEmw5hvq LkO6gW96Cnj0eIdRUkFYDPOD4b6On+m6shG6eLibyp2LZ4NRSeHkIrdqCdaEC2Nr3B+Sz7sj3 u+m1hGTzY0O37G2+CxFw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These were added to blkdev_ioctl() but not blkdev_compat_ioctl, so add them now. Cc: # v4.10+ Fixes: 3ed05a987e0f ("blk-zoned: implement ioctls") Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.20.0 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 6ca015f92766..830f91e05fe3 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -354,6 +354,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) * but we call blkdev_ioctl, which gets the lock for us */ case BLKRRPART: + case BLKREPORTZONE: + case BLKRESETZONE: return blkdev_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); case BLKBSZSET_32: From patchwork Wed Dec 11 20:42:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181317 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042280ile; Wed, 11 Dec 2019 12:45:55 -0800 (PST) X-Google-Smtp-Source: APXvYqzpqBeIrKjppT6er32ZNxSlwvfL1ZslX4pTloEHRSQVT9mU9KDNNE4P8U4Wgt1SsjZafZP3 X-Received: by 2002:a05:6830:18cd:: with SMTP id v13mr3778890ote.118.1576097155874; Wed, 11 Dec 2019 12:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097155; cv=none; d=google.com; s=arc-20160816; b=j9w2brT53zg/AuzHiQwUfykJmHrvtDEONuOwt1vjJjqaChT1kDfQwRZVzDmCubNyS5 aufvebjV7GH/kijdUfTDDKW9p0aQTt0ltWTl6iF/get0HEbrTGg/xLub2HutkK9cRzhN Gca+sHQ7RWRgMmq4B9+CqzEiON3lJVU07hBWTRKLGYg+7c0NMVQc7j5qKu8sd7EWoaQu 2pyIl3ERabz2JywRBZhru0dlxdWZYVX/+DCvk4kIXePOBzSi+mU1CL7oHHCtlzyKrFxG 0RxSbK7/8c4hPW6a6Y/gZWTU+dilIFYPM35IDeHIjyU9zFVGCMGOoVSbw6iG0QwcfQqm q9BQ== 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=S3+nSil5K3Lu0xdE7CqRdAuJtX/1I06dt/tZJdrmwBo=; b=HnUk8PcrSDF1esRrIsmlQAxX6Z58D+WrL8T3w1heMiN55hfdAEJeaPtsq2+Uk8rIqY zZC0tQzmvu4LKLVnqGtGyuTNAG35PFJtgltkUmwGcmdyA4tOanyqCZ9jcZQsRN2L6oKT jy39q8fl1SXfggOQGC2P/Yf4r2IewdZ8cx5MG1+j8fLwSGdYnf6ieBEz4EeGCtfhjqM7 IVeVSLQ10Vt93UgA/rIqFoITXWud4y+AK1tfOSLjfkZ7dbACEseMiY1RznJCySk36JIW EgzxRx8IeTuDFiYymhqmIhLie8rJrlAJoNg+E02Z33B0nYAnEsfzu9yxiSdAbG9Z+/Lz xanQ== 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 r1si1754469otq.298.2019.12.11.12.45.55; Wed, 11 Dec 2019 12:45:55 -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 S1726769AbfLKUpy (ORCPT + 27 others); Wed, 11 Dec 2019 15:45:54 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:56465 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbfLKUpx (ORCPT ); Wed, 11 Dec 2019 15:45:53 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M5fQq-1idU9L0Vhq-007E8d; Wed, 11 Dec 2019 21:44:41 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Hannes Reinecke , Damien Le Moal Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , stable@vger.kernel.org, Christoph Hellwig , linux-block@vger.kernel.org Subject: [PATCH 04/24] compat_ioctl: block: handle BLKGETZONESZ/BLKGETNRZONES Date: Wed, 11 Dec 2019 21:42:38 +0100 Message-Id: <20191211204306.1207817-5-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:7VRHp+IKRwV2Q9YentDGY5xMSAqEOhk7ZARK0JfIsCS+oOLEuza EzQyPOHsQNVHmCOd2y0s+ZGIglq00NyJws3hpQiZcA4cow9FHjmLk3v5elOH2eBhgann8xY 928DwvCV5XQhcL0UtEPyXrPXlIQtcYB91MJk24tTX4hhZV/39SFX18bzQunL2y0vECCFc6h GKP2Io5tZThqRs1BYRBBg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:iq5JBLlu3+U=:/ECo3/I2OfudG0vBX8xJhb fx5gydprst2zUW/oZ8T2Tvh9+s+ePA1wGKvIva9yvBaIxQzdNusGcKec3/xeFDMz3U/Q73heD XZB05O1vTbWINtAk41Y10queHAC4cW0WBtC+yMt3B6QJ6clE+8wray+pupDtPctdlCpwO07vy ghmjZ047czufM9C49L/Efgkhp4fSp4WG0aWRGZyhs+9IqR+K8CYHrBZDa2GqJRF3JNirB8i32 xqdY+zN2J74AAkqVl6snre2sped1hur5lDTlANtgJGNUN2//kHYmitZy72JV5/H7K7ktWZTXw gVu0503X+yqC/c5epuBsq+xuvbK6vsP4r/CCe2qHZoKyG1mfWmmLkKp3Ca1QTxPGMb1SuMQXM LpDU8dBaAlP4RvR+j0Mc+IRuM6SL2bh3MX2jTXKKKwlpd5O7KqLi/rJbxriAGlW1+6F2fChEV TkfaRUaWMQKsRkmOOp35FkGxdAONa4B5BmxB1yOgR/CGROXGTdLfgSQdA/jL2PyF7O85f6ypz vy//qUe2fsTMWgskorZQSRH8Sh2JtE+ycRYubObY/eshvzUJK8QdjbWDDnxAMpHw+wZX9h+9G sKgKahjQuBISN8cgOMEac/xfsHZgiqQhs+HaaYwl3Eb21tXSm6LprSLbNFS6igtpu03UviyTM DP4ECPqC8Q6kU1rPtPbThrvlUbdMArO67y9TS8xZD5fRlbExyJlya3YFVp5XsIn1EfOmjTHVq b1hNbMHeCRLKr01MAHseLxaK2JUCvsjzehSCLRuxcKcx/Ll+z1C56n70JaRNN9xchQurT7eG6 kmmTfmj8E/SNcO1INGrjkhukC2tF1dpKaUtP01A+M5bWP6e6entdDhPyiNA8QMhFyIjNzgg83 E3+Rkn+cmASvGcXVQAzg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These were added to blkdev_ioctl() in v4.20 but not blkdev_compat_ioctl, so add them now. Cc: # v4.20+ Fixes: 72cd87576d1d ("block: Introduce BLKGETZONESZ ioctl") Fixes: 65e4e3eee83d ("block: Introduce BLKGETNRZONES ioctl") Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.20.0 Reviewed-by: Damien Le Moal diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 830f91e05fe3..f5c1140b8624 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -356,6 +356,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKRRPART: case BLKREPORTZONE: case BLKRESETZONE: + case BLKGETZONESZ: + case BLKGETNRZONES: return blkdev_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); case BLKBSZSET_32: From patchwork Wed Dec 11 20:42:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181318 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042384ile; Wed, 11 Dec 2019 12:46:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyYKO+8Ab9A/W+nD/BXkmlhMqIJlm73JUCBuf20CkFVslLMFtcQ49HYdyQn5KAv4drQpqRE X-Received: by 2002:a54:451a:: with SMTP id l26mr4362632oil.69.1576097161990; Wed, 11 Dec 2019 12:46:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097161; cv=none; d=google.com; s=arc-20160816; b=qMxEzy9Erfz8mJ+4la40i2tS8M0UCfdxx3bg1vQWL32G9YZp+4aYhzkPoHj1i/zJpx gVYsgpNmf7y1snmYZBKqnpDpuDQJwHwn/X46TAai9mTHkuflax8On0+xInd2O+f2t/EP EoADaZzLu227zRlQAMnjfE53/yUr3i9EpVAPkwuGvpAw8zTtzmUcd31hSp6p14Hr2Wjl WMurCDhmv/16lGSyEEgaMgZq+ZH70tSXMLmNsXDHO3Vcp43HMFRt3twvQ+1iDJCohm/P ndC60zUH4ypjSThdGoYbil4BUVyZjbGQjNw0TRSgZTR5NVMDL9IME3GiiM+5cnDQMFfO /17Q== 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=RNcmVXAVAm1eaQs1hlIab8YVHih2i8Q71Oh4kk7vJeo=; b=bdvNhBwNQkpI4KoHeHQf/+gT/K0yIyIjflj99rZgwCGb6IiCjSUqf1Nwi36Dfl+FGk dSnMU8VqjqYu5QqIGCtBJMLVx4DsGo9en8rDcxcZ845/5ir3il9PimpNLtgEcCw1hh9S 9OmgCVU6a92he4AqQ3OI2kz1OPXF7M23f95rgqosxmOnEBb7wCGCOl9yc4vbl7iPumwb rDivkXkZgBIQol0/dUurfAv6R6C3/XtYaZbexVhG+SyVaxUFc8pkuviUEYmOz5JsonVb RxViKJV8wb75B+lWfAxf3CJTJEjDI35KiBBrsdbf9pIXdGlRn3xlLPbDyYaPAINWZjkx mXjw== 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 d62si1996667oib.144.2019.12.11.12.46.01; Wed, 11 Dec 2019 12:46:01 -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 S1726831AbfLKUp7 (ORCPT + 27 others); Wed, 11 Dec 2019 15:45:59 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:44829 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbfLKUp4 (ORCPT ); Wed, 11 Dec 2019 15:45:56 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mz9hF-1hkH0n3Mhf-00w9tu; Wed, 11 Dec 2019 21:44:54 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , =?utf-8?q?Javier_Gonz=C3=A1?= =?utf-8?q?lez?= , Keith Busch , Hans Holmberg , Matias Bjorling Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Christoph Hellwig , Ajay Joshi , Dmitry Fomichev , Damien Le Moal , linux-block@vger.kernel.org Subject: [PATCH 05/24] compat_ioctl: block: handle add zone open, close and finish ioctl Date: Wed, 11 Dec 2019 21:42:39 +0100 Message-Id: <20191211204306.1207817-6-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:T3P5inF1wAM0JTp0sDl4O/rqOEQcKKwFPNK080bhsoSzCuvH5os ZIz9G1k8iLEMcivvXznzuZIw7nXoa/IH9pBhTIMo4P4a9A/jq38deJ8BsqLgViD1Gy9X9Z2 amoGNEETinCQm5AIH4yoHFkPvGOvZBVENg0im+gyXDWmVBV4mvW65rzxxvxBlkQGl7iAkuq keBfNdGCjbKGo/blJPJ3A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:y0zEiubbezU=:bi2nIJ6/zTdNQgNrAQOGBX V7vMHhKw/sGC5woyeRTf4QRRUx0TgILAMf8tehFX0MaOP6jFADznPL5YvFZdP/8KBsa8VHUbC aTSmvIjP91oBYVflD9bf3dTv+TM4jQxTpzv15O6HEdOexET67KWy3Be6UFfb4hG5D8FXNGm9F GdOgK7uOqItMAqHbxSqQOX0m0PDdLflVHlRzfCzmMtszJqW33G3ZUyE7yj1rXZzDg7gDYuZdc idOE65NXc3yZz+eiqNSKf2IzdL0nbFdboeLDpfE9UayxXtFjNaqvmEwlyUtogWyleRJXi4Ook gNqQntW55PioCE+OFYKe+s7zE9lN3rNUQ0uWWkCcU50lFGb3Ghd2ImwjmjTtJX9avACuqBLl4 Eq222g4k2YtpuZralMccFnATxMli3e1iUWiT909sw8PyG1g9bap0E1UM6a4URRJ9FE75iUisi tNPlPIwCqTv63RQ3ffUFwl2rWDoRRxjNGhaE32WBkrUYUb8HDWOYNnToxia5Lqhr834m5/QNG xZg8yXK4XMgdHWgXB6c3t63k6K0W0hNB1XAE4cad/gkEFsSZjw8JGgSVsbMMM5nXxdC6RKT/S ZdqOOs6nRczydptZAMhfub/HIFnQPsECNsGVeErqLKRWYl5VVSwAYzmGjjvhhOCBkrl9oV1oL pEb5rDH4teu/dkisZNrqdJgJnE9MGEuDMShclIPlpqmwwC+pVhxb3vTzOIWAFiQHY2YtKYlcU W+/gq1Grakw6tdd5G7LstR7Mm8eYYSBldJ1lCrJ6q/MgyasJLcJ+FBr6vxzpiSG7I1Urf4OAj 0uZU2cZH62GHsFyTBOmKkvWmRX3czxeCNqr4zQA78VMDQQRYzn1QsCw8Kj9LoaPBw9tA7oJpa z3grqTX8c9r65hGmvbqQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These were added to blkdev_ioctl() in linux-5.5 but not blkdev_compat_ioctl, so add them now. Fixes: e876df1fe0ad ("block: add zone open, close and finish ioctl support") Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.20.0 Reviewed-by: Damien Le Moal diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index f5c1140b8624..5b13e344229c 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -356,6 +356,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKRRPART: case BLKREPORTZONE: case BLKRESETZONE: + case BLKOPENZONE: + case BLKCLOSEZONE: + case BLKFINISHZONE: case BLKGETZONESZ: case BLKGETNRZONES: return blkdev_ioctl(bdev, mode, cmd, From patchwork Wed Dec 11 20:42:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181332 Delivered-To: patch@linaro.org Received: by 2002:a92:5b50:0:0:0:0:0 with SMTP id p77csp1041366ilb; Wed, 11 Dec 2019 12:50:30 -0800 (PST) X-Google-Smtp-Source: APXvYqxZC6HCW1tt8tcvt4eYC0rzTiLLVCf92gSS7ntg9jc8XmX+5gVKPDgGwfwU6rQQry//ml5q X-Received: by 2002:a05:6808:98d:: with SMTP id a13mr4254400oic.7.1576097430739; Wed, 11 Dec 2019 12:50:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097430; cv=none; d=google.com; s=arc-20160816; b=q0ESb0cjd/8GEoO6KL+K/yH5PgEimGvaNrsK/nO8ssynAx0U4RUr3RMaMkajoa8I/h c0lKvVH34vudWKfox/pIO/yp7qiKM5rjgvsZxmprtYixEXWyo2C9Bc64Ql3/KfAUCvFI ab03FSKOtPxB1+PgEe5eAOU52UmGYQH/381wbfCs40z8CfH4bvd9JFVS3CNEOj/xrLiu cn5TspXfs9SvyvU+aDjnFTQL8BeBNWpDs2jTeq9sjXNIWbyBW1Tyectop2eNwhjE0cfG ibdRqdF3CIjMyiZQjlAWycba43OCUH6MMPY+xsjRJSQtpvU4qKO8LI1VAd6LrvSIaQxM z4aw== 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=YpKmobFYt+kMB923srnVV+v+jag87t3BW6FRqyC7c7Q=; b=ffHksdOWDaJA5JifVcL1VQ0KaSJagrt/GpLZHJJlYRuAdDFPwuU4BQFLd6vf6wWGEU +EsQFk8J80q1mIdeDZwa9slmVi9/wBH/AtwfqS6RY7LEd8DiTHMxcALrnswuIzw+i9ek YnvBPbXJrSATfFBp70UtFVIV02uSbZRDPPL6EjPGqY6cAuzw9dXDqegX6WNEIHZY834q vVR7E9CB87OWpuSwMz5/J0uOJ5Y4ZaePqdL9gcHhWCDRQSijTvCGh7iq2RU5hZ435Rnv fFPs8uyaUDPFbFHMUx1sHuHCymFBkc9CLim0vJc0zm+TzvFXYDsGrf1jeiRJScUUxUqe GJ0g== 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 s128si1921184oig.204.2019.12.11.12.50.30; Wed, 11 Dec 2019 12:50:30 -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 S1727199AbfLKUu3 (ORCPT + 27 others); Wed, 11 Dec 2019 15:50:29 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:35685 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727140AbfLKUu1 (ORCPT ); Wed, 11 Dec 2019 15:50:27 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MRCBm-1iK9Wr1CTc-00N6b3; Wed, 11 Dec 2019 21:45:01 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Jens Axboe Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , stable@vger.kernel.org, Christoph Hellwig , linux-block@vger.kernel.org Subject: [PATCH 06/24] compat_ioctl: block: handle Persistent Reservations Date: Wed, 11 Dec 2019 21:42:40 +0100 Message-Id: <20191211204306.1207817-7-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:MERO8zqQm/hzGxvh7HZnjW9vQ1ZkuwnxVUEsPHkICjTXF72YTAX GzMR0NQXrHDUH1Ymk9up4NF0oLy5R2DPdiNH0cZ5VKqru27Xw4DQslx1eJSQWf06CCL1CNf jgBrKB7/+0fQuGpKbgn+ah/UhrVsIriUPnvb9s0qeTnOjN0sopsSOo5nNWQRPuh8beEa46x CqJxhbbw4iH1L6KK+ABTw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:cgHM/oukC3A=:Wr9cjDcJN40wTgqwfOa2OY IeB4iEnKqfNoRtRGuXIwtlpmRnDA+FXs7+eBPsV3Jtcv7d5IVtBbcJmfIW5Jq2GTuk4rqxiZG upmoAj6LgLqs/Xga9Dvv3jZwEz4E6KHff+Z7KEjINDweoqJV7C8SkI1177LjWSxknHaesB0Q5 BjXEId+7YKOx03fWONcPFlB411QY5y32LND3+HeBcQM1FO1iVA+d15fICtU5rAtUwdg/J18SA k8eCOqXrWszndNXc+gnRwLq6O32FMoXeBONlMKkSOBAeEJOMyO7DqM/BxKRhRKAqZ2wgI1qfP TkPb+PfBTqlvfXQrJaYNahGpIVImte/G46I83l43XRdEBp9PvtxdWZ4haYTdngDQKN5yX3oXO uXgi0/BXVLT1gKvLnz4kRLfePf0H3qBBY6Ex30UinIn5gLxRDlDqZApaVwkU8wy7aKFt1jUb9 ihFLXWJ6uxSKiB7bzLHfHZksBhL7Mvc/eLbS2/zJwZp/vchOB/uAD8bmhwn4AtsXP+sOkHikd t2HrJqmN2rMiGWFSIB4OVqIQkaoHABPCZOjowivoRLnLO4SQBSJNAbfzF/SOtoY9wlCfC2kSr wENXIPN6oQLrNRvceFj+PrbKDiDFQE/2+dFF+qQJlbH+VnzeBpVgAqV7i8IpNy0LfMzGuXEq/ N90+kCpIPtN+R2PGwv1Jv08WFACU+uGWXH3WMib15C4h1o3sA7kUEBrIp3qsAbR3+O14ebLQo b0m349+vlPkY7mdXIAqMELR9ztbqWPLSAkLrziNrgq2KP+J/t/0Q2Y7+x+RtBamThBy8hkYiQ rg02cnlfarh5rkL6HtGaqMnHHoW7tbUaNsiJYR/5Za2agv6fEKGSLJ+o6uCXNcdnFHxoaYFTO 26SDlJk8ZBEKbCH6Zjyg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These were added to blkdev_ioctl() in linux-5.5 but not blkdev_compat_ioctl, so add them now. Cc: # v4.4+ Fixes: bbd3e064362e ("block: add an API for Persistent Reservations") Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.20.0 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 5b13e344229c..f16ae92065d7 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -408,6 +408,14 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKTRACETEARDOWN: /* compatible */ ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); return ret; + case IOC_PR_REGISTER: + case IOC_PR_RESERVE: + case IOC_PR_RELEASE: + case IOC_PR_PREEMPT: + case IOC_PR_PREEMPT_ABORT: + case IOC_PR_CLEAR: + return blkdev_ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); default: if (disk->fops->compat_ioctl) ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); From patchwork Wed Dec 11 20:42:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181322 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042755ile; Wed, 11 Dec 2019 12:46:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyQ+nLOothnpwkiJYxmZ22M/B5NePPcVjtzbI08jPqhhbxK18UsqxkclP0JpsGCszQafSyZ X-Received: by 2002:a9d:453:: with SMTP id 77mr3860201otc.307.1576097182502; Wed, 11 Dec 2019 12:46:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097182; cv=none; d=google.com; s=arc-20160816; b=ZTb5A4vdGPpJT8Ch+dsWPbOGhF1hAd2BQKnMO2NF84T3MyivXZXgAD6NwyIRw4e4i2 8jCNVU7bpH3VR8sjE6QUYSM/vuU8INBKQDmOk0C8X3P4rbfxP2eOvV+M+GTC3FXqmmA5 2eIVzVvNrbYwJzKCJFwUoHeAe4uRN18hD24Z9aIsObVCehK8BwQ69vagJS4ys+jiZhJl GonQ+jSACypoZh67doelSjEsw+mH4HthHpwPCNz2Kki8cFow3F2y8bT5T1Jz5nhvraUv EvLhgslCn6e+DLijUlWvnNfg9pkZcXkcOTkHp6sV0uAI6OixmnRq6GOf6N/7fo44W5rE W3wg== 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=Ui+PwTKn8A+c8+qMLznZVwQaSecG+968WggH9whL7Sg=; b=NiwC93HUZCq7Jjef1O5Nuvzvjgm/m2w5k1y+XEmLKsDTGi5eGXrYhUpoIOrPG8EyTX 45mp4evSUrXY/7NXG9FnJ7eOaK50pJJMxQAcd2AcaF9H/N2PGfCIy8ka9ieyqOKyM+Kc hN/Fog5mS9k4Cw05XhMa0t3qCGGE6QOl/G/QLyuOcfk9v8Q4vhrUwHyQzYjgCUCAvVQx 5wzTyMTCP4tikc5OcpkdNTPoCLzijq3Wfvmp394K3j289P/P8OFAs0/iVsEzNL6zPTeX 7MfAKzDcVreEfZ4yiwXywms9H5m3O26spX3Sbmt+Vn0VA6Da0zdm5yYSFRyYE2jXZPv0 D83g== 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 y4si2098798otk.219.2019.12.11.12.46.22; Wed, 11 Dec 2019 12:46:22 -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 S1727030AbfLKUqV (ORCPT + 27 others); Wed, 11 Dec 2019 15:46:21 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:38855 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726771AbfLKUp5 (ORCPT ); Wed, 11 Dec 2019 15:45:57 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N0o7f-1hkohk3wnd-00wiOe; Wed, 11 Dec 2019 21:45:10 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Jeff Dike , Richard Weinberger , Anton Ivanov , Justin Sanders Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Alex Dewar , Daniel Walter , Greg Kroah-Hartman , linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 07/24] compaT_ioctl: ubd, aoe: use blkdev_compat_ptr_ioctl Date: Wed, 11 Dec 2019 21:42:41 +0100 Message-Id: <20191211204306.1207817-8-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:gy8z+YAlxaJ9blvRYgmlwoOjM5ATVorSryFF8QdI4xwnfePEif2 ZPqNZhXPZ2zKjqu+nHu5cY9UbimuPi3idKRpKUHXeFhUocrdiKGZl1/ztl9P/tv6FzJ/PhQ QfZ8OcX0GLkWwfNM3Vvs0xduPX27a2+KLP8a3SGV7HE9F75Njm6oBeKzUmFnAvHr12Ec8N9 5gn9BVCoxS5wHBp8wOO0g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:pGK6m1crKsA=:gSjJQpNokt5OeOSFQeubXS DhaKLPBBb6EV6alKwS18pbLZRwhjKMomynM6uF1IwkqUjosaLsZM5+fPzPTj8qcCy3o/bvOwH ak7ENd0/P9BEOfygvkRK/sXam/1u76ZTGCHaowaE3HMgWdLm9nqlluqoXOTs/Fd2bujikB0Is AmWz+dOLA7fovKnGj+0oVpPptqiYyDbtX/GSGi7EqN6K5gmr1HrDHd+tj1ZSC08UdOlCGZGCu IwBvuLdlgsdnEWnEV3tmDNgqWm4Ttd9r5m30tPJLnByHL83pkyWR0Z4L4vI7JqnEYy44gTLb0 IMwp1vEBhGRws4JPpInvZbQ+0MvlDuk20B8fxUByf4ihqvnZi7FWnJ7Q39NR8oWoTNONmqm64 9SCQaclMLWn9UYQypRTiJfpbR1eLtANQTZOMCSTZZ8C717vegRMJtsSM7d8yySarspbydIClD NIU7HCCBp+OZ/j2z0MHerIfJ++Q5nY22EAdBnqLN7Z9Faswsn6mOj9S3cio22FmZkwoKtmJwH FzaZEi/of2JEyPSYXrmUEKDgQxOEj+obRUPtt9kogZRoE2aFCnUj5dfZT6qgwCZVdsxo998PC dCZmerXpuxR4YytniK67YdDWyX1RXOrapkFwk+rBwcRMAE7HMAFRAblqF4l1SeLuYK7QHfgx+ +3+QmrVkplwr1i0Nkn0I+bNKP0/Tfc4BP0Rr1c8cfvERunmo/gbQumMgI98O+9FPHPabF3g5m iB33cvRo47XAQc1md8dzuy9DuqR4oNh/yFNLdzDwNFrp+74V1cGw7aGxXXpPZPNQpYFwUAu0y uaWmDUA6OYy4cA2yP5Ia24bfQsCYvmIeIdnTNcaMMsQsAwh/3ObdpFUTbiYn44CScMJmpYMEH 9z/m1cveMeFXPF7tB5tA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These drivers implement the HDIO_GET_IDENTITY and CDROMVOLREAD ioctl commands, which are compatible between 32-bit and 64-bit user space and traditionally handled by compat_blkdev_driver_ioctl(). As a prerequisite to removing that function, make both drivers use blkdev_compat_ptr_ioctl() as their .compat_ioctl callback. Signed-off-by: Arnd Bergmann --- arch/um/drivers/ubd_kern.c | 1 + drivers/block/aoe/aoeblk.c | 1 + 2 files changed, 2 insertions(+) -- 2.20.0 diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 6627d7c30f37..582eb5b1f09b 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -113,6 +113,7 @@ static const struct block_device_operations ubd_blops = { .open = ubd_open, .release = ubd_release, .ioctl = ubd_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, .getgeo = ubd_getgeo, }; diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c index bd19f8af950b..7b32fb673375 100644 --- a/drivers/block/aoe/aoeblk.c +++ b/drivers/block/aoe/aoeblk.c @@ -329,6 +329,7 @@ static const struct block_device_operations aoe_bdops = { .open = aoeblk_open, .release = aoeblk_release, .ioctl = aoeblk_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, .getgeo = aoeblk_getgeo, .owner = THIS_MODULE, }; From patchwork Wed Dec 11 20:42:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181321 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042640ile; Wed, 11 Dec 2019 12:46:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzJeJej7p6y/EW5EB3VnDzh5KJsKCy22BCzHZyZnvHW8PLpkVTTyCP7wbIizbiUUxEyIgBz X-Received: by 2002:aca:3b89:: with SMTP id i131mr4081285oia.43.1576097175769; Wed, 11 Dec 2019 12:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097175; cv=none; d=google.com; s=arc-20160816; b=HG//9iVE/ine4CWtbQCjaZ6wev9QbiP8HAfSoERygRO1XAOBoSHo8tWFLDuum+zcwc LbdIR1b1hxva49jV2JvjUhu0YZChFdlBKsPrnRaLwMD1yh9oBVKCHhheDWotXb6mOsjj UQEje6n152xAUHpi/Vw0Gu5BsetsV4k7xJEgWyfzTC53RnSBLlz3owZCvX9ltX+rbkZa vsTxKWAjrRb40z4KesbXFNHe9tAMqG982gNzhcrA823PJiEjmeNtImvvCvXbPc0JaO9M I2Dli6G08uDcIOm23uthP9GPG0179vyQmA/dbwrnqVW35kF8Wj1LFdlwBS+wLyZlmNMf 7ixQ== 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=ga96TGRzOIf8fqr+b1GNEYlycVyxH6YjySPwyZnSFeM=; b=0YkIZWvsuDr76jUk97T5Q+eoTFBvfFhMsZuKmR5lTrxRZAJ5h9Cb9qqe6aTov1dy34 h4JZMqGzYysRHVB9prkGw+kLbIuSu4XydXtj8uqY8bgCres6QNihz5HRvzjjaUdVM7Wt ZHMk0SR+6Tw/q/gIf93f36+6iUCo5NuWtBvuPtpYyM0qLlJpPEjSXaOq4APgqDn/4WkX 1pcyvI2A8SAyd5ncQSlcVfPLNKMOOyLhBxUrDK3lnsKtbETRH8bpSgoZTe6QXuZRgcVg vl+CIShFRSc142AKcWbyxhseFJe8B46AtqWkgkB0vl5x0lpST6R+tsiSLc607gAEi++9 8m7w== 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 j71si1856935oib.213.2019.12.11.12.46.15; Wed, 11 Dec 2019 12:46:15 -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 S1726989AbfLKUqO (ORCPT + 27 others); Wed, 11 Dec 2019 15:46:14 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:54809 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726689AbfLKUqH (ORCPT ); Wed, 11 Dec 2019 15:46:07 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MO9vD-1iKzPs165J-00OU2W; Wed, 11 Dec 2019 21:45:21 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Chaitanya Kulkarni , Hannes Reinecke , Martin Wilck Subject: [PATCH 08/24] compat_ioctl: move CDROM_SEND_PACKET handling into scsi Date: Wed, 11 Dec 2019 21:42:42 +0100 Message-Id: <20191211204306.1207817-9-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:T9YafS4Y5YdpmurpT0bF6+4sbIuel2ibFF2FSIKvxx5hotg9jpx gpb9EGkrCvb5mTBd03vG9GRI3caFpeQHTodhTU8m1iUDy84RzO/uWY8gk2vbA6MzIpJAwO3 /rudggSeJ4PhGSjx0xcF0kQBQm8vpu0E//s3mtVRDN+aQz0V5eJ3tPWU1oeYY/aUvjgcatF qRhFkz/tUwaR8xIEr6R9A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:RKPMK4n3QW8=:+BvTC9yynSn32rTUD6Fm3I 06HHnAhgSO4ExRPzrlKj18jH7CGbz9a95Le1wRutYE3vjIVovOAEnKT8a3aZ7OEqTHznepmSA 7K8++CEcbgfDjarB609ju63go2ttSC6cMPRdz62MNimbftrJsrzE1TWaAumP/+b3T8g0qKWt7 QcWTiIhX7sTPprF6MdfkBNUo6nQzjD5HSDUZCaA+DbzkS0e6bn2lvNhysouUsE+9AMa+nF8DU FO7NCyioHdkV8bMF9qhsWzL+GE/M8qwpLKWbiAUSH+BR+itVACnT4+M5U5KVxktWoGrt+4+Et gJp1o9eGj+hMxnKfMDkGCo9/SNgEjxERTszDn0dY1v9Hp8xCD0Lwtn6Uv/s7mZwQGF45KV6rL xZgk1TjHgDHDye5RHoh0e+4kJEKXA2vkbF4xqyijzrHlfgfCzkhhjNpSXnSmxHGU+UCiMflDM C+xNkEfm63qmi0doNwq78TRq7LgXnlbc6L5oCw4j/cc1mCq1MGv04aCNEDD2+TXcGJEz5XY8Q 4snbzIfdWWKssaUl7UR4CY8F1HGL6sz75v22nNr7O6OSxyPlBFSH7VAkK+6d2bsb/zYu6Ne9p iE1f9g8gj7O2GK0wE1lTIp77NQ1KZW6DlquGLiOziSyL6vMuzYGKYcp/zEmpvLdYNSGn+Ki8g sJD3W8ifzhpj5nm19n/VuPpxFB/6dITjGhb0X25JzN+cigEQnI52cEAbrKycTROerSAXudApw zzIZg+7KKCi9kgG2nJ+o5xarNSZ5hKM7F09BILVKoOO6FwKfcAeCvRBS6Xxw4VMZkpYReonUn ZWCGxKkhQeGPnuFanX0w6iQ8c53UC4hGFErTIy81otoBekO4OIPUX+ebqp5XE5lEntoGTU6cE z801MArhGTGAKoEKdjAQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is only one implementation of this ioctl, so move the handling out of the common block layer code into the place where it's actually needed. It also gets called indirectly through pktcdvd, which needs to be aware of this change. As I noticed, the old implementation of the compat handler failed to convert the structure on the way out, so the updated fields never got written back to user space. This is either not important, or it has never worked and should be fixed now. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 47 +--------- block/scsi_ioctl.c | 185 ++++++++++++++++++++++++++++------------ drivers/block/pktcdvd.c | 6 +- 3 files changed, 135 insertions(+), 103 deletions(-) -- 2.20.0 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index f16ae92065d7..578e04f94619 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -102,18 +102,6 @@ struct compat_cdrom_read_audio { compat_caddr_t buf; }; -struct compat_cdrom_generic_command { - unsigned char cmd[CDROM_PACKET_SIZE]; - compat_caddr_t buffer; - compat_uint_t buflen; - compat_int_t stat; - compat_caddr_t sense; - unsigned char data_direction; - compat_int_t quiet; - compat_int_t timeout; - compat_caddr_t reserved[1]; -}; - static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { @@ -141,38 +129,6 @@ static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, (unsigned long)cdread_audio); } -static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) -{ - struct cdrom_generic_command __user *cgc; - struct compat_cdrom_generic_command __user *cgc32; - u32 data; - unsigned char dir; - int itmp; - - cgc = compat_alloc_user_space(sizeof(*cgc)); - cgc32 = compat_ptr(arg); - - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) || - get_user(data, &cgc32->buffer) || - put_user(compat_ptr(data), &cgc->buffer) || - copy_in_user(&cgc->buflen, &cgc32->buflen, - (sizeof(unsigned int) + sizeof(int))) || - get_user(data, &cgc32->sense) || - put_user(compat_ptr(data), &cgc->sense) || - get_user(dir, &cgc32->data_direction) || - put_user(dir, &cgc->data_direction) || - get_user(itmp, &cgc32->quiet) || - put_user(itmp, &cgc->quiet) || - get_user(itmp, &cgc32->timeout) || - put_user(itmp, &cgc->timeout) || - get_user(data, &cgc32->reserved[0]) || - put_user(compat_ptr(data), &cgc->reserved[0])) - return -EFAULT; - - return __blkdev_driver_ioctl(bdev, mode, cmd, (unsigned long)cgc); -} - struct compat_blkpg_ioctl_arg { compat_int_t op; compat_int_t flags; @@ -224,8 +180,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, return compat_hdio_ioctl(bdev, mode, cmd, arg); case CDROMREADAUDIO: return compat_cdrom_read_audio(bdev, mode, cmd, arg); - case CDROM_SEND_PACKET: - return compat_cdrom_generic_command(bdev, mode, cmd, arg); /* * No handler required for the ones below, we just need to @@ -263,6 +217,7 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case CDROM_DISC_STATUS: case CDROM_CHANGER_NSLOTS: case CDROM_GET_CAPABILITY: + case CDROM_SEND_PACKET: /* Ignore cdrom.h about these next 5 ioctls, they absolutely do * not take a struct cdrom_read, instead they take a struct cdrom_msf * which is compatible. diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index b61dbf4d8443..b4e73d5dd5c2 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -639,6 +639,136 @@ int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp) } EXPORT_SYMBOL(get_sg_io_hdr); +#ifdef CONFIG_COMPAT +struct compat_cdrom_generic_command { + unsigned char cmd[CDROM_PACKET_SIZE]; + compat_caddr_t buffer; + compat_uint_t buflen; + compat_int_t stat; + compat_caddr_t sense; + unsigned char data_direction; + compat_int_t quiet; + compat_int_t timeout; + compat_caddr_t reserved[1]; +}; +#endif + +static int scsi_get_cdrom_generic_arg(struct cdrom_generic_command *cgc, + const void __user *arg) +{ +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) { + struct compat_cdrom_generic_command cgc32; + + if (copy_from_user(&cgc32, arg, sizeof(cgc32))) + return -EFAULT; + + *cgc = (struct cdrom_generic_command) { + .buffer = compat_ptr(cgc32.buffer), + .buflen = cgc32.buflen, + .stat = cgc32.stat, + .sense = compat_ptr(cgc32.sense), + .data_direction = cgc32.data_direction, + .quiet = cgc32.quiet, + .timeout = cgc32.timeout, + .reserved[0] = compat_ptr(cgc32.reserved[0]), + }; + memcpy(&cgc->cmd, &cgc32.cmd, CDROM_PACKET_SIZE); + return 0; + } +#endif + if (copy_from_user(cgc, arg, sizeof(*cgc))) + return -EFAULT; + + return 0; +} + +static int scsi_put_cdrom_generic_arg(const struct cdrom_generic_command *cgc, + void __user *arg) +{ +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) { + struct compat_cdrom_generic_command cgc32 = { + .buffer = (uintptr_t)(cgc->buffer), + .buflen = cgc->buflen, + .stat = cgc->stat, + .sense = (uintptr_t)(cgc->sense), + .data_direction = cgc->data_direction, + .quiet = cgc->quiet, + .timeout = cgc->timeout, + .reserved[0] = (uintptr_t)(cgc->reserved[0]), + }; + memcpy(&cgc32.cmd, &cgc->cmd, CDROM_PACKET_SIZE); + + if (copy_to_user(arg, &cgc32, sizeof(cgc32))) + return -EFAULT; + + return 0; + } +#endif + if (copy_to_user(arg, cgc, sizeof(*cgc))) + return -EFAULT; + + return 0; +} + +static int scsi_cdrom_send_packet(struct request_queue *q, + struct gendisk *bd_disk, + fmode_t mode, void __user *arg) +{ + struct cdrom_generic_command cgc; + struct sg_io_hdr hdr; + int err; + + err = scsi_get_cdrom_generic_arg(&cgc, arg); + if (err) + return err; + + cgc.timeout = clock_t_to_jiffies(cgc.timeout); + memset(&hdr, 0, sizeof(hdr)); + hdr.interface_id = 'S'; + hdr.cmd_len = sizeof(cgc.cmd); + hdr.dxfer_len = cgc.buflen; + switch (cgc.data_direction) { + case CGC_DATA_UNKNOWN: + hdr.dxfer_direction = SG_DXFER_UNKNOWN; + break; + case CGC_DATA_WRITE: + hdr.dxfer_direction = SG_DXFER_TO_DEV; + break; + case CGC_DATA_READ: + hdr.dxfer_direction = SG_DXFER_FROM_DEV; + break; + case CGC_DATA_NONE: + hdr.dxfer_direction = SG_DXFER_NONE; + break; + default: + return -EINVAL; + } + + hdr.dxferp = cgc.buffer; + hdr.sbp = cgc.sense; + if (hdr.sbp) + hdr.mx_sb_len = sizeof(struct request_sense); + hdr.timeout = jiffies_to_msecs(cgc.timeout); + hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd; + hdr.cmd_len = sizeof(cgc.cmd); + + err = sg_io(q, bd_disk, &hdr, mode); + if (err == -EFAULT) + return -EFAULT; + + if (hdr.status) + return -EIO; + + cgc.stat = err; + cgc.buflen = hdr.resid; + if (scsi_put_cdrom_generic_arg(&cgc, arg)) + return -EFAULT; + + return err; +} + int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mode, unsigned int cmd, void __user *arg) { @@ -689,60 +819,9 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod err = -EFAULT; break; } - case CDROM_SEND_PACKET: { - struct cdrom_generic_command cgc; - struct sg_io_hdr hdr; - - err = -EFAULT; - if (copy_from_user(&cgc, arg, sizeof(cgc))) - break; - cgc.timeout = clock_t_to_jiffies(cgc.timeout); - memset(&hdr, 0, sizeof(hdr)); - hdr.interface_id = 'S'; - hdr.cmd_len = sizeof(cgc.cmd); - hdr.dxfer_len = cgc.buflen; - err = 0; - switch (cgc.data_direction) { - case CGC_DATA_UNKNOWN: - hdr.dxfer_direction = SG_DXFER_UNKNOWN; - break; - case CGC_DATA_WRITE: - hdr.dxfer_direction = SG_DXFER_TO_DEV; - break; - case CGC_DATA_READ: - hdr.dxfer_direction = SG_DXFER_FROM_DEV; - break; - case CGC_DATA_NONE: - hdr.dxfer_direction = SG_DXFER_NONE; - break; - default: - err = -EINVAL; - } - if (err) - break; - - hdr.dxferp = cgc.buffer; - hdr.sbp = cgc.sense; - if (hdr.sbp) - hdr.mx_sb_len = sizeof(struct request_sense); - hdr.timeout = jiffies_to_msecs(cgc.timeout); - hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd; - hdr.cmd_len = sizeof(cgc.cmd); - - err = sg_io(q, bd_disk, &hdr, mode); - if (err == -EFAULT) - break; - - if (hdr.status) - err = -EIO; - - cgc.stat = err; - cgc.buflen = hdr.resid; - if (copy_to_user(arg, &cgc, sizeof(cgc))) - err = -EFAULT; - + case CDROM_SEND_PACKET: + err = scsi_cdrom_send_packet(q, bd_disk, mode, arg); break; - } /* * old junk scsi send command ioctl diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 861fc65a1b75..ab4d3be4b646 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2671,15 +2671,13 @@ static int pkt_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned in case CDROMEJECT: case CDROMMULTISESSION: case CDROMREADTOCENTRY: + case CDROM_SEND_PACKET: /* compat mode handled in scsi_cmd_ioctl */ case SCSI_IOCTL_SEND_COMMAND: return pkt_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); - /* FIXME: no handler so far */ - case CDROM_LAST_WRITTEN: - /* handled in compat_blkdev_driver_ioctl */ - case CDROM_SEND_PACKET: default: + case CDROM_LAST_WRITTEN: return -ENOIOCTLCMD; } } From patchwork Wed Dec 11 20:42:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181323 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042874ile; Wed, 11 Dec 2019 12:46:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwWph+Hw7JA1asqIDfrJBrtdMD4y8lKDkO7sq3ErtRXhIPLrQMArubuRKvVQGD4dIScJsDI X-Received: by 2002:a9d:4f0e:: with SMTP id d14mr3701012otl.90.1576097188255; Wed, 11 Dec 2019 12:46:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097188; cv=none; d=google.com; s=arc-20160816; b=ViGtirhgIyVBP1Xdpmds1ix/F4gOGFsg+V0neHRJSvXQxM0a/BU8svxKY3VV5kFDho HbwtMyxVyWnuOOA/YKYz4ot9IA/tEUrqxH1Mkwq+G09H75QbHtKhec9FcUr5iSBfCfqs 8/ThUB+cgG9Wlh3GELaJi5CCVimKTIA9Yy6ZKx2TPH/TEgoftCAxbMpa36fkBprlAODy mXY447b41fLMkRKWCMJeIRwag6VkOntDTeYlcp4cSPsO4idvww7kztpoxV9BLG1q3Snb 4rNl8xIFhM+NHViGqqvHsjE0Sh4sd0NbuSe2bat/LMhuu0ALTn6RwDKYtnGAdWFW+ued kKpQ== 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=+IyWi71jOz+f1/EpORDZXIhsKPvu7kRnxluBl5Bn2rc=; b=EhQiKEOdcOyWJSbRpfICSnw+M5DuuWTSmdfSQCog8WS8GBMBvfpiJu7YZ6ZDhZrSeH m8obrBy2/X3IDTbwepWgzQDTKecHmThJ3EKF7Io361+LWaxhaSRcmObrJ3Tt9dyNJbg8 E5DoBMv2IsLdxfx8dDukoAA+HcaakZ9Joxto+9+JThWcH4sc5dgkPWsXHHIJMP1+e0KT Y2BJviqW22xTSGlRJUZ5fHGasHdUDmWzqBGJlr4nOxXynDg8R6uu2o2gxbQGx8kcedUu MqSNI0fPErKQm+d9p9Jy7x2F0esLn7keeFMn4QYxvNej7RiHYvXLVG56bFjnNSuZNHHM psdQ== 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 s14si1687082otq.37.2019.12.11.12.46.27; Wed, 11 Dec 2019 12:46:28 -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 S1727053AbfLKUq0 (ORCPT + 27 others); Wed, 11 Dec 2019 15:46:26 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:34855 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726771AbfLKUq0 (ORCPT ); Wed, 11 Dec 2019 15:46:26 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MacWq-1i8qJS0cf4-00cBEd; Wed, 11 Dec 2019 21:45: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 , Jonathan Corbet , Mauro Carvalho Chehab , =?utf-8?q?Diego_Elio_Petten=C3=B2?= , Guenter Roeck , linux-block@vger.kernel.org Subject: [PATCH 09/24] compat_ioctl: move CDROMREADADIO to cdrom.c Date: Wed, 11 Dec 2019 21:42:43 +0100 Message-Id: <20191211204306.1207817-10-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:9eLcpqX9qM3wY9O4JMlBOGxtF6980Tea0e3xYW37bDIbuBQTU3d EBt9uH6NIbNAq3wnxnKjoZGRiY26U6pGdg8mn4FyQwBgKP3hprv2duU5iz3Bj/tpbriZqX1 rAicuFbxRQ2b8PzXcWI0CpjiIAIqjITj0IyontPLj5Ii8Z0oB8HwnOC5O59p9zHFz77n5DX vbJmPvFNQp9dPaV6e2OjA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:miUaOKDhzGc=:NQ5w4Tv6kJpsYc2hAv9MBL XPFl09NhiZJ8sFOqfF9F6Cr0nFZNVPknX8DvCdwadIpGG8vRZo0r2s0GEMW9I0GOEweeE4rtJ QULXit1ZqycFg4OdaK+bhQ9D/a6sGdIPqRq/savDBCKzANNZ8KcYlBXcH3WXNn+1eiAhEuDME QUqMGSkKqO+8dKz80yFyRPYmBlQNqi1yxHppfyltSyZHDwFSCH4vTKVPyYUCSE6+PK/wBR27z bDFmAi2h7AyJqvyBsvL0B15h67jZPpncHFqDMMsXIzYOtzFDinZ/Pk+Eiz+HAyjWEGmIY4WCk gjFVUOOF1DM3vptgfDBdc949e53LeRbkee6q1XSX9/knW68cf7dY4iqtT4YaMctWk0NVt6/Qq yOgqoJ+L2zfHVcjYpTo/mO7y+U9Jb9fGjPAEbC2dRKepMRAXlFp9orwg01MUw5gTHUFpNXF0r F4/0uYnJtIbL6UVVdPb4Mzz3N/yM3uwOBOCgZYXdTC5bfojvOjoooqbCZw0jbfo499FagB50m NTEyfrR+0mBnjv8tM4JMB2DDwb4rWu/gS6Om1UJVoBX7Q0rnHucA9D+5Ff57mZSCtB50gwMLl yb7btU8OddXIGAUuT6SWlQQAA9I4xsIJTnizjWoJpvJFJGioNGxOjXcsRpIGt20yHftYoNm5v HzHEwir5mPeDEw3UlbGCdrKs8aylgUiApZdYTe0ZwMOz0u6geXJq+fgdmkO4TUTMmsLoQauSF AruH41K6eLFBjyFIgqO6brjg92nbkNTjp2QNuLLonSDCIkuqB3RwIf0XXsw8fVFaD0GWoFDUA EjF4z4yAkWSlMWSADJPdLzeicqaNoSaOlGnSJeqz7KlHL6ICc7FfoKH7ZcHaZcWcmjysT1Glv kWY027vK4y78pBqNljdw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Again, there is only one file that needs this, so move the conversion handler into the native implementation. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 36 ------------------------------------ drivers/cdrom/cdrom.c | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 39 deletions(-) -- 2.20.0 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 578e04f94619..cf136bc2c9fc 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -95,40 +95,6 @@ static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode, return error; } -struct compat_cdrom_read_audio { - union cdrom_addr addr; - u8 addr_format; - compat_int_t nframes; - compat_caddr_t buf; -}; - -static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) -{ - struct cdrom_read_audio __user *cdread_audio; - struct compat_cdrom_read_audio __user *cdread_audio32; - __u32 data; - void __user *datap; - - cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio)); - cdread_audio32 = compat_ptr(arg); - - if (copy_in_user(&cdread_audio->addr, - &cdread_audio32->addr, - (sizeof(*cdread_audio32) - - sizeof(compat_caddr_t)))) - return -EFAULT; - - if (get_user(data, &cdread_audio32->buf)) - return -EFAULT; - datap = compat_ptr(data); - if (put_user(datap, &cdread_audio->buf)) - return -EFAULT; - - return __blkdev_driver_ioctl(bdev, mode, cmd, - (unsigned long)cdread_audio); -} - struct compat_blkpg_ioctl_arg { compat_int_t op; compat_int_t flags; @@ -178,8 +144,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case HDIO_GET_ADDRESS: case HDIO_GET_BUSSTATE: return compat_hdio_ioctl(bdev, mode, cmd, arg); - case CDROMREADAUDIO: - return compat_cdrom_read_audio(bdev, mode, cmd, arg); /* * No handler required for the ones below, we just need to diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index eebdcbef0578..48095025e588 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -3017,9 +3017,31 @@ static noinline int mmc_ioctl_cdrom_read_audio(struct cdrom_device_info *cdi, struct cdrom_read_audio ra; int lba; - if (copy_from_user(&ra, (struct cdrom_read_audio __user *)arg, - sizeof(ra))) - return -EFAULT; +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) { + struct compat_cdrom_read_audio { + union cdrom_addr addr; + u8 addr_format; + compat_int_t nframes; + compat_caddr_t buf; + } ra32; + + if (copy_from_user(&ra32, arg, sizeof(ra32))) + return -EFAULT; + + ra = (struct cdrom_read_audio) { + .addr = ra32.addr, + .addr_format = ra32.addr_format, + .nframes = ra32.nframes, + .buf = compat_ptr(ra32.buf), + }; + } else +#endif + { + if (copy_from_user(&ra, (struct cdrom_read_audio __user *)arg, + sizeof(ra))) + return -EFAULT; + } if (ra.addr_format == CDROM_MSF) lba = msf_to_lba(ra.addr.msf.minute, From patchwork Wed Dec 11 20:42:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181324 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1042940ile; Wed, 11 Dec 2019 12:46:31 -0800 (PST) X-Google-Smtp-Source: APXvYqylhzZ5rOKxN33o4fcmb+4Ao6viXhGPal3dqSphnHcAgJy+l1DTEfsu0NThc1pZ2wfcTOj3 X-Received: by 2002:a9d:6e89:: with SMTP id a9mr3718337otr.38.1576097191777; Wed, 11 Dec 2019 12:46:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097191; cv=none; d=google.com; s=arc-20160816; b=KVdT2dQsH1y73xJkAybvGakYkSgNmJTjkMG8c26gI6iJaPzNnKJFpapoOj6XO4Ko9t hAdwkVrk9/6/fD0EzgtH+8sozl5TbK9Ok1kfGrf+VH7UMRs4xwE/zqs+bYhmykc0L9C0 07hdeE1wm7T5wsK8vuZUccjdLQ+OncUCJESlqPb7teUwwmhMrvFdnScpCLR5M9tSNTM7 wqv4kklkihCoGco+nCHEyOFGDTXAzpb+mglCGXIq/Sh7oV5gNyixbj7FhjkDk1I6STJR yA4d15ncBGX9LY8TXSWpYFS1zLHAghADEqVr7+YRVP/7NbMgFa0Zli8kSMJvXz13YtE6 09YA== 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=bHr7vznmK+jYeWprRgaBOffx2NPdRWjg6fbSJRf0a0s=; b=TZDb0yC0k0Xbk2duCHiCaGj2ZN4Ly6PUyOd0ktdHuZHc0c7eU5Scv+KMHf1srgk41k GBpYrxhC5ZuzuhS69FdEHYtJBapXBtCEPqsf8VbcB2aXqLH2LSSNbbpl8LamtXrWdNye 2/CIxM+gdmJ4du2E1cOsqlUbeY3ZZ+CyWJ/lHV6XTiHRQKoNYPNJF+IGFwjuLpy3P5ZK VkRjiGbjT53/hxUtHylNiTSrrVFvEZCWkC9kjUTGazJCOG/hLKO5ldU4oSCUqWf3n3MU 27iDOtT5E5pEhz1jY9RRgyTjf45saz9dyWc89hu0rMx2ebYuyiWvpd8gvlCkbVzNH5Gt xbfw== 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 s14si1687082otq.37.2019.12.11.12.46.31; Wed, 11 Dec 2019 12:46:31 -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 S1727077AbfLKUqa (ORCPT + 27 others); Wed, 11 Dec 2019 15:46:30 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:47121 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726771AbfLKUq3 (ORCPT ); Wed, 11 Dec 2019 15:46:29 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MdNPq-1i65A826tc-00ZQLd; Wed, 11 Dec 2019 21:45:44 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Martin Wilck , Hannes Reinecke , Jonathan Corbet , Mauro Carvalho Chehab , Guenter Roeck , =?utf-8?q?Diego_Elio_Petten=C3=B2?= Subject: [PATCH 10/24] compat_ioctl: cdrom: handle CDROM_LAST_WRITTEN Date: Wed, 11 Dec 2019 21:42:44 +0100 Message-Id: <20191211204306.1207817-11-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:OgKProSambYiHxIdc4WgI96dWkA775je0kzaKhUxPtesDlYoKyr gFFE1yy9DzEM7a5B5AA/oSqXoT7QuiY4bPuyHN27QCD94Ex8qoyXne6agA5MTSOyDSrPZGD b1iEfWDWCeor9YWE98KUBDkDqgzEcVe4XsydwGdKj0HN1+aNts0vphUCJe97+YwSV7Cwuc1 NPTBUBiYBp0q71uYDhjLg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:Hu2x/EQ5Akw=:kkX8RCM7OH0NzXIm2tqs9i sLHHlNRUC31BYCN7hIZytGYHFX+czQfkQlwPZsH8e+XKW0dHB9up5hnk5z1rU4r2NUrUdAr0v VyFaamsfs6G8SqhUkpOmVGoWOAFaSQ9MrbqI8sLODVKtntYt8R9eWpeRcFnSTEuNb3g+whPI4 mSoYVxg6+8o8mtCTLdVnfxhCUDVnh8gqsJ4JQFVfHK22DWhxEvcMJ9T7tE6IdA9ZA/EZjXdGV sLfZpMxbGKRov84Jy/2ZqSVMIfpDQMWZXGjo/+qFZeKurqf54xnsjNmZsaPHpyaZBMnfiW+TX lCwVM07T3jmrVnam7Xonjfn9L7acTC6cFTWU9o7QQ+kpCJa/ZdAi70SzHbyMuOL4ZYkH05Xud mDpr4nwzEIgJLWzGkvxxX1iaWM1j4ZEEm9HjrCQlOCY8TCNRxHspFNWoOWvTOMzjjm8iD8Xua QvN6mPKXr5GZvwpMwnKbRHX+uEzUYLGg4npHHrWkdI/zRcVEjRL5Eza8kz+EtRENOfL6ITRXh zX8zKnuUaxBeEyYR/X5pQjKN0SeBGmVyB7RyJJSdUdUj8PsBoUMfCVEe2kyuBOSZPdzMyWBSh oXqLDy417zcfrnc+7Ec9vujspmUmVuaAc1qWxswpslZCkHlvfejhXZNJ4vt34IFAZSTkG28+y BmG53KpQIu9xron0cA3NL0rgACyTESFb8ouD/QfdlH5XSnKUcEzLZAd+9sLL35tAeKq1A9PSf kY7ij1PIMzoQc6ix9EpU5tLRR18Ky03ORsAG97f+/xE/WXSpPvyjACZw8W5Z1HkwulabSwBkC B5mgacsSWMkl7bJNu7JTb9YAezAK7f0wmDxlDBqeVfLIwvb4vJNJXpOMn3ZIPtML6Qg51rh4x UCB0u9rL3bexsg3A8PyA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is the only ioctl command that does not have a proper compat handler. Making the normal implementation do the right thing is actually very simply, so just do that by using an in_compat_syscall() check to avoid the special case in the pkcdvd driver. Signed-off-by: Arnd Bergmann --- drivers/block/pktcdvd.c | 24 +----------------------- drivers/cdrom/cdrom.c | 7 ++++--- 2 files changed, 5 insertions(+), 26 deletions(-) -- 2.20.0 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index ab4d3be4b646..5f970a7d32c0 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2663,26 +2663,6 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, return ret; } -#ifdef CONFIG_COMPAT -static int pkt_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) -{ - switch (cmd) { - /* compatible */ - case CDROMEJECT: - case CDROMMULTISESSION: - case CDROMREADTOCENTRY: - case CDROM_SEND_PACKET: /* compat mode handled in scsi_cmd_ioctl */ - case SCSI_IOCTL_SEND_COMMAND: - return pkt_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); - - /* FIXME: no handler so far */ - default: - case CDROM_LAST_WRITTEN: - return -ENOIOCTLCMD; - } -} -#endif - static unsigned int pkt_check_events(struct gendisk *disk, unsigned int clearing) { @@ -2704,9 +2684,7 @@ static const struct block_device_operations pktcdvd_ops = { .open = pkt_open, .release = pkt_close, .ioctl = pkt_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = pkt_compat_ioctl, -#endif + .compat_ioctl = blkdev_compat_ptr_ioctl, .check_events = pkt_check_events, }; diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 48095025e588..faca0f346fff 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -3293,9 +3293,10 @@ static noinline int mmc_ioctl_cdrom_last_written(struct cdrom_device_info *cdi, ret = cdrom_get_last_written(cdi, &last); if (ret) return ret; - if (copy_to_user((long __user *)arg, &last, sizeof(last))) - return -EFAULT; - return 0; + if (in_compat_syscall()) + return put_user(last, (__s32 __user *)arg); + + return put_user(last, (long __user *)arg); } static int mmc_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, From patchwork Wed Dec 11 20:42:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181326 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1043915ile; Wed, 11 Dec 2019 12:47:20 -0800 (PST) X-Google-Smtp-Source: APXvYqxvmHcdZY/eEwuH6HFvzKOzae/FROt50MRzFhkwSy4kT2hGdSXoDhj89p75KVLCLWBJ1jI9 X-Received: by 2002:a05:6830:681:: with SMTP id q1mr3631756otr.162.1576097240712; Wed, 11 Dec 2019 12:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097240; cv=none; d=google.com; s=arc-20160816; b=zFVU3bspD9g8IogyAi9lK04aneH4CEwd//HspnfJ5KSonpap+gERN7jW5unFETWwdZ o98bkDIx7INV+fx41Gv8paoSqufaIJ0bmcp34JmZDBguSKVEVpPs0Ig+yNCZnhmUmDil 8M4/fdtbon1TcRy+FthnBgToROEsZhg2q51JDmGQqXcTdgCZ67QzeXzHEnIb+XGTvkY7 bwH4bB2g8G1g2vd+cEHDY3eofG1lTLzElXRGHgBSVYSZlLYfeQj12OJcP0XOtwB/mzfh CfAALMv7vmSxqiqosf4RK5MeVVP61vGHKob6z1ZM+P/n8xq6/KoTls3by1Z4Dn/+wCTB 24cQ== 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=iNYEmTBE6u1vLAzLj9HVPquZ2gpryVAt0RfSPbEOp/4=; b=Ow7x4Rx1DU0lT14jSNNZsjvfFOHvO/kp3GFiAHL+HXNyL7CdQj6QGxBz2ZFi7bpAo+ VmIcISqEjWCVLNFsCpanyMN0XA7+KNVo/LNEm/IwpGBnL1Zltq8X4nJjZWARVyZwoi+I 4JUjZdvXe0xhvyse7MxOmx+lhIkuzpWJq0/dCx1wa6HUdQ4u4MNYK0rwmQjgLrz81pf0 agmy9X1UBf15j8jktpBBamumuzuZe8aYY+aDsTLZhHpGSp84TN1g6jdIMdOgPf7bQTId AGezER0fjOgsG01O7Z1cnPHpaxmx/RyHg9vwusimdmhSa3xYV2afPwNDLfmevcUQ7KVq 9A8Q== 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 s14si1687082otq.37.2019.12.11.12.47.20; Wed, 11 Dec 2019 12:47:20 -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 S1726847AbfLKUrT (ORCPT + 27 others); Wed, 11 Dec 2019 15:47:19 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:39917 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUrR (ORCPT ); Wed, 11 Dec 2019 15:47:17 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mo73N-1hvNrF2EZP-00pfdu; Wed, 11 Dec 2019 21:46:42 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Denis Efremov , Tim Waugh , Boris Ostrovsky , Juergen Gross , Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Stefano Stabellini , Hannes Reinecke , Damien Le Moal , Bart Van Assche , linux-block@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 11/24] compat_ioctl: block: handle cdrom compat ioctl in non-cdrom drivers Date: Wed, 11 Dec 2019 21:42:45 +0100 Message-Id: <20191211204306.1207817-12-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:J/m2/bKJ2+pQDxQ1q226bByLe0vDPb/F2fJ3RpYYYVapImzb8aV HWSvDBZiFBEiHXWH/xWL1jk4hQERohAteHEMq2lpbMCC2anNojNV6PsQ+gg2WufxemHktc1 LyPWs3HbVs920rfFkymL5JQsEGJs//HvxV5XmvoL8txVyvk9ot9sTr81q1MSSw2dd/7OnwF PZSWIVICg0YVKDXL6K7dQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:DV6o32cCptM=:l/Of3UL40h1Gs6yrtcWn+e 4767u/NI/4g42ftlcB1rmhfV1JWoVD4LaYYo0JaTG5s6dC/UvDLk5wUO/rzT35d0X74aGK/vw ZzuO5Sfiuyu3sh/R3qDuNr/OBJp8ZGii/aLBpIMxXHpzZMFfmKfvecMGNOmA+Gq50FsJkxQaR A2zIFRydZ47PpZefsLdEoTKcgvLPHb7Tm2GNslBvrDX6Rr0I67QRiTc3YLRBlX9ynDTUJXLwo LnOc0sqAlB/PtptI8I5TK/uxN/S5T//2LOTZDmsxpeWiocQBjRJO14A5K7cMEnIY5B+RHLxek gAAdg/nxcAUOceYLoJ1sP19//eXcqy50vqxRWFQNMqWG97Ve3eZdRRqduUhY+3JgZoF6FO6ZM aKBa4A1eJ/aKXU76mR9r9lvT4iABkg+0Sm/Cve2dyCTvhA7VAI7sksverbtJVW/2KJprZ72MV 08/bikqWwwtd6GA0LKYzaRw/wNglfuToitJxn/a5LHf8tW2PKFth3O94FGIpiM3E4sXQBfAhr 2WjnWXsWaxPtkJ6iijJeH9BfwCpmm5Qh4ConI9X0elJLxTbPZOGVFZPZQd+f07OvVTik2n8Fb 6OrV2ynOjoohTm2MB0FpMDmjqPLVBSRArhIsvcb7uccbkHxfyKOs863DIYP3ChrqLvP1P/eck R9A8Rw1bnHmWjp3UtoQC5renptBxT3Jkw9nS5C4tvW1jF0+DYl6fBO8tXkud7GXVPsmUnHc72 x+rBx1bA9kL3BV/2+7ZL27IZYx33bCjbMjeNGZFuOk5xhCQCnVUQDJicSDSNQwZCX7+86Y4eQ GEH8mehP/lSQ9dzTDymYLxem9zZdxhtFq5yFvsTCm1McKxM6Nf3brzo9Rm1bSQ/dHk1u2HGUz KOjNZeK9kNw+4KJDAdxQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Various block drivers implement the CDROMMULTISESSION, CDROM_GET_CAPABILITY, and CDROMEJECT ioctl commands, relying on the block layer to handle compat_ioctl mode for them. Move this into the drivers directly as a preparation for simplifying the block layer later. Since some of these commands need a compat_ptr() conversion, introduce a blkdev_compat_ptr_ioctl() helper function that can be used as the .compat_ioctl callback for those drivers that only support compatible commands. The actual CD-ROM drivers that call cdrom_ioctl() are converted in a separate patch. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 21 +++++++++++++++++++++ drivers/block/floppy.c | 3 +++ drivers/block/paride/pd.c | 1 + drivers/block/paride/pf.c | 1 + drivers/block/sunvdc.c | 1 + drivers/block/xen-blkfront.c | 1 + include/linux/blkdev.h | 7 +++++++ 7 files changed, 35 insertions(+) -- 2.20.0 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/drivers/block/floppy.c b/drivers/block/floppy.c index 485865fd0412..cd3612e4e2e1 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3879,6 +3879,9 @@ static int fd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int { int drive = (long)bdev->bd_disk->private_data; switch (cmd) { + case CDROMEJECT: /* CD-ROM eject */ + case 0x6470: /* SunOS floppy eject */ + case FDMSGON: case FDMSGOFF: case FDSETEMSGTRESH: diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c index 6f9ad3fc716f..c0967507d085 100644 --- a/drivers/block/paride/pd.c +++ b/drivers/block/paride/pd.c @@ -874,6 +874,7 @@ static const struct block_device_operations pd_fops = { .open = pd_open, .release = pd_release, .ioctl = pd_ioctl, + .compat_ioctl = pd_ioctl, .getgeo = pd_getgeo, .check_events = pd_check_events, .revalidate_disk= pd_revalidate diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c index 6b7d4cab3687..bb09f21ce21a 100644 --- a/drivers/block/paride/pf.c +++ b/drivers/block/paride/pf.c @@ -276,6 +276,7 @@ static const struct block_device_operations pf_fops = { .open = pf_open, .release = pf_release, .ioctl = pf_ioctl, + .compat_ioctl = pf_ioctl, .getgeo = pf_getgeo, .check_events = pf_check_events, }; diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c index 571612e233fe..39aeebc6837d 100644 --- a/drivers/block/sunvdc.c +++ b/drivers/block/sunvdc.c @@ -171,6 +171,7 @@ static const struct block_device_operations vdc_fops = { .owner = THIS_MODULE, .getgeo = vdc_getgeo, .ioctl = vdc_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, }; static void vdc_blk_queue_start(struct vdc_port *port) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index a74d03913822..23c86350a5ab 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -2632,6 +2632,7 @@ static const struct block_device_operations xlvbd_block_fops = .release = blkif_release, .getgeo = blkif_getgeo, .ioctl = blkif_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, }; 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 *); From patchwork Wed Dec 11 20:42:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181325 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1043875ile; Wed, 11 Dec 2019 12:47:18 -0800 (PST) X-Google-Smtp-Source: APXvYqxyUV1wZzDGdQLzL7DI28zuVV54gjycRtZp1T7SDu3Ig0tXAE+ksrCYmJVPt/HU9V3g1gN7 X-Received: by 2002:a05:6830:1555:: with SMTP id l21mr3645260otp.41.1576097238509; Wed, 11 Dec 2019 12:47:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097238; cv=none; d=google.com; s=arc-20160816; b=m3UelGw5s767EXoziI6F6rKprtDoc1vGAFdxTtGG4AL9BmtK6x5zaIQtNKQ7HTf0LG w9F286gCqgr6NIS4Vb+/iPYuABgOIjk2Mak18keF+e+DbpYMpLF55d/NmLr6vV/BTN1L nzhyP7L3qoJF3HRAlGr+R8Qe+pPdWdFO0DIsbIXlx7HeZdR21IaHiwLPB1cTPm4Y8NJi AtBM2BtNWyFuqYUorVViWUU+rBWtyajRihAylcyXa2PLpeMnOdwUdWwIM6KpumTpLQ9n edlkcfFyVnEXDOUUQe94i+gHYhW42zpDsDne1BXW5YQWkZGDmwzgFdl833en6w3Q3nGu aB/g== 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=bSMoH68OJuS2SiyqIA0a/D4rZaEt5209rKVTqBaz+Zw=; b=QVIDcqbGgVzfmaE8KLjJ5QydNZzwqXgsCQxQLnbh2akoW738HnlICn4UXL7Z53DqZQ waXWKK2ZbGS9VZgd8Vcc8KNiuKwORtRRV+VcKcTmQGv/aiL1qM8NnCX6Ir6GfHIzzhxX EDjQjMj48R6kQ2nGICjLCdBxd51PslbHQl89zZNeW03t+WBna4uP3ZvzKKYcb4Aj/ja4 qI4FEv+TY7kyGc7D1htN+g5j+OUrL29pwsdGVOSCAdnQRyafSWKSwq3olhPJadi9B7Er FZXgFh76FsgDRjjoFLY428MYFsyxpmkuhLvbkKbypt/B0VjiaTtsC9YS5YzmS61mGHdq ZlYw== 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 s14si1687082otq.37.2019.12.11.12.47.18; Wed, 11 Dec 2019 12:47:18 -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 S1726683AbfLKUrR (ORCPT + 27 others); Wed, 11 Dec 2019 15:47:17 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:53299 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfLKUrQ (ORCPT ); Wed, 11 Dec 2019 15:47:16 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N7Qt9-1heGB12Xy1-017l1U; Wed, 11 Dec 2019 21:47:02 +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 , Hannes Reinecke , linux-scsi@vger.kernel.org Subject: [PATCH 12/24] compat_ioctl: add scsi_compat_ioctl Date: Wed, 11 Dec 2019 21:42:46 +0100 Message-Id: <20191211204306.1207817-13-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:K9j2t2hRIDN1s24Qc+2ApYId+NR70I0ahQXZVZus7eh7p5W3KwC BexL4HNQXEGo1mU+/z+mF+nWOdFPvBBNu+B3O+hhRy6chSEBu6VtLmq6zXb4gdu/3JIZkWp fxlku3lFgKF/LiyPgpzzL8FHeSh1jnUjSLS5XVoRw4PLA0ipNO8wXuf5fhuEbAVIaJ5e9cD Xp7cjFIB9kwrj12+7CkmA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:iCPMOUwnMGU=:56ma4IjE+C5v8tJDupanbg ffaWXakkoowFJced4omf+RzDDMZK7NMo9/Q1isuFrGMdxbOrbBfPNB4zVP292J9Lbze6z2vby 06MP9oMvdo6eX2EQ+g6AyzUwrOXltJyuT/hOYV6Su2QTSINt/C4WWoqEXtdSge4uz7tfCyCfM NAUvMG9TLvoWOo7S8XMZgeW9VdarpO8Z6RaMpJWsAqIEFK7gKubRgL8PBHYuUNrnT6DkeHy6Y D2RgrNSWuI3nI0AUGGni+g0HZzWgwLC5QtKsxsQj9gSQytfqAuiY5q/RIT/0Jd5MHcv6ouf+x EEB3nJoKwgCYlh8Lx79x5uuRLFOQpSySmOqaD7P17FrJWT2sby0FrSqCrNx82EaFhOFk0y8B1 eVwHci2CU8wKbf3Tt2N3rLVN+DK/ozFKAXNYPJbwcpoQRIHtcXAuCVgELFDqYsGkUa+ql2gvC I32A8I4uzEqukJM7Z9b+D9DNGfOl2HZvnkR/ZhmtObpEo5/pUFMfj11wTiSsTYebpdrhG8+HY 8c/NxNufKbs+tpi1t5B/poXDjXurDqYNvg+E5zjGn8xLXJivGVlsSEEEwwvZU94xH2RO97qTk sd9kyb/N8K8jMfqZqEz8RnBPgNlLtXMRO04cU0ns0ZvRQbc6aumAItMheTcPj+ZUIQPfCTPWK oAVIFgY8NprWEIdqZfjvA01MQ2v5Zo3hXfyOGYaXQlRWV74VXSf4th8Xzis0k/650QKI8mrDK cQqX4kJHyT/K3IX6moEX6stv8hy4WfiXEZf8ZfqNZXgEK9idm51FpDCc6gyFKsAtIGdDb4bZ5 uVs5sguZu62Bjex2nnONT0YwfyPyRwY1tNjMH6PcTOBj5p2/ohWqRAkR/T3GTfRVOUcCbpZ1w vdIHEV5oDXVh+MX6OPeA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to move the compat handling for SCSI ioctl commands out of fs/compat_ioctl.c into the individual drivers, we need a helper function first to match the native ioctl handler called by sd, sr, st, etc. Signed-off-by: Arnd Bergmann --- drivers/scsi/scsi_ioctl.c | 54 +++++++++++++++++++++++++++++---------- include/scsi/scsi_ioctl.h | 1 + 2 files changed, 41 insertions(+), 14 deletions(-) -- 2.20.0 diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index 57bcd05605bf..8f3af87b6bb0 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c @@ -189,17 +189,7 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg) } -/** - * scsi_ioctl - Dispatch ioctl to scsi device - * @sdev: scsi device receiving ioctl - * @cmd: which ioctl is it - * @arg: data associated with ioctl - * - * Description: The scsi_ioctl() function differs from most ioctls in that it - * does not take a major/minor number as the dev field. Rather, it takes - * a pointer to a &struct scsi_device. - */ -int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +static int scsi_ioctl_common(struct scsi_device *sdev, int cmd, void __user *arg) { char scsi_cmd[MAX_COMMAND_SIZE]; struct scsi_sense_hdr sense_hdr; @@ -266,14 +256,50 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) return scsi_ioctl_get_pci(sdev, arg); case SG_SCSI_RESET: return scsi_ioctl_reset(sdev, arg); - default: - if (sdev->host->hostt->ioctl) - return sdev->host->hostt->ioctl(sdev, cmd, arg); } + return -ENOIOCTLCMD; +} + +/** + * scsi_ioctl - Dispatch ioctl to scsi device + * @sdev: scsi device receiving ioctl + * @cmd: which ioctl is it + * @arg: data associated with ioctl + * + * Description: The scsi_ioctl() function differs from most ioctls in that it + * does not take a major/minor number as the dev field. Rather, it takes + * a pointer to a &struct scsi_device. + */ +int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +{ + int ret = scsi_ioctl_common(sdev, cmd, arg); + + if (ret != -ENOIOCTLCMD) + return ret; + + if (sdev->host->hostt->ioctl) + return sdev->host->hostt->ioctl(sdev, cmd, arg); + return -EINVAL; } EXPORT_SYMBOL(scsi_ioctl); +#ifdef CONFIG_COMPAT +int scsi_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) +{ + int ret = scsi_ioctl_common(sdev, cmd, arg); + + if (ret != -ENOIOCTLCMD) + return ret; + + if (sdev->host->hostt->compat_ioctl) + return sdev->host->hostt->compat_ioctl(sdev, cmd, arg); + + return ret; +} +EXPORT_SYMBOL(scsi_compat_ioctl); +#endif + /* * We can process a reset even when a device isn't fully operable. */ diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h index 5101e987c0ef..4fe69d863b5d 100644 --- a/include/scsi/scsi_ioctl.h +++ b/include/scsi/scsi_ioctl.h @@ -44,6 +44,7 @@ typedef struct scsi_fctargaddress { int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, int cmd, bool ndelay); extern int scsi_ioctl(struct scsi_device *, int, void __user *); +extern int scsi_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg); #endif /* __KERNEL__ */ #endif /* _SCSI_IOCTL_H */ From patchwork Wed Dec 11 20:42:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181327 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1044043ile; Wed, 11 Dec 2019 12:47:27 -0800 (PST) X-Google-Smtp-Source: APXvYqxIgYRmogk22BaUSo44YD+888smg8aeviazsrfFqo4CYdHi3t1ZlR8yxNgJs4uqYeychuQb X-Received: by 2002:a9d:7a8f:: with SMTP id l15mr3689283otn.109.1576097247124; Wed, 11 Dec 2019 12:47:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097247; cv=none; d=google.com; s=arc-20160816; b=w2/eF/pejWivjBTEwazMmeNeCFI+KBK/0onDvMwS1zg6iIjWcFVnwLVRtAOMA+WUq0 CQ0WmzZ4X2MeMsCiZy2KoEaSTJsFj8oy1yzEfd++mV083ybllzFQyNIFEEjayad+/7Lx nVkjCPGaKYLGes+f0gUCfdAuh7YgBdEr7o3cc1DeD58RNRr9WNeaQiCo1reDWv8fcZZy q9kRDJ7NRkUOqOurIh+xgTZfVXKs/tqqP/h7LHg1lilaIPZOg8AgMWdzf95BBsUoy+3I Y13HX7xl2SCer0HSPtKHW5BEeFtN89IwLQQcdSmvJP1FrMJ6McrZmvLkyW4UGb6qxAO0 6pXQ== 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=1AVkuICYuUJ9D3eRwQf8/7qao6yYJFs+YeK6ywV2mhg=; b=B61KMNQVACIZ/laAArj22TyrXMfaFRRenNiPP3ZT4D4JFWWTHjLdILMn51r/RQx13d EiXHWWG2mkW96aDZR61q/pM9g/vne+kdAmLDMEp8z2Ny4/+Y5fIL17hJJTxGn3d6Hq1P Q1F/wlHoSRAVjh5GwkFcun7NYiuYBJbadBkKZoUUreWXq6UdFC4AsdqvNEQQGAbVYPVn naVyOMZF65lty1p7naQavHakiCwuKlWyF6Y7TinNvytT4uwTZiHEvHabORpiq1KGeXv2 otrTTV453TqPvKwr9UTT0e63FWRYl22EXfuqyG0+skBuhVaLiTOw1SdngEE1L/wtVwZs eAXQ== 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 w1si1835897otp.57.2019.12.11.12.47.26; Wed, 11 Dec 2019 12:47:27 -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 S1727104AbfLKUrZ (ORCPT + 27 others); Wed, 11 Dec 2019 15:47:25 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:44493 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUrZ (ORCPT ); Wed, 11 Dec 2019 15:47:25 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MYNS0-1iAqRJ0S8I-00VNnz; Wed, 11 Dec 2019 21:47:11 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , FUJITA Tomonori Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Chaitanya Kulkarni , Benjamin Block , linux-scsi@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 13/24] compat_ioctl: bsg: add handler Date: Wed, 11 Dec 2019 21:42:47 +0100 Message-Id: <20191211204306.1207817-14-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:9E//4H5jUjxcz88C86R1AD+v07xscBKEn+U5T2BAdtLUAnLN0TR pJgxkACJ2VOrwR21uFSKt045qw16CVFBKgxXRjl0wRXdIi5qvgtMPA2iOaEdMhuh+mWULCt EUPuHtjCDvcR/p3/P41WVjN3SGzN2XxCq0aarb5ncSCwLZiBPEKJmhY3WKVzezophJM9sQp yCYgZnaFk6bm8zt5Q8ozA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:v55hPGbeD1k=:IimA31h3OAuyU1W0DDaoVL g3OvsSmdNHSaEs4Gs3UxXci2k4RCJNRBJKKffYXVlD10ugWEUY706Wsw/XVqt2dVNSIGEVXhA dvGgAN0AuKEfOq5Nr0oXoiJqkxCe44UFhuA7h+Sy4+bZja7QiweCUAynaH7Ek7yIHCu928Ez3 CvDvPNgttFkSqonwZYX3/RnPO1a3iQbOW1/vN6ND6tFLN8A/OYn4HidUrtseO+1mkmyG8FcnA iJXScjWKnL4tqXgMvrfRQkEFrOEGgf6UW7eKKIEr8ngL2bZmpuI197iNv5aTI1Pp+b+44SUs3 mQD4jJ0xqPv+j11bZNqRawcLFtm1spFQNnWb3tidW3guiC8lrJSajAlCE6/kvkRxmen5rxvrq XBhbze+FZfygxhggJERbbk+41YUTfg55I2gJVbXCrIkkTTnN0Od+/lQUkCQtMxYapqX7MIToa Em/vHawJc2dL4FVsupr2V+/H6OEcgHZfb4RMYLMdhqCUaJ31tesvtmvDd51l4SPNPhLznfeIy 7OVhdD05wE7GN98NgSBQBh0IYZOE82NOU3tvk9NScW44ZETUBByBOOavsTmG8xKUakgx8mMR6 exaE4zh0EwsTfnwNR7e7G+cS01mRpVT2XaIp1GTxEI3XptQRkiGak5XEQhVzoLtQlejkQEIF2 EeHI58uWrmr5WVkixR8GE95knlczX1j0ZOAnfGn/08CEylXQCV6hqKOlEGXq6rHu7qraoR0Mv sBXSSOxLCkiH35xBBwc8Fr0dMR9d9uAu4ubde7KiPPNX+5R5TRjsGYer3bj96/L5SAVl604vB r/PrNrfEq0chmpD/BedGKE5ayZasUml2ioBCsX2dmqJ+l8mZySv68q8O4gjp8CakeUK7DZsZc d0oG+rl2zmJMClUdj1yw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org bsg_ioctl() calls into scsi_cmd_ioctl() for a couple of generic commands and relies on fs/compat_ioctl.c to handle it correctly in compat mode. Adding a private compat_ioctl() handler avoids that round-trip and lets us get rid of the generic emulation once this is done. Note that bsg implements an SG_IO command that is different from the other drivers and does not need emulation. Signed-off-by: Arnd Bergmann --- block/bsg.c | 1 + 1 file changed, 1 insertion(+) -- 2.20.0 diff --git a/block/bsg.c b/block/bsg.c index 833c44b3d458..d7bae94b64d9 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -382,6 +382,7 @@ static const struct file_operations bsg_fops = { .open = bsg_open, .release = bsg_release, .unlocked_ioctl = bsg_ioctl, + .compat_ioctl = compat_ptr_ioctl, .owner = THIS_MODULE, .llseek = default_llseek, }; From patchwork Wed Dec 11 20:42:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181328 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1044820ile; Wed, 11 Dec 2019 12:48:14 -0800 (PST) X-Google-Smtp-Source: APXvYqzZe+IDRw+jNOSrsxg8+AAPLXDi7ES1yYA4/WZOK2DqWPGWxDe1Hm6mPI8LQfkpfAQnSaR0 X-Received: by 2002:a54:488d:: with SMTP id r13mr4052520oic.115.1576097294074; Wed, 11 Dec 2019 12:48:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097294; cv=none; d=google.com; s=arc-20160816; b=bKkEFe4VnxtXXJpdt0e0vqoNbS2NCr4tbvDspP6nregEzLI5FwJpbS4MJIDkJMt1GL DI0+MJN0iunlVzzcL+MLfRQuHRmFO98dSeusrcSKYiiPrPacAt7qmX4yqqVN0kPdFVnT SQ75fy0fc88GdzTtRPfDszTextkUXFBkuutFUuFrnKmb4iDsckdCEbYQQACC9nIboKW9 V4eP2d+XhJHmy+VQJOyQ6Ukiz8WELBA8CcbmG6AI6sOSn/EGaLE+E1XbR5MAvTcHt9j6 0fV/BCVcfrkEqgwqsguhjWxH2tYh/aqme+AShjz/SnX6Zffo0P00EGetqePhd5W/eX8t kz/A== 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=vJ6DAIYEbJkv9DabE3g2Y3jbfkRa/IbLo6jaDEfinnI=; b=g6UJ85yriCMKHuJmNSueGRIo4iiENQdfHfDrCp3SChlHssFGCQczoHWriuNR2MMnhn +lVAFUzVQdopfon+1aGqgAnGGcw7/k5mZBu8wsrDolo7wIzizIICLjOCu41FLYyXcOco dIm2pc0LrkgxjFvsVSudOmsPRD9OqUfNr71iQchJXEuo5Vc39lbyK8fKU7bg0+wBynys hiSN0ZuCHaksL4Nng+Ev9XcKTE73Y21rgJwFA3I4IPjYLWvB0RfJgT6ELS4aVQhifRHl stZqWc5ui3+kuzRhV5SE3LLxvItUmAwmWIzIZCAWB1OjGYkGl++4WwcXWC1SkDEYaSJJ 9gAQ== 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 i206si1838419oif.173.2019.12.11.12.48.13; Wed, 11 Dec 2019 12:48:14 -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 S1726974AbfLKUsM (ORCPT + 27 others); Wed, 11 Dec 2019 15:48:12 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:38543 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUsM (ORCPT ); Wed, 11 Dec 2019 15:48:12 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mekzb-1i6twK2kir-00ann6; Wed, 11 Dec 2019 21:47:37 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , "David S. Miller" Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , "Gustavo A. R. Silva" , Hannes Reinecke , Martin Wilck , Amol Surati , linux-ide@vger.kernel.org Subject: [PATCH 14/24] compat_ioctl: ide: floppy: add handler Date: Wed, 11 Dec 2019 21:42:48 +0100 Message-Id: <20191211204306.1207817-15-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:IvMP2z5YVCzTvfD6TzM8mO/FDut3fDi9clWAIVOAKQ93amLy1cC HRMNnnS3Jh8NFtNdPec+W92Ubk5oC4PIQ3b9ys0V92gINm3PrE+R/TaBqRI1lIF5MR1sjAn Bzi/Q//wOfsqW13GMHz89tVMV39l31bTV1ZBZe90popRMNO1u9Y/M7buvnmvOQ23RPSATwO LKCmU89E6oL19n6kj5HnQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:cJ5UoDf47fg=:6MvwK9m7x1EFzq7MGFpMQ6 6R8OBWh6wz4jtW+BKHiMrITSuki5bg/Up3EZs+tx/Qeeeq1rSLx67KPrIhJD2PFIRt+xLEV+E QVyO6L86/XuOBAxVYwX/G+ESSpexRklx0K2mFDs4TfnuysHD6tfTeCoaQOJEbDcGv0xqtp+Q5 X9h5d5UDGJLkisRKOX1jVMT7//kcEBElGzg6sd/rC8OcNnz4rNUAQlVnFOymcbTh0RFGTkDoS W7IOKgldnjK/CTZcmAupSaONozFLgA+a1gt04xLqVHqWQVBelEFvZ1IZ/R6KdX/2QEMeuCl7N nxtmnP7mIji3dF+QKukKMKB/dZQsugZtF68QmAJ1lLP7tEtOJJ0L90bEqK4OgXZDom8VQp2ZE UmjXM+SEf0x3A2lJqrux+5ipbbCbVrMpXtRbCk7uswAW6SL0+ZIKDrTu/BttPEuxB46mSqymO t3GrjL7+SL2ZibkZMIwi4WAuJthf4lezXj6zTrBSEvszLeYsTbDQr4yIDO5IsljICUZz8bthE UhhcOkxszZbuesFbwkaKIAfOD7CEqCkVeEHLoiFE/F8q8a3dOkN1muGcPLT4COXqGf6niTlQf jdM516lHC/yIioUexSCh1kNmUW4hBhgaE7v0Ojw3kBYyw4M8WzL6Hm4/aMLlgi3IIQcafZIym nQNmvCwwxM+0hs085vppOCYaY1PE1wjL9XF/eLJ/gg6O2C00JpaL8+fF007qwswTNSbaPxD/p LvipP8LJhfQ83m8mBhTrSEdhvvmMzIPcXDSyrC14EIfTZ/YBVg2NwEYTZOSB8p4LnZNW+ohAf On/I37Ay5Zi4/9koZjL9kLEiyvR+kn1rDP0uM9/O3cvV6cP1C+q+xwKjiSWrGJGT8tztLZMqi YU5r+N70aE8HFqBeY1qw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rather than relying on fs/compat_ioctl.c, this adds support for a compat_ioctl() callback in the ide-floppy driver directly, which lets it translate the scsi commands. Signed-off-by: Arnd Bergmann --- drivers/ide/ide-floppy.c | 4 ++++ drivers/ide/ide-floppy.h | 2 ++ drivers/ide/ide-floppy_ioctl.c | 36 ++++++++++++++++++++++++++++++++++ drivers/ide/ide-gd.c | 14 +++++++++++++ include/linux/ide.h | 2 ++ 5 files changed, 58 insertions(+) -- 2.20.0 diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index 1ea2f9e82bf8..1fe1f9d37a51 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -546,4 +547,7 @@ const struct ide_disk_ops ide_atapi_disk_ops = { .set_doorlock = ide_set_media_lock, .do_request = ide_floppy_do_request, .ioctl = ide_floppy_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ide_floppy_compat_ioctl, +#endif }; diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h index 13c9b4b6d75e..8505a5f58f4e 100644 --- a/drivers/ide/ide-floppy.h +++ b/drivers/ide/ide-floppy.h @@ -26,6 +26,8 @@ void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *); /* ide-floppy_ioctl.c */ int ide_floppy_ioctl(ide_drive_t *, struct block_device *, fmode_t, unsigned int, unsigned long); +int ide_floppy_compat_ioctl(ide_drive_t *, struct block_device *, fmode_t, + unsigned int, unsigned long); #ifdef CONFIG_IDE_PROC_FS /* ide-floppy_proc.c */ diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c index 40a2ebe34e1d..4fd70f804d6f 100644 --- a/drivers/ide/ide-floppy_ioctl.c +++ b/drivers/ide/ide-floppy_ioctl.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -302,3 +303,38 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev, mutex_unlock(&ide_floppy_ioctl_mutex); return err; } + +#ifdef CONFIG_COMPAT +int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev, + fmode_t mode, unsigned int cmd, unsigned long arg) +{ + struct ide_atapi_pc pc; + void __user *argp = compat_ptr(arg); + int err; + + mutex_lock(&ide_floppy_ioctl_mutex); + if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) { + err = ide_floppy_lockdoor(drive, &pc, arg, cmd); + goto out; + } + + err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp); + if (err != -ENOTTY) + goto out; + + /* + * skip SCSI_IOCTL_SEND_COMMAND (deprecated) + * and CDROM_SEND_PACKET (legacy) ioctls + */ + if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) + err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); + + /* + * there is no generic_ide_compat_ioctl(), that is handled + * through compat_blkdev_ioctl(). + */ +out: + mutex_unlock(&ide_floppy_ioctl_mutex); + return err; +} +#endif diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c index dba9ad5c97b3..1b0270efcce2 100644 --- a/drivers/ide/ide-gd.c +++ b/drivers/ide/ide-gd.c @@ -341,11 +341,25 @@ static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode, return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg); } +#ifdef CONFIG_COMPAT +static int ide_gd_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj); + ide_drive_t *drive = idkp->drive; + + return drive->disk_ops->compat_ioctl(drive, bdev, mode, cmd, arg); +} +#endif + static const struct block_device_operations ide_gd_ops = { .owner = THIS_MODULE, .open = ide_gd_unlocked_open, .release = ide_gd_release, .ioctl = ide_gd_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = ide_gd_compat_ioctl, +#endif .getgeo = ide_gd_getgeo, .check_events = ide_gd_check_events, .unlock_native_capacity = ide_gd_unlock_native_capacity, diff --git a/include/linux/ide.h b/include/linux/ide.h index 46b771d6999e..06dae6438557 100644 --- a/include/linux/ide.h +++ b/include/linux/ide.h @@ -413,6 +413,8 @@ struct ide_disk_ops { sector_t); int (*ioctl)(struct ide_drive_s *, struct block_device *, fmode_t, unsigned int, unsigned long); + int (*compat_ioctl)(struct ide_drive_s *, struct block_device *, + fmode_t, unsigned int, unsigned long); }; /* ATAPI device flags */ From patchwork Wed Dec 11 20:42:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181329 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1046229ile; Wed, 11 Dec 2019 12:49:37 -0800 (PST) X-Google-Smtp-Source: APXvYqwCB9hOEx7Op01FlWVUqdCQq/PJRFT0AEf/29mMzzXXmSkrzuKPy2pPj4FN5GLt4XNNMHel X-Received: by 2002:a05:6830:594:: with SMTP id c20mr2750502oth.166.1576097376972; Wed, 11 Dec 2019 12:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097376; cv=none; d=google.com; s=arc-20160816; b=a24HtGCULPblQkyLave4IqF3cpn5Zv7w/cNoxNqP6sx1kEWfm1jP/0wVKwsR8mjvx3 tE8rOBiY78JIw8/T44xUXY/niUDa/v5LP/RCIpMPaN03wD+VzdETUeB/ucq5bqHZ399b 1wiVkdxl1HW5/jNLM3DoRrr+QhipiqyQIM4kkMsykevi6o+5ofRdDuTQt5dJeD0ygvo3 0p0a7w+EWLGuD9ZrXPKfliPrx/Tq56wTWrK6bBrS2xfBRzz2q5J9cQxa+z/iDdegph0w /pQLUj3HlLIAltImwAsLZbT8XXMKQk3+eBCpkThvrcB/nojVZLSgupkJdbhMO5YYqJQs YRyA== 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=PF7Qz5DKcwJUjXjMxu5c2rst/os0YxvSQ+1rBygm6tQ=; b=cKWS9GWxdJ+2C+JKfi9tdcXp0ZrkKtw88bJZnnu6BJ6V/fYXC7LDBM3zB6lO7oTaqT g+gDVpgsxABBvmIoK+SQAIzDI1H6dXlCWxHM6VF7m8zDsIP1BG3KsFO05BLrQ//K359u ksDYVs/EHfpTcDoWg27sL4MmS6YMzUk0qksjUFO+9NeLWi/JfyOgylqug51avttrcCr3 K/zUIDUdfa1WAruQO/AtxmVqnbHt6xNTFffT3KuR9NeFTJqjBXoBAKf4RXmGcEnfX4ir 4HiMqmTQgZtpMgccb5Tfn6uSNK4IUTYUVmXtKcteEi/ZKoP8kHwOyFiT3/EF80c5x0tW vujg== 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 z8si1834403oto.36.2019.12.11.12.49.36; Wed, 11 Dec 2019 12:49:36 -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 S1727421AbfLKUtf (ORCPT + 27 others); Wed, 11 Dec 2019 15:49:35 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:42825 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726831AbfLKUte (ORCPT ); Wed, 11 Dec 2019 15:49:34 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M42b8-1if8um20TA-0005Wv; Wed, 11 Dec 2019 21:48:56 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , "Michael S. Tsirkin" , Jason Wang , Doug Gilbert , =?utf-8?q?Kai_M=C3=A4kisara?= Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Paolo Bonzini , Stefan Hajnoczi , Bart Van Assche , Hannes Reinecke , Damien Le Moal , John Garry , virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 15/24] compat_ioctl: scsi: move ioctl handling into drivers Date: Wed, 11 Dec 2019 21:42:49 +0100 Message-Id: <20191211204306.1207817-16-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:BaNM5i3rFNToDWp9jqn98bS6gnJlc1tUHYGa076M37t4numkmEH rmgMewG1Vi+BsQ/z8r6JFumNEzJhwXbkY93w78CnKNhOKnoChx4VrIkfSPo2MoO3z82l4VB J4KPCeRZLRCn0RIC0yEceOWO4NbMkkcX4eSx2TVmRsLJ70LxQTgVEu92Y4ycBBUW/GNlT9b VCNWFpOoJ+xrP9oEfE68w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:U6GIxbucmvM=:2VfssZVNDAhPiU7N9HwQPZ PCmC7/SVP5XheKAB6Hw9XDyg+6C/vuTLprB69lkl2LruWKv7lTayTvXMmc/x63Qix9mHc2eUj hZQwOEvWYbFrBIozvkET+/y0P9TsC735E9LmTXywAr3yOjfz8hMoA6w5jrTidIHTH/MlF6R/l X35huqxBnekp87Sv73Eed2nQAGwOlVvquGQXWgb9SBd4rCMvhKdCrg2D96A8TNan3cl3YEtzf jrWokUNDC+CYqFL+YHp+6cYm+/4WuNoeF/6fzixpeheuc2v85u/+/QNBSa2gEtj29DGri86eT /wETNUAM9Yh4EWqj68xNOrdiEDgAt1RhMvHF5uEVpYbbIFhJuy19g+OdC1pLU8vVOTJ8UU3dI mmzRTEJDklVDi4yFDYF8T2PjwAMdgWjKLT97pOo47LYi5ohyXhU+pInkeUIMfk6kPa8X92e93 SD1K9xWLlMCKeM8Y1DHp5c/8pR1x7lgKPsApQiZaFFfwav/igamRrpQMTB89yOOQQBM9vlFRi u3tioDUOgZ7snHqyDzp7b493e6kQK9gYIQ6/4RYYjcnByHyiNNlh0suiObzAcgFOTcfCK3TPa SJtLmB3K2HOmQp/1kkUaiTyUHeWMU5lkXAaWIT1L30+FpJH3IxYnYrhJZqVglL0OlS6BEAFKH 04ngRIAWr9G00f2BAlnvNgObxSUUg4hbUnAKZFOW3r7nW7ZpcOQk6q5cWwsJuw+hqxXf+pzpK dp5cYF834e9IhpREH1CamKSH7TaALhrqE2qXxMvplAHcUX4UYrvJWzzla5in9RqDjCeRGaGr3 PoMNxOjDo+uzozEBY9V+dW6WXEEn7bfYXO1tCogxKRg203EBa9xjS5JgtuTLlT313bVGDMz0s ZeB2jEMeV7pnZW2S7tpQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each driver calling scsi_ioctl() gets an equivalent compat_ioctl() handler that implements the same commands by calling scsi_compat_ioctl(). The scsi_cmd_ioctl() and scsi_cmd_blk_ioctl() functions are compatible at this point, so any driver that calls those can do so for both native and compat mode, with the argument passed through compat_ptr(). With this, we can remove the entries from fs/compat_ioctl.c. The new code is larger, but should be easier to maintain and keep updated with newly added commands. Signed-off-by: Arnd Bergmann --- drivers/block/virtio_blk.c | 3 + drivers/scsi/ch.c | 9 ++- drivers/scsi/sd.c | 50 ++++++-------- drivers/scsi/sg.c | 44 ++++++++----- drivers/scsi/sr.c | 57 ++++++++++++++-- drivers/scsi/st.c | 51 ++++++++------ fs/compat_ioctl.c | 132 +------------------------------------ 7 files changed, 142 insertions(+), 204 deletions(-) -- 2.20.0 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 7ffd719d89de..fbbf18ac1d5d 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -405,6 +405,9 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) static const struct block_device_operations virtblk_fops = { .ioctl = virtblk_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = blkdev_compat_ptr_ioctl, +#endif .owner = THIS_MODULE, .getgeo = virtblk_getgeo, }; diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c index 76751d6c7f0d..ed5f4a6ae270 100644 --- a/drivers/scsi/ch.c +++ b/drivers/scsi/ch.c @@ -872,6 +872,10 @@ static long ch_ioctl_compat(struct file * file, unsigned int cmd, unsigned long arg) { scsi_changer *ch = file->private_data; + int retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd, + file->f_flags & O_NDELAY); + if (retval) + return retval; switch (cmd) { case CHIOGPARAMS: @@ -883,7 +887,7 @@ static long ch_ioctl_compat(struct file * file, case CHIOINITELEM: case CHIOSVOLTAG: /* compatible */ - return ch_ioctl(file, cmd, arg); + return ch_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); case CHIOGSTATUS32: { struct changer_element_status32 ces32; @@ -898,8 +902,7 @@ static long ch_ioctl_compat(struct file * file, return ch_gstatus(ch, ces32.ces_type, data); } default: - // return scsi_ioctl_compat(ch->device, cmd, (void*)arg); - return -ENOIOCTLCMD; + return scsi_compat_ioctl(ch->device, cmd, compat_ptr(arg)); } } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index cea625906440..5afb0046b12a 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1465,13 +1465,12 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo) * Note: most ioctls are forward onto the block subsystem or further * down in the scsi subsystem. **/ -static int sd_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) +static int sd_ioctl_common(struct block_device *bdev, fmode_t mode, + unsigned int cmd, void __user *p) { struct gendisk *disk = bdev->bd_disk; struct scsi_disk *sdkp = scsi_disk(disk); struct scsi_device *sdp = sdkp->device; - void __user *p = (void __user *)arg; int error; SCSI_LOG_IOCTL(1, sd_printk(KERN_INFO, sdkp, "sd_ioctl: disk=%s, " @@ -1507,9 +1506,6 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode, break; default: error = scsi_cmd_blk_ioctl(bdev, mode, cmd, p); - if (error != -ENOTTY) - break; - error = scsi_ioctl(sdp, cmd, p); break; } out: @@ -1691,39 +1687,31 @@ static void sd_rescan(struct device *dev) revalidate_disk(sdkp->disk); } +static int sd_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + void __user *p = (void __user *)arg; + int ret; + + ret = sd_ioctl_common(bdev, mode, cmd, p); + if (ret != -ENOTTY) + return ret; + + return scsi_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p); +} #ifdef CONFIG_COMPAT -/* - * This gets directly called from VFS. When the ioctl - * is not recognized we go back to the other translation paths. - */ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { - struct gendisk *disk = bdev->bd_disk; - struct scsi_disk *sdkp = scsi_disk(disk); - struct scsi_device *sdev = sdkp->device; void __user *p = compat_ptr(arg); - int error; - - error = scsi_verify_blk_ioctl(bdev, cmd); - if (error < 0) - return error; + int ret; - error = scsi_ioctl_block_when_processing_errors(sdev, cmd, - (mode & FMODE_NDELAY) != 0); - if (error) - return error; + ret = sd_ioctl_common(bdev, mode, cmd, p); + if (ret != -ENOTTY) + return ret; - if (is_sed_ioctl(cmd)) - return sed_ioctl(sdkp->opal_dev, cmd, p); - - /* - * Let the static ioctl translation table take care of it. - */ - if (!sdev->host->hostt->compat_ioctl) - return -ENOIOCTLCMD; - return sdev->host->hostt->compat_ioctl(sdev, cmd, p); + return scsi_compat_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p); } #endif diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 985546aac236..08efcee7a34d 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -910,19 +910,14 @@ static int put_compat_request_table(struct compat_sg_req_info __user *o, #endif static long -sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) +sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, + unsigned int cmd_in, void __user *p) { - void __user *p = (void __user *)arg; int __user *ip = p; int result, val, read_only; - Sg_device *sdp; - Sg_fd *sfp; Sg_request *srp; unsigned long iflags; - if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) - return -ENXIO; - SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_ioctl: cmd=0x%x\n", (int) cmd_in)); read_only = (O_RDWR != (filp->f_flags & O_ACCMODE)); @@ -1145,29 +1140,44 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) cmd_in, filp->f_flags & O_NDELAY); if (result) return result; + + return -ENOIOCTLCMD; +} + +static long +sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) +{ + void __user *p = (void __user *)arg; + Sg_device *sdp; + Sg_fd *sfp; + int ret; + + if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) + return -ENXIO; + + ret = sg_ioctl_common(filp, sdp, sfp, cmd_in, p); + if (ret != -ENOIOCTLCMD) + return ret; + return scsi_ioctl(sdp->device, cmd_in, p); } #ifdef CONFIG_COMPAT static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) { + void __user *p = compat_ptr(arg); Sg_device *sdp; Sg_fd *sfp; - struct scsi_device *sdev; + int ret; if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) return -ENXIO; - sdev = sdp->device; - if (sdev->host->hostt->compat_ioctl) { - int ret; - - ret = sdev->host->hostt->compat_ioctl(sdev, cmd_in, (void __user *)arg); - + ret = sg_ioctl_common(filp, sdp, sfp, cmd_in, p); + if (ret != -ENOIOCTLCMD) return ret; - } - - return -ENOIOCTLCMD; + + return scsi_compat_ioctl(sdp->device, cmd_in, p); } #endif diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 4664fdf75c0f..6033a886c42c 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -598,6 +599,55 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, return ret; } +#ifdef CONFIG_COMPAT +static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, + unsigned long arg) +{ + struct scsi_cd *cd = scsi_cd(bdev->bd_disk); + struct scsi_device *sdev = cd->device; + void __user *argp = compat_ptr(arg); + int ret; + + mutex_lock(&sr_mutex); + + ret = scsi_ioctl_block_when_processing_errors(sdev, cmd, + (mode & FMODE_NDELAY) != 0); + if (ret) + goto out; + + scsi_autopm_get_device(sdev); + + /* + * Send SCSI addressing ioctls directly to mid level, send other + * ioctls to cdrom/block level. + */ + switch (cmd) { + case SCSI_IOCTL_GET_IDLUN: + case SCSI_IOCTL_GET_BUS_NUMBER: + ret = scsi_compat_ioctl(sdev, cmd, argp); + goto put; + } + + /* + * CDROM ioctls are handled in the block layer, but + * do the scsi blk ioctls here. + */ + ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); + if (ret != -ENOTTY) + return ret; + + ret = scsi_compat_ioctl(sdev, cmd, argp); + +put: + scsi_autopm_put_device(sdev); + +out: + mutex_unlock(&sr_mutex); + return ret; + +} +#endif + static unsigned int sr_block_check_events(struct gendisk *disk, unsigned int clearing) { @@ -641,12 +691,11 @@ static const struct block_device_operations sr_bdops = .open = sr_block_open, .release = sr_block_release, .ioctl = sr_block_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = sr_block_compat_ioctl, +#endif .check_events = sr_block_check_events, .revalidate_disk = sr_block_revalidate_disk, - /* - * No compat_ioctl for now because sr_block_ioctl never - * seems to pass arbitrary ioctls down to host drivers. - */ }; static int sr_open(struct cdrom_device_info *cdi, int purpose) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 9e3fff2de83e..393f3019ccac 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -3501,7 +3501,7 @@ static int partition_tape(struct scsi_tape *STp, int size) /* The ioctl command */ -static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) +static long st_ioctl_common(struct file *file, unsigned int cmd_in, void __user *p) { int i, cmd_nr, cmd_type, bt; int retval = 0; @@ -3509,7 +3509,6 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) struct scsi_tape *STp = file->private_data; struct st_modedef *STm; struct st_partstat *STps; - void __user *p = (void __user *)arg; if (mutex_lock_interruptible(&STp->lock)) return -ERESTARTSYS; @@ -3824,9 +3823,19 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) } mutex_unlock(&STp->lock); switch (cmd_in) { + case SCSI_IOCTL_STOP_UNIT: + /* unload */ + retval = scsi_ioctl(STp->device, cmd_in, p); + if (!retval) { + STp->rew_at_close = 0; + STp->ready = ST_NO_TAPE; + } + return retval; + case SCSI_IOCTL_GET_IDLUN: case SCSI_IOCTL_GET_BUS_NUMBER: break; + default: if ((cmd_in == SG_IO || cmd_in == SCSI_IOCTL_SEND_COMMAND || @@ -3840,42 +3849,46 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) return i; break; } - retval = scsi_ioctl(STp->device, cmd_in, p); - if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) { /* unload */ - STp->rew_at_close = 0; - STp->ready = ST_NO_TAPE; - } - return retval; + return -ENOTTY; out: mutex_unlock(&STp->lock); return retval; } +static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) +{ + void __user *p = (void __user *)arg; + struct scsi_tape *STp = file->private_data; + int ret; + + ret = st_ioctl_common(file, cmd_in, p); + if (ret != -ENOTTY) + return ret; + + return scsi_ioctl(STp->device, cmd_in, p); +} + #ifdef CONFIG_COMPAT static long st_compat_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) { void __user *p = compat_ptr(arg); struct scsi_tape *STp = file->private_data; - struct scsi_device *sdev = STp->device; - int ret = -ENOIOCTLCMD; + int ret; /* argument conversion is handled using put_user_mtpos/put_user_mtget */ switch (cmd_in) { - case MTIOCTOP: - return st_ioctl(file, MTIOCTOP, (unsigned long)p); case MTIOCPOS32: - return st_ioctl(file, MTIOCPOS, (unsigned long)p); + return st_ioctl_common(file, MTIOCPOS, p); case MTIOCGET32: - return st_ioctl(file, MTIOCGET, (unsigned long)p); + return st_ioctl_common(file, MTIOCGET, p); } - if (sdev->host->hostt->compat_ioctl) { + ret = st_ioctl_common(file, cmd_in, p); + if (ret != -ENOTTY) + return ret; - ret = sdev->host->hostt->compat_ioctl(sdev, cmd_in, (void __user *)arg); - - } - return ret; + return scsi_compat_ioctl(STp->device, cmd_in, p); } #endif diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index 358ea2ecf36b..ab4471f469e6 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c @@ -36,109 +36,11 @@ #include "internal.h" -#ifdef CONFIG_BLOCK -#include -#include -#include -#include -#include -#endif - #include #include #include - -#include - -/* - * simple reversible transform to make our table more evenly - * distributed after sorting. - */ -#define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff) - -#define COMPATIBLE_IOCTL(cmd) XFORM((u32)cmd), -static unsigned int ioctl_pointer[] = { -#ifdef CONFIG_BLOCK -/* Big S */ -COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN) -COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK) -COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK) -COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY) -COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER) -COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND) -COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST) -COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI) -#endif -#ifdef CONFIG_BLOCK -/* SG stuff */ -COMPATIBLE_IOCTL(SG_IO) -COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE) -COMPATIBLE_IOCTL(SG_SET_TIMEOUT) -COMPATIBLE_IOCTL(SG_GET_TIMEOUT) -COMPATIBLE_IOCTL(SG_EMULATED_HOST) -COMPATIBLE_IOCTL(SG_GET_TRANSFORM) -COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE) -COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE) -COMPATIBLE_IOCTL(SG_GET_SCSI_ID) -COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA) -COMPATIBLE_IOCTL(SG_GET_LOW_DMA) -COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID) -COMPATIBLE_IOCTL(SG_GET_PACK_ID) -COMPATIBLE_IOCTL(SG_GET_NUM_WAITING) -COMPATIBLE_IOCTL(SG_SET_DEBUG) -COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE) -COMPATIBLE_IOCTL(SG_GET_COMMAND_Q) -COMPATIBLE_IOCTL(SG_SET_COMMAND_Q) -COMPATIBLE_IOCTL(SG_GET_VERSION_NUM) -COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN) -COMPATIBLE_IOCTL(SG_SCSI_RESET) -COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE) -COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN) -COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN) -#endif -}; - -/* - * Convert common ioctl arguments based on their command number - * - * Please do not add any code in here. Instead, implement - * a compat_ioctl operation in the place that handleѕ the - * ioctl for the native case. - */ -static long do_ioctl_trans(unsigned int cmd, - unsigned long arg, struct file *file) -{ - return -ENOIOCTLCMD; -} - -static int compat_ioctl_check_table(unsigned int xcmd) -{ -#ifdef CONFIG_BLOCK - int i; - const int max = ARRAY_SIZE(ioctl_pointer) - 1; - - BUILD_BUG_ON(max >= (1 << 16)); - - /* guess initial offset into table, assuming a - normalized distribution */ - i = ((xcmd >> 16) * max) >> 16; - - /* do linear search up first, until greater or equal */ - while (ioctl_pointer[i] < xcmd && i < max) - i++; - - /* then do linear search down */ - while (ioctl_pointer[i] > xcmd && i > 0) - i--; - - return ioctl_pointer[i] == xcmd; -#else - return 0; -#endif -} - COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, compat_ulong_t, arg32) { @@ -216,19 +118,9 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, goto out_fput; } - if (!f.file->f_op->unlocked_ioctl) - goto do_ioctl; - break; - } - - if (compat_ioctl_check_table(XFORM(cmd))) - goto found_handler; - - error = do_ioctl_trans(cmd, arg, f.file); - if (error == -ENOIOCTLCMD) error = -ENOTTY; - - goto out_fput; + goto out_fput; + } found_handler: arg = (unsigned long)compat_ptr(arg); @@ -239,23 +131,3 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, out: return error; } - -static int __init init_sys32_ioctl_cmp(const void *p, const void *q) -{ - unsigned int a, b; - a = *(unsigned int *)p; - b = *(unsigned int *)q; - if (a > b) - return 1; - if (a < b) - return -1; - return 0; -} - -static int __init init_sys32_ioctl(void) -{ - sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer), - init_sys32_ioctl_cmp, NULL); - return 0; -} -__initcall(init_sys32_ioctl); From patchwork Wed Dec 11 20:42:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181330 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1046253ile; Wed, 11 Dec 2019 12:49:39 -0800 (PST) X-Google-Smtp-Source: APXvYqyGzY64hbxZd1WrwPTiLPE05EBgOgMzIqH4S6S1t65JLT33E/d1V2JJz6P+wGGQSm2XIxi2 X-Received: by 2002:a05:6830:4a4:: with SMTP id l4mr3975733otd.91.1576097378998; Wed, 11 Dec 2019 12:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097378; cv=none; d=google.com; s=arc-20160816; b=QgmuPqSya3DroJMxFEL5URH5omxUWh+9CCO3pLSG7LniBslkKpvrC9pzrpc2TljWE4 o2JqTPUD355a/qblSzdBlKMYGjjDbjGo22KO9OXPtYOP52EpCDqu4jP00eoxOVBpSzCT SgonR7Oaom1mze8+LDTY7hZCVf8A2vMvXhGlKWvqfyIOMJt6Z7Is15ap5C1m5PmUZFSH 02IyCvqSns4mBxwIyjNstKjQjQngPjuYMP3MpQvZF0wF33cgAnA52R9zw1mPF5+VJOTq BhZJVku6qh8KUd+rd+gLxQMRxTaMALKIhsNI+Ro/frfZzQPJ43yUle+JAnzxbpVm9CEh GkXA== 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=MI3gyflPxmaoHDHBEuYF8mxiI/ZyyNhPvRPfin4Zbtk=; b=GaosGuUp1dsKdTsFKomemLk7nmPqciCSV1X1FKgZ34UQcnWH0jSMOZl0D85/d4QTaT ikk7RXkMIghcNSxfvEAM4bUqPBk9sffO+ze98K7atdf/j9VwK6Gd7/GsLXDzgPttqj5M +vtmCftUYi7HWsGRSjH+UFcS03hC08EOnYpJJvWscc3xzgEX+p++mhHjxaLRGbqnxdxT mmNcVnUTJK9veGx81Wbw/yXAvJcogz2JXfW9R8Ji1yUjfN0Ajw0j+gwPAVIa+LdWtHi7 se2b2VkEi/eUFJR0dcq031QFwq7ReylvzJfiJCcaWTbNMOdyYHBUNGa3ad4WOxvgeUQx icDg== 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 z8si1834403oto.36.2019.12.11.12.49.38; Wed, 11 Dec 2019 12:49:38 -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 S1727466AbfLKUth (ORCPT + 27 others); Wed, 11 Dec 2019 15:49:37 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:34925 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbfLKUtf (ORCPT ); Wed, 11 Dec 2019 15:49:35 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MKsf5-1iQVNa1LfJ-00LCmO; Wed, 11 Dec 2019 21:49:19 +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 , David Howells , "Theodore Ts'o" , "Darrick J. Wong" , linux-fsdevel@vger.kernel.org Subject: [PATCH 16/24] compat_ioctl: move sys_compat_ioctl() to ioctl.c Date: Wed, 11 Dec 2019 21:42:50 +0100 Message-Id: <20191211204306.1207817-17-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:Ttcjs3bklKjAtbzKwLkyQ9fvJEHsZYNVFkShl5ifO6FRmOUyrr3 gCYrhvrhvqv4mlaj0onteSi+IqOGUBJj7QPfX9GV6O2n7cY9/EVp2PBaa5JCidBiWsxbn88 yX1p0Ty1MFO6aynL+E5lj9evWqN8jg8+fhaPvrm3GsDqNSuJYp5HZjfFfNSiNm2ZQ2aroBQ 3rxR/jmm8sw1GfQrxnjlg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:0aiEZj2EOyc=:okEOF1/ZeXe1YiM/rGRtfI jhoeyCCtZd3trf1XPcPkRuNDo7eeM3PeLkllWdgHsvUfJMd8vvEVsOPTf3nyZkR3ZvGX6tD2J mdcNR8atHeSFnmim8ubtInawJon4PetrUjL+swA3ZensR0loFfBgLrn63fPhMfLk47zjVf9Nw 9L8l7Ahv8HfJzmz6fyyOc1tULJfMG7kD19sFU+4WR/j3TwehoOsfy+sUejChDPqgexdzCPqbx uNTl1eYPyRxM5Vq5M+EuH0C+h21KkEL8N4St/0+ktE1pVd20JhD9L3TXgUSgKRXsvPm4IKtpY qdlAwsyErH5snTICdMShdJlrrocYTjTGC1JjREr89NNhq1oT5TfP1Jyw3DlUMMJ6CZfBpqCKb qPYp9NglInkmcX6Wg1avMpztbJsyKoWL5R83llQh1WkT/BmByLjp8+Avz+RkatfysBAkcSqTR jG21BNiRHvexLdaKQGAkeooHbk6LJA8gqEFUUO3wxckiinNqdpwZynH0HkKmS67I4HicGErR3 RK7zudBSQYVb4N+8f4J2WEtXCxQohIzwM94q9EMVdDKM2OBv4WywAyvO0ugnHgV07Ljse0uqI AtLym8e7cr7nhkbZC6ZKwoXiuaqcR+TtQ9VUyCaGzkXmnt64xwRtstuU8a9O7F4g+LTLwoAxW TbWeEMUk0mlkuxkRfA1GXTxpOGNLlWwU+u+haFsc3vEFY/+F7ol2EcKS9/eYUAuUIJ/wFyzIi CSdG6K5jtS9nqBFuF+nt+DhE87QbZcshJXoy3THeNt5+eHP/XPVOkfgp9eyJFkrPdrdMJrZNV tpDrahct0QSssjIAlRem5kQsQ5mEyG3itpbsp/8rDyFK1lLto3jgGhCVWr0KOcK1DyjVsYyWx dgNY6VU1Y/oW2m+2CVpw== 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 --- fs/Makefile | 2 +- fs/compat_ioctl.c | 133 ---------------------------------------------- fs/ioctl.c | 90 +++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 134 deletions(-) delete mode 100644 fs/compat_ioctl.c -- 2.20.0 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 From patchwork Wed Dec 11 20:42:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181331 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1046644ile; Wed, 11 Dec 2019 12:50:02 -0800 (PST) X-Google-Smtp-Source: APXvYqxjJhouTRu4bpoZw70onRwXNo1eyxnkBEP7Z73yOCryCpAyTkVfcIpb9JY1mYrwmN/45TlH X-Received: by 2002:a9d:4d8a:: with SMTP id u10mr4040638otk.232.1576097402004; Wed, 11 Dec 2019 12:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097401; cv=none; d=google.com; s=arc-20160816; b=nr7GhUz4R3JXkeDfsr7YDfBth1F6siiILz0ArndMGiaRGjhZB6CQ6AwgbvGNCXpQQu Za47ne16chxt92SftGEO8GkkeQ2FjMgPFHMyykDPqHWvUSCCRRJbxYDR0oVd+TfszN7p VGU+s1RJ3dCEPcnWc1vxgPWojyaeK4qq41sFzxAIv2CHLhl4tIXXVj+AFw/YUnZy4lsq MnnnVsuXIHjxknVWqir9ZSST9iCXwkNsAn3H0JAxSeuWoiI0o+F9/a/fspKJZBwd4Ako hLXM6XXBQLjau1qeMfxWaIGhgewFBfMah6SRd1emuk7qWtiqIWIe7Hd8I3JD5aihnk2i f/6Q== 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=hw1y70F66VZZ+OgbcT+EfkGDrm7zpzPTpXzlCdUtNGE=; b=dJDZboKNlQRft4Le3tx+e374bcuWa7YkrK4smKY4WoVX06DsqiY8iRc7lwwkrzOEVS 88TZDWY1pRlctXTpCMz60wW9nGm6Lvncj65OnIQH1tSwGnzddvv0qI3XFqtev5OJTYSf 2lM/Pqmwn7B8O4TSc6SQLsOuDFhFIB17yR++qtwOEEy9OScynQM5hFEChD5GJyq6MDgL zUMvyOnE7oN9h3UMFaJZFXSGXcZotauq4EjZBWQWYn5mQQLaYuoOSniicgKTViEhhurg Gb1S0hlACXdvWHYOuURKnawt7zOxUm3sUM5n73pCNOYK8tOGMzGDbnGuH+ZJJBc+kHzV iKaw== 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 g6si1900086otb.231.2019.12.11.12.50.01; Wed, 11 Dec 2019 12:50:01 -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 S1727063AbfLKUuA (ORCPT + 27 others); Wed, 11 Dec 2019 15:50:00 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:56239 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUuA (ORCPT ); Wed, 11 Dec 2019 15:50:00 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M6ltQ-1ieZtt2IWc-008KbD; Wed, 11 Dec 2019 21:49:47 +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 , "Darrick J. Wong" , David Howells , Andreas Gruenbacher , linux-fsdevel@vger.kernel.org Subject: [PATCH 17/24] compat_ioctl: simplify the implementation Date: Wed, 11 Dec 2019 21:42:51 +0100 Message-Id: <20191211204306.1207817-18-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:2QOi0GRoSVZvZP81pnp07X8GxQRVp+KXF3Fz3h9jWGug/tFNzWe eDBggFxHoy+XvsXjHq3eL1Aatz78Tm5Hjh/sJepjoAku0St3n17qTGLw/PS1mpTt2mIYqaS lP0IwFb0/eUV33BmjU9CAaoVz7/FmpT7IXgZ8+QAvbjSJGpnYsBecQNJC6oZ3rEER5C3Rav /YihCQHK++/tIqqhmBrZQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:fb5mcQzzps8=:3eiJj/7I/GKqwakzu/gyG0 5kE+7lRJgrfdjWWmCvGlTVKMQc2hIEMtkLgwGrcHnN3AAHjepjY5CdFB3uY1qeI3kln9xDO/L prXoa5dSWea3QubTH5Kg+/xt6XcO7t1z0gnGeQEhDDPrLCJ/N+dqzQtqGlj96PnZthA8BeeBh Rl/x+iPP/mVdMaaAWwJ79R6cCXu2T43O94eJYxOqeZLarXPYxkcpTTn21B+JKrvGSMRZNfjfT /UVhmgLKb5ZHBlNkioXB/fXhGRDynOPI47IJ2E898X7ZP4D2Q/ekR65TjBdslNhAKuHpva5qL kUbdPFcL+GWQgb3gHD7LIQRveobBsiWxDuqWoUpxapAemxA5SuqxCejDCJQVFph7kJQCxUGIE nNpRy0638d32lN9z4I8ExCDUv3rWD/3nvr2BnaAn4+MLInFSKyP82gyRXG71Jj+8CyVRUWAff zpn8NNasY54HXacUQr+erl41+GXFqqH4MfILQg6jb+HTVcWXsgyr02upfo0m38AwD7uloWJbk oqySsKgILaUg/7gdL7PtEHC9E9RFHACYyM2oxjr+CEEudpuvGHm9Rmx02yBM0DhyioNsile+G YxufqG77bJfpZ+Z0nFrozUF0Es00F4mUzzrlum3ncmSKFy6WFDFveK18pHxWVU7b12Bq/tcbL 1Mla/RhJmCmR73qY7LOrmY9cbCm1fGrRHPZWW7Ir+TcmhqgOGKnF+4v6QE5L15VqOjBxPjk2C uC89pNXMNf0sdGap3aZ/w5Kx5re9Kqc1D92mLYW6aKrt4pZ4sQ+qNaz4c3Kp/hOOlOUnO3LxH r9FYNqX87IOOakW7pOMJO/qtVUic+Lgs7rp+MzMx1JJbdzQY6W0DKJ4U+d1FfnPGEycgl5W7z gCkXdXryG/Xf2kvwsg0g== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that both native and compat ioctl syscalls are in the same file, a couple of simplifications can be made, bringing the implementation closer together: - do_vfs_ioctl(), ioctl_preallocate(), and compat_ioctl_preallocate() can become static, allowing the compiler to optimize better - slightly update the coding style for consistency between the functions. - rather than listing each command in two switch statements for the compat case, just call a single function that has all the common commands. As a side-effect, FS_IOC_RESVSP/FS_IOC_RESVSP64 are now available to x86 compat tasks, along with FS_IOC_RESVSP_32/FS_IOC_RESVSP64_32. This is harmless for i386 emulation, and can be considered a bugfix for x32 emulation, which never supported these in the past. Signed-off-by: Arnd Bergmann --- fs/internal.h | 6 -- fs/ioctl.c | 157 +++++++++++++++++------------------------ include/linux/falloc.h | 2 - include/linux/fs.h | 4 -- 4 files changed, 64 insertions(+), 105 deletions(-) -- 2.20.0 diff --git a/fs/internal.h b/fs/internal.h index 4a7da1df573d..d46247850ad7 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -180,11 +180,5 @@ extern void mnt_pin_kill(struct mount *m); */ extern const struct dentry_operations ns_dentry_operations; -/* - * fs/ioctl.c - */ -extern int do_vfs_ioctl(struct file *file, unsigned int fd, unsigned int cmd, - unsigned long arg); - /* direct-io.c: */ int sb_init_dio_done_wq(struct super_block *sb); diff --git a/fs/ioctl.c b/fs/ioctl.c index 8f22f7817edb..7c9a5df5a597 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -467,7 +467,7 @@ EXPORT_SYMBOL(generic_block_fiemap); * Only the l_start, l_len and l_whence fields of the 'struct space_resv' * are used here, rest are ignored. */ -int ioctl_preallocate(struct file *filp, int mode, void __user *argp) +static int ioctl_preallocate(struct file *filp, int mode, void __user *argp) { struct inode *inode = file_inode(filp); struct space_resv sr; @@ -495,8 +495,8 @@ int ioctl_preallocate(struct file *filp, int mode, void __user *argp) /* on ia32 l_start is on a 32-bit boundary */ #if defined CONFIG_COMPAT && defined(CONFIG_X86_64) /* just account for different alignment */ -int compat_ioctl_preallocate(struct file *file, int mode, - struct space_resv_32 __user *argp) +static int compat_ioctl_preallocate(struct file *file, int mode, + struct space_resv_32 __user *argp) { struct inode *inode = file_inode(file); struct space_resv_32 sr; @@ -521,11 +521,9 @@ int compat_ioctl_preallocate(struct file *file, int mode, } #endif -static int file_ioctl(struct file *filp, unsigned int cmd, - unsigned long arg) +static int file_ioctl(struct file *filp, unsigned int cmd, int __user *p) { struct inode *inode = file_inode(filp); - int __user *p = (int __user *)arg; switch (cmd) { case FIBMAP: @@ -542,7 +540,7 @@ static int file_ioctl(struct file *filp, unsigned int cmd, return ioctl_preallocate(filp, FALLOC_FL_ZERO_RANGE, p); } - return vfs_ioctl(filp, cmd, arg); + return -ENOIOCTLCMD; } static int ioctl_fionbio(struct file *filp, int __user *argp) @@ -661,53 +659,48 @@ static int ioctl_file_dedupe_range(struct file *file, } /* - * When you add any new common ioctls to the switches above and below - * please update compat_sys_ioctl() too. - * * do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d. * It's just a simple helper for sys_ioctl and compat_sys_ioctl. + * + * When you add any new common ioctls to the switches above and below, + * please ensure they have compatible arguments in compat mode. */ -int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, - unsigned long arg) +static int do_vfs_ioctl(struct file *filp, unsigned int fd, + unsigned int cmd, unsigned long arg) { - int error = 0; void __user *argp = (void __user *)arg; struct inode *inode = file_inode(filp); switch (cmd) { case FIOCLEX: set_close_on_exec(fd, 1); - break; + return 0; case FIONCLEX: set_close_on_exec(fd, 0); - break; + return 0; case FIONBIO: - error = ioctl_fionbio(filp, argp); - break; + return ioctl_fionbio(filp, argp); case FIOASYNC: - error = ioctl_fioasync(fd, filp, argp); - break; + return ioctl_fioasync(fd, filp, argp); case FIOQSIZE: if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) { loff_t res = inode_get_bytes(inode); - error = copy_to_user(argp, &res, sizeof(res)) ? - -EFAULT : 0; - } else - error = -ENOTTY; - break; + return copy_to_user(argp, &res, sizeof(res)) ? + -EFAULT : 0; + } + + return -ENOTTY; case FIFREEZE: - error = ioctl_fsfreeze(filp); - break; + return ioctl_fsfreeze(filp); case FITHAW: - error = ioctl_fsthaw(filp); - break; + return ioctl_fsthaw(filp); case FS_IOC_FIEMAP: return ioctl_fiemap(filp, argp); @@ -716,6 +709,7 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, /* anon_bdev filesystems may not have a block size */ if (!inode->i_sb->s_blocksize) return -EINVAL; + return put_user(inode->i_sb->s_blocksize, (int __user *)argp); case FICLONE: @@ -729,24 +723,30 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, default: if (S_ISREG(inode->i_mode)) - error = file_ioctl(filp, cmd, arg); - else - error = vfs_ioctl(filp, cmd, arg); + return file_ioctl(filp, cmd, argp); break; } - return error; + + return -ENOIOCTLCMD; } int ksys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { - int error; struct fd f = fdget(fd); + int error; if (!f.file) return -EBADF; + error = security_file_ioctl(f.file, cmd, arg); - if (!error) - error = do_vfs_ioctl(f.file, fd, cmd, arg); + if (error) + goto out; + + error = do_vfs_ioctl(f.file, fd, cmd, arg); + if (error == -ENOIOCTLCMD) + error = vfs_ioctl(f.file, cmd, arg); + +out: fdput(f); return error; } @@ -790,92 +790,63 @@ long compat_ptr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) EXPORT_SYMBOL(compat_ptr_ioctl); COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, - compat_ulong_t, arg32) + compat_ulong_t, arg) { - unsigned long arg = arg32; struct fd f = fdget(fd); - int error = -EBADF; + int error; + if (!f.file) - goto out; + return -EBADF; /* RED-PEN how should LSM module know it's handling 32bit? */ error = security_file_ioctl(f.file, cmd, arg); if (error) - goto out_fput; + goto out; switch (cmd) { - /* these are never seen by ->ioctl(), no argument or int argument */ - case FIOCLEX: - case FIONCLEX: - case FIFREEZE: - case FITHAW: + /* FICLONE takes an int argument, so don't use compat_ptr() */ 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 */ + error = ioctl_file_clone(f.file, arg, 0, 0, 0); + break; + #if defined(CONFIG_X86_64) + /* these get messy on amd64 due to alignment differences */ case FS_IOC_RESVSP_32: case FS_IOC_RESVSP64_32: error = compat_ioctl_preallocate(f.file, 0, compat_ptr(arg)); - goto out_fput; + break; 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; + break; 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; + break; #endif + /* + * everything else in do_vfs_ioctl() takes either a compatible + * pointer argument or no argument -- call it with a modified + * argument. + */ default: - if (f.file->f_op->compat_ioctl) { + error = do_vfs_ioctl(f.file, fd, cmd, + (unsigned long)compat_ptr(arg)); + if (error != -ENOIOCTLCMD) + break; + + 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; + if (error == -ENOIOCTLCMD) + error = -ENOTTY; + break; } - found_handler: - arg = (unsigned long)compat_ptr(arg); - do_ioctl: - error = do_vfs_ioctl(f.file, fd, cmd, arg); - out_fput: - fdput(f); out: + fdput(f); + return error; } #endif diff --git a/include/linux/falloc.h b/include/linux/falloc.h index 8bf3d79f3e82..f3f0b97b1675 100644 --- a/include/linux/falloc.h +++ b/include/linux/falloc.h @@ -51,8 +51,6 @@ struct space_resv_32 { #define FS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct space_resv_32) #define FS_IOC_ZERO_RANGE_32 _IOW ('X', 57, struct space_resv_32) -int compat_ioctl_preallocate(struct file *, int, struct space_resv_32 __user *); - #endif #endif /* _FALLOC_H_ */ diff --git a/include/linux/fs.h b/include/linux/fs.h index 98e0349adb52..daf570bca42a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2552,10 +2552,6 @@ extern int finish_open(struct file *file, struct dentry *dentry, int (*open)(struct inode *, struct file *)); extern int finish_no_open(struct file *file, struct dentry *dentry); -/* fs/ioctl.c */ - -extern int ioctl_preallocate(struct file *filp, int mode, void __user *argp); - /* fs/dcache.c */ extern void __init vfs_caches_init_early(void); extern void __init vfs_caches_init(void); From patchwork Wed Dec 11 20:42:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181333 Delivered-To: patch@linaro.org Received: by 2002:a92:5b50:0:0:0:0:0 with SMTP id p77csp1041613ilb; Wed, 11 Dec 2019 12:50:44 -0800 (PST) X-Google-Smtp-Source: APXvYqw842IxgtC+zOiqvmWIQvc0KQLLn9EOlj5UdwIfoQ2QBpRB+20D9qqdWR8ofr4TrX09SER4 X-Received: by 2002:aca:5117:: with SMTP id f23mr4145733oib.50.1576097444433; Wed, 11 Dec 2019 12:50:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097444; cv=none; d=google.com; s=arc-20160816; b=MR/JRSGOO+E8iw8+3Q7mKKhk+StlP9Y+weG/MItLTlbHKfRdVtWA7Eu4xQrjGikFUx I0jpdGAsBW7A9m/X8jWJ9DbSJEF3QHXLMX4fEHuMsBGbDML1lXiAJuGGxmDXN4gloQ1S vtB6zTNzyyjp9ofXlj7PDHD+Lfvjc3neclyK4FkHCoT7zcXwxNDKPOG93n8LEos7MhPi xCw5Vwc1MqKY30bm8ng1QrqhnWYgMDLteNHsjEayG0tTwjzbFIT6+HZ6oWT5zglDkWQY s9XswLejoKPw0u9jkSsWNSP/IPRDvYeeAmeXJ5pbttAWlV5SNl+QKykYd8M0a/vxLe8h 5Osw== 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=KNYX6SmnxcHU+EB4bOKJKMFcpH26A767qXp5FzAXjow=; b=hOlU6tml62vk6KuGFE7m9sERQsVM8i8e8951EgSpWGZTg7pz6LU+brJ4QqKLc5lzsT zI1KukIww1N9/GtjZRkaYWi0OlCVjr4CpdwPoahqD0H6DNvNVY8Z1lSIigPU4QZ0QR5j /WTeO8ECFo3Nmt3d0uwRb6SYcVHSFmrYmypxnXP4yZSR+KPEiZDKVkDreccDzOxYkCmh mCOU54Gaspif+L4Z25KzkktzTq1gB1an6Ja5L/F92mda10lI7bRHTu2JRFk6HrIO4FIv vlgERt7WejS3YWo54MXMpr1EdbhXKGqBMFqHWa1J1LZ2he14aYE8FF2uZrReLrZKV/8D +1Hg== 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 m85si1856815oig.158.2019.12.11.12.50.44; Wed, 11 Dec 2019 12:50:44 -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 S1727210AbfLKUun (ORCPT + 27 others); Wed, 11 Dec 2019 15:50:43 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:56963 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUum (ORCPT ); Wed, 11 Dec 2019 15:50:42 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MLz7f-1iNCZv1Qiv-00HtOe; Wed, 11 Dec 2019 21:50:18 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Tim Waugh , Borislav Petkov , "David S. Miller" Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Hannes Reinecke , linux-block@vger.kernel.org, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 18/24] compat_ioctl: move cdrom commands into cdrom.c Date: Wed, 11 Dec 2019 21:42:52 +0100 Message-Id: <20191211204306.1207817-19-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:YCC/4Cjm3aDYhGrVvv4vw+/A3W06RkJIX2vxsyaBWOwABLnpSY0 RA84rLENvr6GZ+SZrzgiGodaxTM+m2zHv3jC9nZ8PvrEgP8TU/0gCkO5D18uiAal4+0hFFX jiegrBrTxABAqlc+aLlM3EscQFWgbVf0ARY6eFMRjNjOwndlfTuEaI40MMv7h4v9UeeEbxl VP6Uq+ZvyoT7YYcZT9kjw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:9xEE4g5+y1E=:Hp3/3rN4TA2XdTQ/ZzXAp4 glzcY9TOBSffEXTuRYc+dcmHJcrbZ1Ab3/tuAZkfYu333ipdoJTFtSo6lNpNhw4crqPOdVqLN j9YyG25B9AFvowzc7CnNFLuuqoLimhcP6XpF1yHYBHGh34IxMThn6VFzdR4l4Lj2zPKRVhKCJ E6L5QZwADcGrpq1Eu6dULOLqU+3oSDvKHt7UtiqrTqi0edht+RxPSyuy0nF/EkBdC+5fJTech U/Snv0uPIaKE5ctkJC+gqh3DhM85vd0t9PGFy4sHDKTQ88N/QPnkQ4QoFBJrCXhqeir6Rrrn+ L+2DLl4DYXaFjcQlPqiCtgYajpR+LyzAszZFeETOEpCXJo9uozCMFOfvyfksQiXPwtDn1Q5v5 l3zsAgiBHMMR23H6Uzwtn8SuWQIUMlG0t65UDQIHn76EMu6r0ivfx0cUl8arB23+ejKyMJ6XR Y1MdzkFHwTGMi+MWNVyRY7yBkVPza6h6wBE0pfZitdd5ELziQbA3T9rgS1p51eZjee7DDQ2yT szzl3/5Nwbjtl+fKDwLeQM2uFkYNM9WzpWLsZ2c1jYYyxc32w7sKepB3Fp5V0vcqXOEZ/pSNT xnBnq0oxtC9mG+cLRI8JJIBoLbC446PHO/nRGNPYeY6LqswkFVXZE8Uli3sMNgocJEaVlBvdv jY71lV/obi6/1Gk6bhSftJ1ztMGw4ePxgEnfVBDoBN/IA4nqbwy7QXtjeUuOPqlg9iPlqtWvW BFruKHq0q3mTkhQyuAnYIFqeKBPLawr7DdtOXL/Br/Bq/JqZIdyLWjxKCRtaO+zhINgjy/W/O 8HA4p80/KqA6pkRfIkbE2l7kclxzRZMo7EoNUuEaZuD+1w1OMvLgmE+5jejt0zE1D0ehy166M 1XyCth261VtdB0xAEmow== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no need for the special cases for the cdrom ioctls any more now, so make sure that each cdrom driver has a .compat_ioctl() callback and calls cdrom_compat_ioctl() directly there. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 45 -------------------------------------- drivers/block/paride/pcd.c | 3 +++ drivers/cdrom/gdrom.c | 3 +++ drivers/ide/ide-cd.c | 36 ++++++++++++++++++++++++++++++ drivers/scsi/sr.c | 10 +++------ 5 files changed, 45 insertions(+), 52 deletions(-) -- 2.20.0 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index cf136bc2c9fc..7cb534d6e767 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -159,42 +159,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case HDIO_DRIVE_CMD: /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ case 0x330: - /* CDROM stuff */ - case CDROMPAUSE: - case CDROMRESUME: - case CDROMPLAYMSF: - case CDROMPLAYTRKIND: - case CDROMREADTOCHDR: - case CDROMREADTOCENTRY: - case CDROMSTOP: - case CDROMSTART: - case CDROMEJECT: - case CDROMVOLCTRL: - case CDROMSUBCHNL: - case CDROMMULTISESSION: - case CDROM_GET_MCN: - case CDROMRESET: - case CDROMVOLREAD: - case CDROMSEEK: - case CDROMPLAYBLK: - case CDROMCLOSETRAY: - case CDROM_DISC_STATUS: - case CDROM_CHANGER_NSLOTS: - case CDROM_GET_CAPABILITY: - case CDROM_SEND_PACKET: - /* Ignore cdrom.h about these next 5 ioctls, they absolutely do - * not take a struct cdrom_read, instead they take a struct cdrom_msf - * which is compatible. - */ - case CDROMREADMODE2: - case CDROMREADMODE1: - case CDROMREADRAW: - case CDROMREADCOOKED: - case CDROMREADALL: - /* DVD ioctls */ - case DVD_READ_STRUCT: - case DVD_WRITE_STRUCT: - case DVD_AUTH: arg = (unsigned long)compat_ptr(arg); /* These intepret arg as an unsigned long, not as a pointer, * so we must not do compat_ptr() conversion. */ @@ -210,15 +174,6 @@ static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, case HDIO_SET_ACOUSTIC: case HDIO_SET_BUSSTATE: case HDIO_SET_ADDRESS: - case CDROMEJECT_SW: - case CDROM_SET_OPTIONS: - case CDROM_CLEAR_OPTIONS: - case CDROM_SELECT_SPEED: - case CDROM_SELECT_DISC: - case CDROM_MEDIA_CHANGED: - case CDROM_DRIVE_STATUS: - case CDROM_LOCKDOOR: - case CDROM_DEBUG: break; default: /* unknown ioctl number */ diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c index 636bfea2de6f..117cfc8cd05a 100644 --- a/drivers/block/paride/pcd.c +++ b/drivers/block/paride/pcd.c @@ -275,6 +275,9 @@ static const struct block_device_operations pcd_bdops = { .open = pcd_block_open, .release = pcd_block_release, .ioctl = pcd_block_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = blkdev_compat_ptr_ioctl, +#endif .check_events = pcd_block_check_events, }; diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c index 5b21dc421c94..886b2638c730 100644 --- a/drivers/cdrom/gdrom.c +++ b/drivers/cdrom/gdrom.c @@ -518,6 +518,9 @@ static const struct block_device_operations gdrom_bdops = { .release = gdrom_bdops_release, .check_events = gdrom_bdops_check_events, .ioctl = gdrom_bdops_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = blkdev_compat_ptr_ioctl, +#endif }; static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id) diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index 9d117936bee1..2de6e8ace957 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -25,6 +25,7 @@ #define IDECD_VERSION "5.00" +#include #include #include #include @@ -1710,6 +1711,38 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode, return ret; } +#ifdef CONFIG_COMPAT +static int idecd_locked_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info); + int err; + + switch (cmd) { + case CDROMSETSPINDOWN: + return idecd_set_spindown(&info->devinfo, arg); + case CDROMGETSPINDOWN: + return idecd_get_spindown(&info->devinfo, arg); + default: + break; + } + + return cdrom_ioctl(&info->devinfo, bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); +} + +static int idecd_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + int ret; + + mutex_lock(&ide_cd_mutex); + ret = idecd_locked_compat_ioctl(bdev, mode, cmd, arg); + mutex_unlock(&ide_cd_mutex); + + return ret; +} +#endif static unsigned int idecd_check_events(struct gendisk *disk, unsigned int clearing) @@ -1732,6 +1765,9 @@ static const struct block_device_operations idecd_ops = { .open = idecd_open, .release = idecd_release, .ioctl = idecd_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = idecd_compat_ioctl, +#endif .check_events = idecd_check_events, .revalidate_disk = idecd_revalidate_disk }; diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 6033a886c42c..0fbb8fe6e521 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -628,13 +628,9 @@ static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsign goto put; } - /* - * CDROM ioctls are handled in the block layer, but - * do the scsi blk ioctls here. - */ - ret = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); - if (ret != -ENOTTY) - return ret; + ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, (unsigned long)argp); + if (ret != -ENOSYS) + goto put; ret = scsi_compat_ioctl(sdev, cmd, argp); From patchwork Wed Dec 11 20:42:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181334 Delivered-To: patch@linaro.org Received: by 2002:a92:5b50:0:0:0:0:0 with SMTP id p77csp1042756ilb; Wed, 11 Dec 2019 12:51:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyWcCaHSEAcyK/EANjPOd+0NtrbtP2J+8QhdzPIQ4jc2FN+E+v+mHMyF1as6fobfa4QsvPQ X-Received: by 2002:aca:ec45:: with SMTP id k66mr4345662oih.179.1576097511877; Wed, 11 Dec 2019 12:51:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097511; cv=none; d=google.com; s=arc-20160816; b=uyJyDJvwyD6bI9NfC2/NdNVn5ue/8szkJowpzQmW5ZUQ+TjoyWtwV4XYnasyZTGiyq 3EpFOlMk9Rf4uJauYf3H8XyPe1v3IKP2WelWxypCKo8BXN+l6dYkJ8PZHomNLJ0ZCzbZ FnNaQYfGVbMtwo7/EQQeFu+iFK97JbvHTpjqv4y+HDra8n+ReE5rWtiYnn1i4RwI4w5b CFlJ6hVnzkVLXasQlhZN85kmiUOaEJN9oOgp9mHUYG3FczmfW2U4XibUR12vFrQArulY 1ZAfATd90k9QxN/O4559dOwl0l7nd3c3xykP0VHHlahre9PJx2PWQYHIHvoLd24k4Y0A eQRA== 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=I2iubamz4SQwC/dne1lcARk5QXyzvIf7Z+kXRy3axZM=; b=rAJ7iWU4+mmoF0QJlj2reh6U1hAaXFq7LOPhGixFXzRvFpcphiPiBN+xqTntS2r8Lo 19dIwjtYQOju2rJGLy2ty8/LJm6w2b6Yghakr8zcUdOR82DVuqY/5DSTByZc7qVn5715 nP4UQyk3LQUtb/UECi0GlQPi59N1I/JrUR880CzjK3CVN9sEk0Tnec9rUz8qyI55iN1/ ehJBnfunK/avUAEcNYP1Bzl4Ig+00ICdJyxHZL8R5Fm5UfJIpeUuDHulekxU1ya3R/e5 AbzoplmsbBHesDMj5R0Am17CaUjq/3O2BNXsGGWrD4nio8F1fNOzyXNNJbi3e53/ZqDd Rc9A== 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 w127si1911884oib.188.2019.12.11.12.51.51; Wed, 11 Dec 2019 12:51:51 -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 S1726928AbfLKUvu (ORCPT + 27 others); Wed, 11 Dec 2019 15:51:50 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:45853 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbfLKUvt (ORCPT ); Wed, 11 Dec 2019 15:51:49 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N4R0a-1hhIFG2CJi-011RMZ; Wed, 11 Dec 2019 21:51:32 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , John Garry , Brian King , Intel SCU Linux support , Artur Paszkiewicz , Jack Wang Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Hannes Reinecke , linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 19/24] compat_ioctl: scsi: handle HDIO commands from drivers Date: Wed, 11 Dec 2019 21:42:53 +0100 Message-Id: <20191211204306.1207817-20-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:VLpQgUZjxMkjb5YR1h3oCFegmEv0coXfNiTrkHDQbxAgyNP2E6r MhXP2DgggU3oHmH6OM02Nk4EdkpfukoiVoudcNxW0gfqQQUukVExLJ7qPeUaC3clym7QDC0 nxat+UUyfjMPDoRwh/vX8d4K73OhBvOqGwqCeFzy/lYeu2qwmuA9trb2+GROu1JTOt3YvxB MLF8IJwkJNZW0Nm7LIFpw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:Px569MvALqc=:ysQLWqqciSyF15brchKM3I AbgC7DJI/etNcD+NoccD2d9MqjmlCKi5QZwvOSVw3d5aEnupRdMueWRTKTtD0L/Gr8TRj3Y72 iSBCbkqGkDo9MTm1JFmOcpGjOGvXfaysP0YDObPqS7ydxwRCxsfpE7hTcmwswcvBl5iQfrjhu eKLPypYh9ZvSyzYcB3mZkDpPngBv6/lCuW9PX9VMtpb5aoj0T4k9M1lqHBVTdiOUMc5CvcAjR mcUHXeEJvTsU03QjrFBk+VT3A0Hlsaw9UvkIYfK74sBafee67riQ0pcmXlw+HYzF4gDuoDtZI Jt6AhxBwKxun6NVYFVjTkJlsIDsEm6bBQU8ZH1267i8g7SgZucFxe7Ix8cfgdh9JZS0m0Gxdc mQsnRZPAxsSS64lpve3Is6NbsTN9AiORby8p0ywPyvZWYFS0DJoV2gbbx9Fv7lkUa3DiKNung X9ASeZFO3SP2nNFfwTpE4M5dy04rABfp+TP7ymdgx6Npw3jvzEYMJRbaFqdcgI4SfO6BrgbZR uF7gIhgrSKYmunLQ7S3JU+NbclFRBThXEPe81WzG3q/o6LR6RchCoSiQtqCgpDHQvK6R+W72D 8htJh+GZOeT7VW3gyPgN6Pns/RBZuCRJvFsbVBKI5oNXNZyt5+nmlGk6CG4lTm5jCzCrG8b5n T9iHACHK0zsazU8SackkzxZkdJXhU5jrxwL2CQqeMlcIit9bWKIYIfcBjcnGEhjBKaosW7PFS PvI7Vp1Bm6nCKKDOQMMg3wWYXZcu1ljfBPF+W+1becYC/U0WLm6L91VeAQv6GFQ6I+HopLzkJ TTnWy3eGhD4EZBkg/3QdrcNxVcufdDAKajSMPDmwzy6Vo8bVL8QzKfKQFu/AhtH0qHPyJE7vZ KDXp5oroB2gZemEXwXBQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ata_sas_scsi_ioctl() function implements a number of HDIO_* commands for SCSI devices, it is used by all libata drivers as well as a few drivers that support SAS attached SATA drives. The only command that is not safe for compat ioctls here is HDIO_GET_32BIT. Change the implementation to check for in_compat_syscall() in order to do both cases correctly, and change all callers to use it as both native and compat callback pointers, including the indirect callers through sas_ioctl and ata_scsi_ioctl. Signed-off-by: Arnd Bergmann --- drivers/ata/libata-scsi.c | 9 +++++++++ drivers/scsi/aic94xx/aic94xx_init.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 3 +++ drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 +++ drivers/scsi/ipr.c | 3 +++ drivers/scsi/isci/init.c | 3 +++ drivers/scsi/mvsas/mv_init.c | 3 +++ drivers/scsi/pm8001/pm8001_init.c | 3 +++ include/linux/libata.h | 6 ++++++ 10 files changed, 39 insertions(+) -- 2.20.0 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 58e09ffe8b9c..eb2eb599e602 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -17,6 +17,7 @@ * - http://www.t13.org/ */ +#include #include #include #include @@ -761,6 +762,10 @@ static int ata_ioc32(struct ata_port *ap) return 0; } +/* + * This handles both native and compat commands, so anything added + * here must have a compatible argument, or check in_compat_syscall() + */ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, unsigned int cmd, void __user *arg) { @@ -773,6 +778,10 @@ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, spin_lock_irqsave(ap->lock, flags); val = ata_ioc32(ap); spin_unlock_irqrestore(ap->lock, flags); +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) + return put_user(val, (compat_ulong_t __user *)arg); +#endif return put_user(val, (unsigned long __user *)arg); case HDIO_SET_32BIT: diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index f5781e31f57c..d022407e5645 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c @@ -54,6 +54,9 @@ static struct scsi_host_template aic94xx_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .track_queue_depth = 1, }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c index 3af53cc42bd6..fa25766502a2 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c @@ -1772,6 +1772,9 @@ static struct scsi_host_template sht_v1_hw = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = host_attrs_v1_hw, .host_reset = hisi_sas_host_reset, }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 61b1e2693b08..545eaff5f3ee 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -3551,6 +3551,9 @@ static struct scsi_host_template sht_v2_hw = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = host_attrs_v2_hw, .host_reset = hisi_sas_host_reset, }; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index bf5d5f138437..fa05e612d85a 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -3075,6 +3075,9 @@ static struct scsi_host_template sht_v3_hw = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = host_attrs_v3_hw, .tag_alloc_policy = BLK_TAG_ALLOC_RR, .host_reset = hisi_sas_host_reset, diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c index 079c04bc448a..ae45cbe98ae2 100644 --- a/drivers/scsi/ipr.c +++ b/drivers/scsi/ipr.c @@ -6727,6 +6727,9 @@ static struct scsi_host_template driver_template = { .name = "IPR", .info = ipr_ioa_info, .ioctl = ipr_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ipr_ioctl, +#endif .queuecommand = ipr_queuecommand, .eh_abort_handler = ipr_eh_abort, .eh_device_reset_handler = ipr_eh_dev_reset, diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c index 1727d0c71b12..b48aac8dfcb8 100644 --- a/drivers/scsi/isci/init.c +++ b/drivers/scsi/isci/init.c @@ -168,6 +168,9 @@ static struct scsi_host_template isci_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = isci_host_attrs, .track_queue_depth = 1, }; diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c index da719b0694dc..7af9173c4925 100644 --- a/drivers/scsi/mvsas/mv_init.c +++ b/drivers/scsi/mvsas/mv_init.c @@ -47,6 +47,9 @@ static struct scsi_host_template mvs_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = mvst_host_attrs, .track_queue_depth = 1, }; diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c index ff618ad80ebd..3c6076e4c6d2 100644 --- a/drivers/scsi/pm8001/pm8001_init.c +++ b/drivers/scsi/pm8001/pm8001_init.c @@ -101,6 +101,9 @@ static struct scsi_host_template pm8001_sht = { .eh_target_reset_handler = sas_eh_target_reset_handler, .target_destroy = sas_target_destroy, .ioctl = sas_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = sas_ioctl, +#endif .shost_attrs = pm8001_host_attrs, .track_queue_depth = 1, }; diff --git a/include/linux/libata.h b/include/linux/libata.h index d3bbfddf616a..e68d05febe5a 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1109,6 +1109,11 @@ extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_op extern int ata_scsi_detect(struct scsi_host_template *sht); extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd, void __user *arg); +#ifdef CONFIG_COMPAT +#define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl, +#else +#define ATA_SCSI_COMPAT_IOCTL /* empty */ +#endif extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd); extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev, unsigned int cmd, void __user *arg); @@ -1340,6 +1345,7 @@ extern struct device_attribute *ata_common_sdev_attrs[]; .module = THIS_MODULE, \ .name = drv_name, \ .ioctl = ata_scsi_ioctl, \ + ATA_SCSI_COMPAT_IOCTL \ .queuecommand = ata_scsi_queuecmd, \ .can_queue = ATA_DEF_QUEUE, \ .tag_alloc_policy = BLK_TAG_ALLOC_RR, \ From patchwork Wed Dec 11 20:42:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181339 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1364ile; Wed, 11 Dec 2019 12:53:41 -0800 (PST) X-Google-Smtp-Source: APXvYqygzjRs3ODRv3lnLUmUxr0v4294fwWWtlaUiWS+yMZd1xbATlTgzL29DrnQ4MNnc1TOqsDX X-Received: by 2002:a9d:480c:: with SMTP id c12mr4142365otf.255.1576097621801; Wed, 11 Dec 2019 12:53:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097621; cv=none; d=google.com; s=arc-20160816; b=n3hh2/Wp8iAJweLXJGt9P8NrR2pO53CoPm4twAVnwXvxe6eDYxZ8eeXn2lLv68AxvP JqiwMC8NOfhPbQT4swin9ibXvdhW2ZVUCLC1cO1cqGJs1SWpG2vVCsju30gdAkdUHKt7 P0ughBRq80lFZMAgUgQdFiN33F3KHtHuU4KKDa/k3iAlovKpmStsP0KWuxuQwuaHktyg zdHpK+9RfwQJdQspOD5p90kCK8RIe0LNPY+cj4GBtsgKasZgn+ndrBClly+2l3DLDzk6 CqRSa/wRZeGHVgmAIpy8sZf3F94ooKhLsh4PPnOxZkrW61C8gjYolLYuUsl28EAhLUxP 349w== 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=RsneD0fiGq0gxpCDkNWhD1A5+yOGCvnpQ0eHyOwbg38=; b=JX1xoVXxAd+doRtXSBXwWtXG3BKxXuR2EL9dpOVFsZcXRis4fi8wnMvcTaBeRY/QJ/ NGXMB6yqv8deJgnWQlQlI93lS9cdbSsnexrJLFCPK04GDb9N495jWDIY/dvj30hCl4o9 sir9sfSGj4xsnYNUBdRts+pdcB4QYkWdMB2XI2oHltmpWuHxKvtJ6xHdJMo6tkSjYYo/ 6ek1vilrcwc1KkexFSOVO1GVrzNst81zpBvYsiTLtckpjqosCR2tYY+y1q2n9NRhm0Bm ECYqxFqvlagRSB32rCgIXu4Ds1H6XnJ0kZgqwkGHK5yDdYD95CCkCCIIB+Iwb17HCbAl CwFA== 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 l14si1847192otk.225.2019.12.11.12.53.41; Wed, 11 Dec 2019 12:53:41 -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 S1727170AbfLKUxk (ORCPT + 27 others); Wed, 11 Dec 2019 15:53:40 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:48923 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbfLKUxk (ORCPT ); Wed, 11 Dec 2019 15:53:40 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MUGqT-1iEz5s0XzP-00RH4A; Wed, 11 Dec 2019 21:52:03 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Borislav Petkov , "David S. Miller" Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Hannes Reinecke , Heiko Carstens , linux-block@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH 20/24] compat_ioctl: move HDIO ioctl handling into drivers/ide Date: Wed, 11 Dec 2019 21:42:54 +0100 Message-Id: <20191211204306.1207817-21-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:WqFkragwamlquVD0w4XYqhcIWXTSfEm2ryUKFK8u+208jHdn86k pOxQ/44+skwkscooobamLqYROzjiyDHmhR7vd7mZsDkdahZFFDTypnjyg/Hdp8tBpAR6T6t BG5ICdH2nzWjz0M5aEYDqPXUJycrPXfLGPpgxHV+DfwvgdtlxeAmHPywiBQZ3TMIxNX5TLz YgsS8Zzbr8SkrSCkHWbKQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:hXVkbih942Q=:6QoC8VGHeNYu3jkFNSWBjN Bsgw6GAWOhVxTu0RrIuR52HnpgA7zCpo4k6rUZ/Ogwet5Q1aK3+ymqu8O2ZORhCOS5IxxCq6Q avF0hh61iAVZgSDinHGfpDrdC3HPuGf1j+0QDyI26R+r9JpawVfRAK0hdOhOTDqCA62TYjvtt q6wWAO7PwZTQY7UzLdAavR34PTGVI4Gv0s36ziwloXx8/Q9CYunu8oc7pUEoJCtTrloeCy+gZ 0Rl/8jwIWskh1FutmymHQoNzK3jjV0akRImu0cQ9DBFiYYS7AY/0BbV31IPeiXfwrVMgBIOTg y7bTbSAxuZdkUEbwHu9WYNbB79CSOdvAOER/Z47+cgzlseAhhhpfhyx/yG5yBy+rF8tCgMUTY Us/BhbRYrko109srTIDpm2l5V6+THpeaWq5fbXd9jmghprTW1s1YY+HBtS+3iuvzmx4RXEJNz RU0EtureQPgp69sBqlhSdHzUvLlWGAgJG74445fxi8kWvfP9Jkf+mlwrwghiHbC5S0AfvT9oc GyShavXEXp4jIfNX4UgkEDaUxHDSE5ImMZ6+G6vAm6kna+LeQVvj7e0HOnD3+kiErSCEpnIhq U4B+vpo0NNwtVonekdLUxnokR3fin+AGa8PeTMnwJUUkLAYXy4hm1yLFg5QMxJXmSKEw84Ot/ zmKCTHtKHyOzrzzDiEWzg0pc3XxwuIlcfPO2I02B/6fCvRd1lApXlzTnGG83ygYr2jAkatL6T BIPER0eTia5DCHC2AfUbal6lY2ygnrrOmL3q+9S5Rytp/oX+bo7+UEb2XJtQZgFCF2x2ahKN4 a2bmMo0r9pZ8j9WqxVTaSzR5KHHWlombQ3+4L+BK63p6aC7LMuZdF7sXrH9eO34qTDK1oyXRp dAOLQ2wgSYEiTKaW5Icw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Most of the HDIO ioctls are only used by the obsolete drivers/ide subsystem, these can be handled by changing ide_cmd_ioctl() to be aware of compat mode and doing the correct transformations in place and using it as both native and compat handlers for all drivers. The SCSI drivers implementing the same commands are already doing this in the drivers, so the compat_blkdev_driver_ioctl() function is no longer needed now. The BLKSECTSET and HDIO_GETGEO_BIG ioctls are not implemented in any driver any more and no longer need any conversion. Signed-off-by: Arnd Bergmann --- block/compat_ioctl.c | 75 ---------------------------------- drivers/ide/ide-cd.c | 8 +++- drivers/ide/ide-disk.c | 3 ++ drivers/ide/ide-floppy_ioctl.c | 7 ++-- drivers/ide/ide-ioctls.c | 47 +++++++++++++-------- drivers/ide/ide-tape.c | 14 +++++++ 6 files changed, 57 insertions(+), 97 deletions(-) -- 2.20.0 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 7cb534d6e767..765aa5357655 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -77,24 +77,6 @@ static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, return ret; } -static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) -{ - unsigned long __user *p; - int error; - - p = compat_alloc_user_space(sizeof(unsigned long)); - error = __blkdev_driver_ioctl(bdev, mode, - cmd, (unsigned long)p); - if (error == 0) { - unsigned int __user *uvp = compat_ptr(arg); - unsigned long v; - if (get_user(v, p) || put_user(v, uvp)) - error = -EFAULT; - } - return error; -} - struct compat_blkpg_ioctl_arg { compat_int_t op; compat_int_t flags; @@ -128,61 +110,6 @@ static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, #define BLKBSZSET_32 _IOW(0x12, 113, int) #define BLKGETSIZE64_32 _IOR(0x12, 114, int) -static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, - unsigned cmd, unsigned long arg) -{ - switch (cmd) { - case HDIO_GET_UNMASKINTR: - case HDIO_GET_MULTCOUNT: - case HDIO_GET_KEEPSETTINGS: - case HDIO_GET_32BIT: - case HDIO_GET_NOWERR: - case HDIO_GET_DMA: - case HDIO_GET_NICE: - case HDIO_GET_WCACHE: - case HDIO_GET_ACOUSTIC: - case HDIO_GET_ADDRESS: - case HDIO_GET_BUSSTATE: - return compat_hdio_ioctl(bdev, mode, cmd, arg); - - /* - * No handler required for the ones below, we just need to - * convert arg to a 64 bit pointer. - */ - case BLKSECTSET: - /* - * 0x03 -- HD/IDE ioctl's used by hdparm and friends. - * Some need translations, these do not. - */ - case HDIO_GET_IDENTITY: - case HDIO_DRIVE_TASK: - case HDIO_DRIVE_CMD: - /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ - case 0x330: - arg = (unsigned long)compat_ptr(arg); - /* These intepret arg as an unsigned long, not as a pointer, - * so we must not do compat_ptr() conversion. */ - case HDIO_SET_MULTCOUNT: - case HDIO_SET_UNMASKINTR: - case HDIO_SET_KEEPSETTINGS: - case HDIO_SET_32BIT: - case HDIO_SET_NOWERR: - case HDIO_SET_DMA: - case HDIO_SET_PIO_MODE: - case HDIO_SET_NICE: - case HDIO_SET_WCACHE: - case HDIO_SET_ACOUSTIC: - case HDIO_SET_BUSSTATE: - case HDIO_SET_ADDRESS: - break; - default: - /* unknown ioctl number */ - return -ENOIOCTLCMD; - } - - return __blkdev_driver_ioctl(bdev, mode, cmd, arg); -} - /* Most of the generic ioctls are handled in the normal fallback path. This assumes the blkdev's low level compat_ioctl always returns ENOIOCTLCMD for unknown ioctls. */ @@ -293,8 +220,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) default: if (disk->fops->compat_ioctl) ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); - if (ret == -ENOIOCTLCMD) - ret = compat_blkdev_driver_ioctl(bdev, mode, cmd, arg); return ret; } } diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index 2de6e8ace957..521564da8707 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -1727,8 +1727,12 @@ static int idecd_locked_compat_ioctl(struct block_device *bdev, fmode_t mode, break; } - return cdrom_ioctl(&info->devinfo, bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); + err = generic_ide_ioctl(info->drive, bdev, cmd, arg); + if (err == -EINVAL) + err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + + return err; } static int idecd_compat_ioctl(struct block_device *bdev, fmode_t mode, diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c index 197912af5c2f..27f1098e4bcd 100644 --- a/drivers/ide/ide-disk.c +++ b/drivers/ide/ide-disk.c @@ -794,4 +794,7 @@ const struct ide_disk_ops ide_ata_disk_ops = { .set_doorlock = ide_disk_set_doorlock, .do_request = ide_do_rw_disk, .ioctl = ide_disk_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ide_disk_ioctl, +#endif }; diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c index 4fd70f804d6f..39a790ac6cc3 100644 --- a/drivers/ide/ide-floppy_ioctl.c +++ b/drivers/ide/ide-floppy_ioctl.c @@ -329,10 +329,9 @@ int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev, if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp); - /* - * there is no generic_ide_compat_ioctl(), that is handled - * through compat_blkdev_ioctl(). - */ + if (err == -ENOTTY) + err = generic_ide_ioctl(drive, bdev, cmd, arg); + out: mutex_unlock(&ide_floppy_ioctl_mutex); return err; diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c index d48c17003874..d97da46fdd79 100644 --- a/drivers/ide/ide-ioctls.c +++ b/drivers/ide/ide-ioctls.c @@ -3,11 +3,21 @@ * IDE ioctls handling. */ +#include #include #include #include #include +static int put_user_long(long val, unsigned long arg) +{ +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) + return put_user(val, (compat_long_t __user *)compat_ptr(arg)); +#endif + return put_user(val, (long __user *)arg); +} + static const struct ide_ioctl_devset ide_ioctl_settings[] = { { HDIO_GET_32BIT, HDIO_SET_32BIT, &ide_devset_io_32bit }, { HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, &ide_devset_keepsettings }, @@ -37,7 +47,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev, mutex_lock(&ide_setting_mtx); err = ds->get(drive); mutex_unlock(&ide_setting_mtx); - return err >= 0 ? put_user(err, (long __user *)arg) : err; + return err >= 0 ? put_user_long(err, arg) : err; set_val: if (bdev != bdev->bd_contains) @@ -56,7 +66,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev, EXPORT_SYMBOL_GPL(ide_setting_ioctl); static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd, - unsigned long arg) + void __user *argp) { u16 *id = NULL; int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142; @@ -77,7 +87,7 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd, memcpy(id, drive->id, size); ata_id_to_hd_driveid(id); - if (copy_to_user((void __user *)arg, id, size)) + if (copy_to_user(argp, id, size)) rc = -EFAULT; kfree(id); @@ -87,10 +97,10 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd, static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg) { - return put_user((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) + return put_user_long((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) << IDE_NICE_DSC_OVERLAP) | (!!(drive->dev_flags & IDE_DFLAG_NICE1) - << IDE_NICE_1), (long __user *)arg); + << IDE_NICE_1), arg); } static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) @@ -115,7 +125,7 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) return 0; } -static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) +static int ide_cmd_ioctl(ide_drive_t *drive, void __user *argp) { u8 *buf = NULL; int bufsize = 0, err = 0; @@ -123,7 +133,7 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) struct ide_cmd cmd; struct ide_taskfile *tf = &cmd.tf; - if (NULL == (void *) arg) { + if (NULL == argp) { struct request *rq; rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0); @@ -135,7 +145,7 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) return err; } - if (copy_from_user(args, (void __user *)arg, 4)) + if (copy_from_user(args, argp, 4)) return -EFAULT; memset(&cmd, 0, sizeof(cmd)); @@ -181,19 +191,18 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg) args[1] = tf->error; args[2] = tf->nsect; abort: - if (copy_to_user((void __user *)arg, &args, 4)) + if (copy_to_user(argp, &args, 4)) err = -EFAULT; if (buf) { - if (copy_to_user((void __user *)(arg + 4), buf, bufsize)) + if (copy_to_user((argp + 4), buf, bufsize)) err = -EFAULT; kfree(buf); } return err; } -static int ide_task_ioctl(ide_drive_t *drive, unsigned long arg) +static int ide_task_ioctl(ide_drive_t *drive, void __user *p) { - void __user *p = (void __user *)arg; int err = 0; u8 args[7]; struct ide_cmd cmd; @@ -237,6 +246,12 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, unsigned int cmd, unsigned long arg) { int err; + void __user *argp = (void __user *)arg; + +#ifdef CONFIG_COMPAT + if (in_compat_syscall()) + argp = compat_ptr(arg); +#endif err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_ioctl_settings); if (err != -EOPNOTSUPP) @@ -247,7 +262,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, case HDIO_GET_IDENTITY: if (bdev != bdev->bd_contains) return -EINVAL; - return ide_get_identity_ioctl(drive, cmd, arg); + return ide_get_identity_ioctl(drive, cmd, argp); case HDIO_GET_NICE: return ide_get_nice_ioctl(drive, arg); case HDIO_SET_NICE: @@ -265,11 +280,11 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, case HDIO_DRIVE_CMD: if (!capable(CAP_SYS_RAWIO)) return -EACCES; - return ide_cmd_ioctl(drive, arg); + return ide_cmd_ioctl(drive, argp); case HDIO_DRIVE_TASK: if (!capable(CAP_SYS_RAWIO)) return -EACCES; - return ide_task_ioctl(drive, arg); + return ide_task_ioctl(drive, argp); case HDIO_DRIVE_RESET: if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -277,7 +292,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, case HDIO_GET_BUSSTATE: if (!capable(CAP_SYS_ADMIN)) return -EACCES; - if (put_user(BUSSTATE_ON, (long __user *)arg)) + if (put_user_long(BUSSTATE_ON, arg)) return -EFAULT; return 0; case HDIO_SET_BUSSTATE: diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index 3e7482695f77..4c2a95a2f0b6 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c @@ -1945,11 +1945,25 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode, return err; } +#ifdef CONFIG_COMPAT +static int idetape_compat_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + if (cmd == 0x0340 || cmd == 0x350) + arg = (unsigned long)compat_ptr(arg); + + return idetape_ioctl(bdev, mode, cmd, arg); +} +#endif + static const struct block_device_operations idetape_block_ops = { .owner = THIS_MODULE, .open = idetape_open, .release = idetape_release, .ioctl = idetape_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = idetape_compat_ioctl, +#endif }; static int ide_tape_probe(ide_drive_t *drive) From patchwork Wed Dec 11 20:42:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181335 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp286ile; Wed, 11 Dec 2019 12:52:42 -0800 (PST) X-Google-Smtp-Source: APXvYqw0frRhZq04rFIDfG412LfQr7gps/xTrcACjNUBCC9llrAeDD+drISDzR3cq+/bkFG6YNVZ X-Received: by 2002:a9d:7ada:: with SMTP id m26mr4038267otn.111.1576097562519; Wed, 11 Dec 2019 12:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097562; cv=none; d=google.com; s=arc-20160816; b=ISauuwk3dvZlyWwvslwap43lBylpSpEu6X8Oo0hNnsFYk8e3+JsGHbYmwdkX/upP+i lxboW/EnK5N7j4ERPVJlxxJqLWwuxSrXink+tPfSGq0iuFuFxrbScmx+U494zU2Zvk6M tpj+ZjJko1eG0xZPS1yKMJU5WUNBD35leQXfscQlHE4ByXJ5H2YzjYo8hMjAqs7Cu0JT 4+XE+LI0FbiGwPw+pgxmCNVm6ke3g7V2f2cZMvaEs9wFO/DDDkEd0mjRQdE47X68MZZP aqWbYEw/yXsh+dOUIE4gcgJFKp0qtCBDSqOKJ9/6neOL5ukWt9VfXav6iAIRY+gc2v9L zQxQ== 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=37ltfNr2UPB6+Zd1w2fyaDMrvlxR/t2vJsCD+poZSBg=; b=bo1+j3L5UwsIQmo2bDOG89IrwgzJ+xDrsWERvbEqjyz0WQvbN7nR4/QZZ8ajNphuwS Do5XIch3guXWXLYXIMvg92mBq5zm9UeZdxoO09z+o3XRK40R675tvGUr7iXjpa6UTgIG a8cwgL4U6SKZV8RZTdXv2Ad0eRAIEWzMYJdpWM58SZDZJLs0v1lMHQyBnl0i3TPBdBlw hYqcd1W3DCoZUiVaMXmtCalvR9MJw+uihwMVmrwGLNwkszviLXDx68xUmDXCLuXDFlrs Xl4Pif+7XBWIHoGoRg0vmTdhEanXDxUO4B4D2oiDY4VDcFsLUgz9j153LTBKIxaqmdxs akLA== 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 w127si1911884oib.188.2019.12.11.12.52.42; Wed, 11 Dec 2019 12:52:42 -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 S1727014AbfLKUwj (ORCPT + 27 others); Wed, 11 Dec 2019 15:52:39 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:60331 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUwi (ORCPT ); Wed, 11 Dec 2019 15:52:38 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mate1-1i8Z2a00tv-00cSDW; Wed, 11 Dec 2019 21:52:23 +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 , Tejun Heo , Jan Kara , Chaitanya Kulkarni , Dmitry Fomichev , Ajay Joshi , linux-block@vger.kernel.org Subject: [PATCH 21/24] compat_ioctl: block: move blkdev_compat_ioctl() into ioctl.c Date: Wed, 11 Dec 2019 21:42:55 +0100 Message-Id: <20191211204306.1207817-22-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:w7zHYrDBY2C8svIiJb585dxlyotrcd5oC2ZLPyAld9cJfkGK7w9 g/7173xeoXDG5/fpd2BT5dmzTVQ9QtLnw+ZvQmAdRp7XTbwklWPepFMn8FQ96jQjJcZTUBk r8k37FjwAsXIY36zLysg3btj6jbnNtqx/7tySyV/ASxoQxXsXjgLDLzVgT6wdWu1DEKsiBc wXth8OKzkg892CmZiHMrw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:/VmLmeT7ZSs=:oV3Jkt67hSqaQCYBDkGlZj GXN1jKIrmci6dkyx1ZT27YRSvI4CIARxC1s/uVEb8VQhmp69xUxUxxJxAsnXTcGKq9PHv5nMt lXO2nBBsqs3KUAGGJ6AyPz7H5HYcT1HbfsuxkzCUCEo241KMLzhb05WYnIrlntzZx0VhfjyfY h6+TKu1HxLhqaTDz4n6+moEGQh2spukuko+CPvTIamMHX1O/6tL2ghwh3iCw+mQV2qXAF0NOz Gp6+8DwGzaMW0jgU9GPEnRkP0GIz/ks/b1E8D2+vcZ4mXKocah+c05HQ2EMJQl1ZsRW2AdX+8 hWGs98I1HP7n89WgVw3F7Wcujr6o3jrZL6MAvIwxrjXHMTI1gxIBm5uetM/oLWXbCdbfEFsWP srIdSdeXc96Lxl4UEr0lJnSlexzfa0HqW/sy/GK9nFsC8HQBq/MixJysDON3vouAvo3XJ0JHa jAgK/82tJ4oIhN7XQF+SziJFdFno83GeuijiP/uAmL0QRJaE+JCO4Ub00nGjMyinYT7KStS04 B2Zsd4JAv6W46GluI4EqNNO4R0YZgjcyJwxAyPHLWNJ48fTXk9+JJ51JFZQ6DtpzZeYcq6nN5 7PGKJROy8dVysZFJAutpLobtrPzLqX1NMldJOia8ZBdk7bl8TrvT9ktTEU070LmxIPdkezWJo 0nkrA7kM73cktYs1NYBR/04r58eClYrU9uHQtQCPyZYOiHVhVnnGtPS9VXYAn5mbeB3PAE/HG gKD+cOaiyehoKHtJkVfcfne1vmdraFeijnoIsszcch2HMgBf0k4/iVfBB+0zVcSzOWQ+gx1qV zT3r5nATETfZVfgBoW3wGCleDU3wbzYVczdo9DSSgyXdpUI3BnA4HXHh6U25Cyi6jDMSXW3VM rMWolX6N7WUn4B6Hi/ww== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Having both in the same file allows a number of simplifications to the compat path, and makes it more likely that changes to the native path get applied to the compat version as well. Signed-off-by: Arnd Bergmann --- block/Makefile | 1 - block/compat_ioctl.c | 225 ------------------------------------------- block/ioctl.c | 219 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 226 deletions(-) delete mode 100644 block/compat_ioctl.c -- 2.20.0 diff --git a/block/Makefile b/block/Makefile index 205a5f2fef17..1f70c73ea83d 100644 --- a/block/Makefile +++ b/block/Makefile @@ -25,7 +25,6 @@ obj-$(CONFIG_MQ_IOSCHED_KYBER) += kyber-iosched.o bfq-y := bfq-iosched.o bfq-wf2q.o bfq-cgroup.o obj-$(CONFIG_IOSCHED_BFQ) += bfq.o -obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_CMDLINE_PARSER) += cmdline-parser.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c deleted file mode 100644 index 765aa5357655..000000000000 --- a/block/compat_ioctl.c +++ /dev/null @@ -1,225 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int compat_put_ushort(unsigned long arg, unsigned short val) -{ - return put_user(val, (unsigned short __user *)compat_ptr(arg)); -} - -static int compat_put_int(unsigned long arg, int val) -{ - return put_user(val, (compat_int_t __user *)compat_ptr(arg)); -} - -static int compat_put_uint(unsigned long arg, unsigned int val) -{ - return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); -} - -static int compat_put_long(unsigned long arg, long val) -{ - return put_user(val, (compat_long_t __user *)compat_ptr(arg)); -} - -static int compat_put_ulong(unsigned long arg, compat_ulong_t val) -{ - return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); -} - -static int compat_put_u64(unsigned long arg, u64 val) -{ - return put_user(val, (compat_u64 __user *)compat_ptr(arg)); -} - -struct compat_hd_geometry { - unsigned char heads; - unsigned char sectors; - unsigned short cylinders; - u32 start; -}; - -static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, - struct compat_hd_geometry __user *ugeo) -{ - struct hd_geometry geo; - int ret; - - if (!ugeo) - return -EINVAL; - if (!disk->fops->getgeo) - return -ENOTTY; - - memset(&geo, 0, sizeof(geo)); - /* - * We need to set the startsect first, the driver may - * want to override it. - */ - geo.start = get_start_sect(bdev); - ret = disk->fops->getgeo(bdev, &geo); - if (ret) - return ret; - - ret = copy_to_user(ugeo, &geo, 4); - ret |= put_user(geo.start, &ugeo->start); - if (ret) - ret = -EFAULT; - - return ret; -} - -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) - -/* Most of the generic ioctls are handled in the normal fallback path. - This assumes the blkdev's low level compat_ioctl always returns - ENOIOCTLCMD for unknown ioctls. */ -long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) -{ - int ret = -ENOIOCTLCMD; - struct inode *inode = file->f_mapping->host; - struct block_device *bdev = inode->i_bdev; - struct gendisk *disk = bdev->bd_disk; - fmode_t mode = file->f_mode; - loff_t size; - unsigned int max_sectors; - - /* - * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have - * to updated it before every ioctl. - */ - if (file->f_flags & O_NDELAY) - mode |= FMODE_NDELAY; - else - mode &= ~FMODE_NDELAY; - - switch (cmd) { - case HDIO_GETGEO: - return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); - case BLKPBSZGET: - return compat_put_uint(arg, bdev_physical_block_size(bdev)); - case BLKIOMIN: - return compat_put_uint(arg, bdev_io_min(bdev)); - case BLKIOOPT: - return compat_put_uint(arg, bdev_io_opt(bdev)); - case BLKALIGNOFF: - return compat_put_int(arg, bdev_alignment_offset(bdev)); - case BLKDISCARDZEROES: - return compat_put_uint(arg, 0); - case BLKFLSBUF: - case BLKROSET: - case BLKDISCARD: - case BLKSECDISCARD: - case BLKZEROOUT: - /* - * the ones below are implemented in blkdev_locked_ioctl, - * but we call blkdev_ioctl, which gets the lock for us - */ - case BLKRRPART: - case BLKREPORTZONE: - case BLKRESETZONE: - case BLKOPENZONE: - case BLKCLOSEZONE: - case BLKFINISHZONE: - case BLKGETZONESZ: - case BLKGETNRZONES: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); - case BLKBSZSET_32: - return blkdev_ioctl(bdev, mode, BLKBSZSET, - (unsigned long)compat_ptr(arg)); - case BLKPG: - return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); - case BLKRAGET: - case BLKFRAGET: - if (!arg) - return -EINVAL; - return compat_put_long(arg, - (bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512); - case BLKROGET: /* compatible */ - return compat_put_int(arg, bdev_read_only(bdev) != 0); - case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ - return compat_put_int(arg, block_size(bdev)); - case BLKSSZGET: /* get block device hardware sector size */ - return compat_put_int(arg, bdev_logical_block_size(bdev)); - case BLKSECTGET: - max_sectors = min_t(unsigned int, USHRT_MAX, - queue_max_sectors(bdev_get_queue(bdev))); - return compat_put_ushort(arg, max_sectors); - case BLKROTATIONAL: - return compat_put_ushort(arg, - !blk_queue_nonrot(bdev_get_queue(bdev))); - case BLKRASET: /* compatible, but no compat_ptr (!) */ - case BLKFRASET: - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; - return 0; - case BLKGETSIZE: - size = i_size_read(bdev->bd_inode); - if ((size >> 9) > ~0UL) - return -EFBIG; - return compat_put_ulong(arg, size >> 9); - - case BLKGETSIZE64_32: - return compat_put_u64(arg, i_size_read(bdev->bd_inode)); - - case BLKTRACESETUP32: - case BLKTRACESTART: /* compatible */ - case BLKTRACESTOP: /* compatible */ - case BLKTRACETEARDOWN: /* compatible */ - ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); - return ret; - case IOC_PR_REGISTER: - case IOC_PR_RESERVE: - case IOC_PR_RELEASE: - case IOC_PR_PREEMPT: - case IOC_PR_PREEMPT_ABORT: - case IOC_PR_CLEAR: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); - default: - if (disk->fops->compat_ioctl) - ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); - return ret; - } -} diff --git a/block/ioctl.c b/block/ioctl.c index e728331d1a5b..f8c4e2649335 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -269,6 +269,38 @@ static int put_u64(unsigned long arg, u64 val) return put_user(val, (u64 __user *)arg); } +#ifdef CONFIG_COMPAT +static int compat_put_ushort(unsigned long arg, unsigned short val) +{ + return put_user(val, (unsigned short __user *)compat_ptr(arg)); +} + +static int compat_put_int(unsigned long arg, int val) +{ + return put_user(val, (compat_int_t __user *)compat_ptr(arg)); +} + +static int compat_put_uint(unsigned long arg, unsigned int val) +{ + return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); +} + +static int compat_put_long(unsigned long arg, long val) +{ + return put_user(val, (compat_long_t __user *)compat_ptr(arg)); +} + +static int compat_put_ulong(unsigned long arg, compat_ulong_t val) +{ + return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); +} + +static int compat_put_u64(unsigned long arg, u64 val) +{ + return put_user(val, (compat_u64 __user *)compat_ptr(arg)); +} +#endif + int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, unsigned long arg) { @@ -476,6 +508,44 @@ static int blkdev_getgeo(struct block_device *bdev, return 0; } +#ifdef CONFIG_COMPAT +struct compat_hd_geometry { + unsigned char heads; + unsigned char sectors; + unsigned short cylinders; + u32 start; +}; + +static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, + struct compat_hd_geometry __user *ugeo) +{ + struct hd_geometry geo; + int ret; + + if (!ugeo) + return -EINVAL; + if (!disk->fops->getgeo) + return -ENOTTY; + + memset(&geo, 0, sizeof(geo)); + /* + * We need to set the startsect first, the driver may + * want to override it. + */ + geo.start = get_start_sect(bdev); + ret = disk->fops->getgeo(bdev, &geo); + if (ret) + return ret; + + ret = copy_to_user(ugeo, &geo, 4); + ret |= put_user(geo.start, &ugeo->start); + if (ret) + ret = -EFAULT; + + return ret; +} +#endif + /* set the logical block size */ static int blkdev_bszset(struct block_device *bdev, fmode_t mode, int __user *argp) @@ -604,3 +674,152 @@ 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) + +/* Most of the generic ioctls are handled in the normal fallback path. + This assumes the blkdev's low level compat_ioctl always returns + ENOIOCTLCMD for unknown ioctls. */ +long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) +{ + int ret = -ENOIOCTLCMD; + struct inode *inode = file->f_mapping->host; + struct block_device *bdev = inode->i_bdev; + struct gendisk *disk = bdev->bd_disk; + fmode_t mode = file->f_mode; + loff_t size; + unsigned int max_sectors; + + /* + * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have + * to updated it before every ioctl. + */ + if (file->f_flags & O_NDELAY) + mode |= FMODE_NDELAY; + else + mode &= ~FMODE_NDELAY; + + switch (cmd) { + case HDIO_GETGEO: + return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); + case BLKPBSZGET: + return compat_put_uint(arg, bdev_physical_block_size(bdev)); + case BLKIOMIN: + return compat_put_uint(arg, bdev_io_min(bdev)); + case BLKIOOPT: + return compat_put_uint(arg, bdev_io_opt(bdev)); + case BLKALIGNOFF: + return compat_put_int(arg, bdev_alignment_offset(bdev)); + case BLKDISCARDZEROES: + return compat_put_uint(arg, 0); + case BLKFLSBUF: + case BLKROSET: + case BLKDISCARD: + case BLKSECDISCARD: + case BLKZEROOUT: + /* + * the ones below are implemented in blkdev_locked_ioctl, + * but we call blkdev_ioctl, which gets the lock for us + */ + case BLKRRPART: + case BLKREPORTZONE: + case BLKRESETZONE: + case BLKOPENZONE: + case BLKCLOSEZONE: + case BLKFINISHZONE: + case BLKGETZONESZ: + case BLKGETNRZONES: + return blkdev_ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + case BLKBSZSET_32: + return blkdev_ioctl(bdev, mode, BLKBSZSET, + (unsigned long)compat_ptr(arg)); + case BLKPG: + return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); + case BLKRAGET: + case BLKFRAGET: + if (!arg) + return -EINVAL; + return compat_put_long(arg, + (bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512); + case BLKROGET: /* compatible */ + return compat_put_int(arg, bdev_read_only(bdev) != 0); + case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ + return compat_put_int(arg, block_size(bdev)); + case BLKSSZGET: /* get block device hardware sector size */ + return compat_put_int(arg, bdev_logical_block_size(bdev)); + case BLKSECTGET: + max_sectors = min_t(unsigned int, USHRT_MAX, + queue_max_sectors(bdev_get_queue(bdev))); + return compat_put_ushort(arg, max_sectors); + case BLKROTATIONAL: + return compat_put_ushort(arg, + !blk_queue_nonrot(bdev_get_queue(bdev))); + case BLKRASET: /* compatible, but no compat_ptr (!) */ + case BLKFRASET: + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; + return 0; + case BLKGETSIZE: + size = i_size_read(bdev->bd_inode); + if ((size >> 9) > ~0UL) + return -EFBIG; + return compat_put_ulong(arg, size >> 9); + + case BLKGETSIZE64_32: + return compat_put_u64(arg, i_size_read(bdev->bd_inode)); + + case BLKTRACESETUP32: + case BLKTRACESTART: /* compatible */ + case BLKTRACESTOP: /* compatible */ + case BLKTRACETEARDOWN: /* compatible */ + ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); + return ret; + case IOC_PR_REGISTER: + case IOC_PR_RESERVE: + case IOC_PR_RELEASE: + case IOC_PR_PREEMPT: + case IOC_PR_PREEMPT_ABORT: + case IOC_PR_CLEAR: + return blkdev_ioctl(bdev, mode, cmd, + (unsigned long)compat_ptr(arg)); + default: + if (disk->fops->compat_ioctl) + ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); + return ret; + } +} +#endif 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) From patchwork Wed Dec 11 20:42:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181337 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp651ile; Wed, 11 Dec 2019 12:52:58 -0800 (PST) X-Google-Smtp-Source: APXvYqx+pLsYk3eUc0b/dQl/p/VlALq5M30jalWp+vYqESHXtWMszoJjwqfjrjS3wOnqyAdAw4Iu X-Received: by 2002:a05:6830:1d91:: with SMTP id y17mr3712780oti.276.1576097578721; Wed, 11 Dec 2019 12:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097578; cv=none; d=google.com; s=arc-20160816; b=ZuL6cUN7CH/+hEPSfADAvQfwgXYACI3upn46ssJ5V25LgH6Sk7XbAK/GRi8IHjpMog 44CJDZgLHs0nfMSrLbFsplXiyPxsjw+kWiv2xinSms3mgzlFyi8cDf/PqaTrg8LgR+zp 6qsxO4iB1EBPkb29q0iXVPBvHP830w6MiuW8yjBwBHLh1h3jp6a4QPoCV9LLHW7FXHaa UP0KUUg8iwvaxtemT6nfEap9VEQPQ2fetzPbIXBJyK2TkOzn0cT84LdqdQEha57yY085 8xDQ3lTk2A5ec2Ds4Q10ztf0dhd2t7gAyVL6dCRY/U5KGihBrN2UrUa+CzkWcHmkNrFy CKhg== 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=aNYSrTuJvlEyinSN9jUlUxWVGVcGBrdANOGmvyHq0Gg=; b=Y/fO4ngnjKcvRIQtWG1dtZLDW2TalN/aIxU/bncqx7AJfYdH2FUV/xtMt3OOjmUtua Yy3qFM+lbfu6VIcZO1q9/QtKNcUmMKpD+pmW19R/3zQUfNTXZwiGztX57xp5EQHwt2bd BSX/iAHqNEiMU/AnZ9PprVVYwSbsuvXZ3npgGMtMFLLNiekrRu3DQeHT7wyIzrFZNZEk wSVng6ysiy1Pn9/HHW1wfb9N3uUlaAFnEIXYhlPgTdRJcC8ZTSMU25DXxY5a19HBPxVV ap5PnhxACJQbar9r2x7C1+AXtZ92fHFLAqBYZL30sxAOOi+kJDwNbRnH83V4gpMUo6rZ GSGQ== 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 d11si1735816oti.325.2019.12.11.12.52.58; Wed, 11 Dec 2019 12:52:58 -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 S1727110AbfLKUw5 (ORCPT + 27 others); Wed, 11 Dec 2019 15:52:57 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:36589 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbfLKUw4 (ORCPT ); Wed, 11 Dec 2019 15:52:56 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M1YpJ-1ihckI0soN-0037Oo; Wed, 11 Dec 2019 21:52:45 +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 , Chaitanya Kulkarni , Ajay Joshi , linux-block@vger.kernel.org Subject: [PATCH 23/24] compat_ioctl: simplify up block/ioctl.c Date: Wed, 11 Dec 2019 21:42:57 +0100 Message-Id: <20191211204306.1207817-24-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:+8Rd6bScH9E1zZsBDpHLTq6M7+pje2Uc3WK0Esto0OQN+mxbaHT aHfBbYh+qqZ16iDXt9x6aCrQwksQMVQOYyljdKOviBykkd7cm65jGcmcLCwTIQabu4wlGw5 OhQmwY2bny5wre0fclR/Vc7/Jur6lAzMHMskgzvGWnoF8m1PWcwidc7zVp12+dPpK0Ms7Oc tEjr8XCjyerHwlGyvOXCw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:XlJmLjyUVaI=:IEiwhZ+ftAQTk4lgAB5yCj spMoW3dYnG1ljMiw2y0QiEXxIzZgyxIuA5UytkWBnz805LJIOS6TA8hW590MnHSAKwLzRdTFh CJFSxZxU9M/DUUx+Fxj+iv2iJEXRmAyQBnLdqh0Br+WihOUh7Mv6ttG4CBJLKtxV3EMjBtf42 NRG7G66fMFBtI8CenmD6fyMnCnxBIySIUozWNzx8B38bm8l1fOiP+pBah8dLBBmXig5IPK/lp f4wUv418V+nvKrhOot5/L1PBIcZ1MMgkQQGd2uXD3MxTsV347+CE8LSlmaUyukVhBxlCdnzr+ gbQ0A0Roo2LcUq5euUuKZC4JYaLVAHFMMzUSxr4KsqfoK2g0pQ3yTaRkKjt921Y8mmOgji6F3 DekvdVLktY8ph3/D/NfDBm3GLM3HLgK0ljP8JX7ruppsMe2amOAJqD8H+Um0L8iZZfGTTYwgK 8LBYFTPwxDqmtBWZO6PY4EdrktlMTKs5Gfq9IGc9vykHgKfjioEAd8ioOiRJNHx8MwYHj3QXn ZFml/+ZEvtYRCwTwSLBIO+BLlSt2cZylxrSWeFZKAjia9txLVGcUlMbps5JvExYgiA6/DNnr5 9IMuALI+M1r1sKFWSsUG4fCjaUVQKSARjgFwbZGUcyRMNNQHBB6qwKEPLJLwhAzL9fhWW4UQh bZ5AWsRNJXLWuNNaP3OmdU8glrz7h92bN4Ply12xn2lfLIRgDWDeUo3iPQFOab85+44xegfRW QqRFvrB0q8Z97X0GO9AUP01OY1FW12MucFOrhM9lrrSN6VoqJ3/+sjld+hdfqQTgxzQQiGUIU XWlcK8coiuWuXCsDbUW30ZP5KwHoTbzJ6mMUq0Ph5twjNA1WEiDhwtiFQMd/XqcYx5Z2QxzIi kVewhxI/S7HbbXpELuWw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Having separate implementations of blkdev_ioctl() often leads to these getting out of sync, despite the comment at the top. Since most of the ioctl commands are compatible, and we try very hard not to add any new incompatible ones, move all the common bits into a shared function and leave only the ones that are historically different in separate functions for native/compat mode. To deal with the compat_ptr() conversion, pass both the integer argument and the pointer argument into the new blkdev_common_ioctl() and make sure to always use the correct one of these. blkdev_ioctl() is now only kept as a separate exported interfact for drivers/char/raw.c, which lacks a compat_ioctl variant. We should probably either move raw.c to staging if there are no more users, or export blkdev_compat_ioctl() as well. Signed-off-by: Arnd Bergmann --- block/ioctl.c | 269 ++++++++++++++++++++++---------------------------- 1 file changed, 117 insertions(+), 152 deletions(-) -- 2.20.0 diff --git a/block/ioctl.c b/block/ioctl.c index d6911a1149f5..127194b9f9bd 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -270,65 +270,45 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, BLKDEV_ZERO_NOUNMAP); } -static int put_ushort(unsigned long arg, unsigned short val) +static int put_ushort(unsigned short __user *argp, unsigned short val) { - return put_user(val, (unsigned short __user *)arg); + return put_user(val, argp); } -static int put_int(unsigned long arg, int val) +static int put_int(int __user *argp, int val) { - return put_user(val, (int __user *)arg); + return put_user(val, argp); } -static int put_uint(unsigned long arg, unsigned int val) +static int put_uint(unsigned int __user *argp, unsigned int val) { - return put_user(val, (unsigned int __user *)arg); + return put_user(val, argp); } -static int put_long(unsigned long arg, long val) +static int put_long(long __user *argp, long val) { - return put_user(val, (long __user *)arg); + return put_user(val, argp); } -static int put_ulong(unsigned long arg, unsigned long val) +static int put_ulong(unsigned long __user *argp, unsigned long val) { - return put_user(val, (unsigned long __user *)arg); + return put_user(val, argp); } -static int put_u64(unsigned long arg, u64 val) +static int put_u64(u64 __user *argp, u64 val) { - return put_user(val, (u64 __user *)arg); + return put_user(val, argp); } #ifdef CONFIG_COMPAT -static int compat_put_ushort(unsigned long arg, unsigned short val) +static int compat_put_long(compat_long_t *argp, long val) { - return put_user(val, (unsigned short __user *)compat_ptr(arg)); + return put_user(val, argp); } -static int compat_put_int(unsigned long arg, int val) +static int compat_put_ulong(compat_ulong_t *argp, compat_ulong_t val) { - return put_user(val, (compat_int_t __user *)compat_ptr(arg)); -} - -static int compat_put_uint(unsigned long arg, unsigned int val) -{ - return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); -} - -static int compat_put_long(unsigned long arg, long val) -{ - return put_user(val, (compat_long_t __user *)compat_ptr(arg)); -} - -static int compat_put_ulong(unsigned long arg, compat_ulong_t val) -{ - return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); -} - -static int compat_put_u64(unsigned long arg, u64 val) -{ - return put_user(val, (compat_u64 __user *)compat_ptr(arg)); + return put_user(val, argp); } #endif @@ -547,9 +527,10 @@ struct compat_hd_geometry { u32 start; }; -static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, - struct compat_hd_geometry __user *ugeo) +static int compat_hdio_getgeo(struct block_device *bdev, + struct compat_hd_geometry __user *ugeo) { + struct gendisk *disk = bdev->bd_disk; struct hd_geometry geo; int ret; @@ -603,13 +584,13 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode, } /* - * always keep this in sync with compat_blkdev_ioctl() + * Common commands that are handled the same way on native and compat + * user space. Note the separate arg/argp parameters that are needed + * to deal with the compat_ptr() conversion. */ -int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, - unsigned long arg) +static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, + unsigned cmd, unsigned long arg, void __user *argp) { - void __user *argp = (void __user *)arg; - loff_t size; unsigned int max_sectors; switch (cmd) { @@ -632,60 +613,39 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case BLKFINISHZONE: return blkdev_zone_mgmt_ioctl(bdev, mode, cmd, arg); case BLKGETZONESZ: - return put_uint(arg, bdev_zone_sectors(bdev)); + return put_uint(argp, bdev_zone_sectors(bdev)); case BLKGETNRZONES: - return put_uint(arg, blkdev_nr_zones(bdev->bd_disk)); - case HDIO_GETGEO: - return blkdev_getgeo(bdev, argp); - case BLKRAGET: - case BLKFRAGET: - if (!arg) - return -EINVAL; - return put_long(arg, (bdev->bd_bdi->ra_pages*PAGE_SIZE) / 512); + return put_uint(argp, blkdev_nr_zones(bdev->bd_disk)); case BLKROGET: - return put_int(arg, bdev_read_only(bdev) != 0); - case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */ - return put_int(arg, block_size(bdev)); + return put_int(argp, bdev_read_only(bdev) != 0); case BLKSSZGET: /* get block device logical block size */ - return put_int(arg, bdev_logical_block_size(bdev)); + return put_int(argp, bdev_logical_block_size(bdev)); case BLKPBSZGET: /* get block device physical block size */ - return put_uint(arg, bdev_physical_block_size(bdev)); + return put_uint(argp, bdev_physical_block_size(bdev)); case BLKIOMIN: - return put_uint(arg, bdev_io_min(bdev)); + return put_uint(argp, bdev_io_min(bdev)); case BLKIOOPT: - return put_uint(arg, bdev_io_opt(bdev)); + return put_uint(argp, bdev_io_opt(bdev)); case BLKALIGNOFF: - return put_int(arg, bdev_alignment_offset(bdev)); + return put_int(argp, bdev_alignment_offset(bdev)); case BLKDISCARDZEROES: - return put_uint(arg, 0); + return put_uint(argp, 0); case BLKSECTGET: max_sectors = min_t(unsigned int, USHRT_MAX, queue_max_sectors(bdev_get_queue(bdev))); - return put_ushort(arg, max_sectors); + return put_ushort(argp, max_sectors); case BLKROTATIONAL: - return put_ushort(arg, !blk_queue_nonrot(bdev_get_queue(bdev))); + return put_ushort(argp, !blk_queue_nonrot(bdev_get_queue(bdev))); case BLKRASET: case BLKFRASET: if(!capable(CAP_SYS_ADMIN)) return -EACCES; bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; return 0; - case BLKBSZSET: - return blkdev_bszset(bdev, mode, argp); - case BLKPG: - return blkpg_ioctl(bdev, argp); case BLKRRPART: return blkdev_reread_part(bdev); - case BLKGETSIZE: - size = i_size_read(bdev->bd_inode); - if ((size >> 9) > ~0UL) - return -EFBIG; - return put_ulong(arg, size >> 9); - case BLKGETSIZE64: - return put_u64(arg, i_size_read(bdev->bd_inode)); case BLKTRACESTART: case BLKTRACESTOP: - case BLKTRACESETUP: case BLKTRACETEARDOWN: return blk_trace_ioctl(bdev, cmd, argp); case IOC_PR_REGISTER: @@ -701,12 +661,67 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case IOC_PR_CLEAR: return blkdev_pr_clear(bdev, argp); default: - return __blkdev_driver_ioctl(bdev, mode, cmd, arg); + return -ENOIOCTLCMD; } } -EXPORT_SYMBOL_GPL(blkdev_ioctl); + +/* + * Always keep this in sync with compat_blkdev_ioctl() + * to handle all incompatible commands in both functions. + * + * New commands must be compatible and go into blkdev_common_ioctl + */ +int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, + unsigned long arg) +{ + int ret; + loff_t size; + void __user *argp = (void __user *)arg; + + switch (cmd) { + /* These need separate implementations for the data structure */ + case HDIO_GETGEO: + return blkdev_getgeo(bdev, argp); + case BLKPG: + return blkpg_ioctl(bdev, argp); + + /* Compat mode returns 32-bit data instead of 'long' */ + case BLKRAGET: + case BLKFRAGET: + if (!argp) + return -EINVAL; + return put_long(argp, (bdev->bd_bdi->ra_pages*PAGE_SIZE) / 512); + case BLKGETSIZE: + size = i_size_read(bdev->bd_inode); + if ((size >> 9) > ~0UL) + return -EFBIG; + return put_ulong(argp, size >> 9); + + /* The data is compatible, but the command number is different */ + case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */ + return put_int(argp, block_size(bdev)); + case BLKBSZSET: + return blkdev_bszset(bdev, mode, argp); + case BLKGETSIZE64: + return put_u64(argp, i_size_read(bdev->bd_inode)); + + /* Incompatible alignment on i386 */ + case BLKTRACESETUP: + return blk_trace_ioctl(bdev, cmd, argp); + default: + break; + } + + ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp); + if (ret == -ENOIOCTLCMD) + return __blkdev_driver_ioctl(bdev, mode, cmd, arg); + + return ret; +} +EXPORT_SYMBOL_GPL(blkdev_ioctl); /* for /dev/raw */ #ifdef CONFIG_COMPAT + #define BLKBSZGET_32 _IOR(0x12, 112, int) #define BLKBSZSET_32 _IOW(0x12, 113, int) #define BLKGETSIZE64_32 _IOR(0x12, 114, int) @@ -716,13 +731,13 @@ EXPORT_SYMBOL_GPL(blkdev_ioctl); ENOIOCTLCMD for unknown ioctls. */ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) { - int ret = -ENOIOCTLCMD; + int ret; + void __user *argp = compat_ptr(arg); struct inode *inode = file->f_mapping->host; struct block_device *bdev = inode->i_bdev; struct gendisk *disk = bdev->bd_disk; fmode_t mode = file->f_mode; loff_t size; - unsigned int max_sectors; /* * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have @@ -734,94 +749,44 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) mode &= ~FMODE_NDELAY; switch (cmd) { + /* These need separate implementations for the data structure */ case HDIO_GETGEO: - return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); - case BLKPBSZGET: - return compat_put_uint(arg, bdev_physical_block_size(bdev)); - case BLKIOMIN: - return compat_put_uint(arg, bdev_io_min(bdev)); - case BLKIOOPT: - return compat_put_uint(arg, bdev_io_opt(bdev)); - case BLKALIGNOFF: - return compat_put_int(arg, bdev_alignment_offset(bdev)); - case BLKDISCARDZEROES: - return compat_put_uint(arg, 0); - case BLKFLSBUF: - case BLKROSET: - case BLKDISCARD: - case BLKSECDISCARD: - case BLKZEROOUT: - /* - * the ones below are implemented in blkdev_locked_ioctl, - * but we call blkdev_ioctl, which gets the lock for us - */ - case BLKRRPART: - case BLKREPORTZONE: - case BLKRESETZONE: - case BLKOPENZONE: - case BLKCLOSEZONE: - case BLKFINISHZONE: - case BLKGETZONESZ: - case BLKGETNRZONES: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); - case BLKBSZSET_32: - return blkdev_ioctl(bdev, mode, BLKBSZSET, - (unsigned long)compat_ptr(arg)); + return compat_hdio_getgeo(bdev, argp); case BLKPG: - return compat_blkpg_ioctl(bdev, compat_ptr(arg)); + return compat_blkpg_ioctl(bdev, argp); + + /* Compat mode returns 32-bit data instead of 'long' */ case BLKRAGET: case BLKFRAGET: - if (!arg) + if (!argp) return -EINVAL; - return compat_put_long(arg, + return compat_put_long(argp, (bdev->bd_bdi->ra_pages * PAGE_SIZE) / 512); - case BLKROGET: /* compatible */ - return compat_put_int(arg, bdev_read_only(bdev) != 0); - case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ - return compat_put_int(arg, block_size(bdev)); - case BLKSSZGET: /* get block device hardware sector size */ - return compat_put_int(arg, bdev_logical_block_size(bdev)); - case BLKSECTGET: - max_sectors = min_t(unsigned int, USHRT_MAX, - queue_max_sectors(bdev_get_queue(bdev))); - return compat_put_ushort(arg, max_sectors); - case BLKROTATIONAL: - return compat_put_ushort(arg, - !blk_queue_nonrot(bdev_get_queue(bdev))); - case BLKRASET: /* compatible, but no compat_ptr (!) */ - case BLKFRASET: - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - bdev->bd_bdi->ra_pages = (arg * 512) / PAGE_SIZE; - return 0; case BLKGETSIZE: size = i_size_read(bdev->bd_inode); if ((size >> 9) > ~0UL) return -EFBIG; - return compat_put_ulong(arg, size >> 9); + return compat_put_ulong(argp, size >> 9); + /* The data is compatible, but the command number is different */ + case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ + return put_int(argp, bdev_logical_block_size(bdev)); + case BLKBSZSET_32: + return blkdev_bszset(bdev, mode, argp); case BLKGETSIZE64_32: - return compat_put_u64(arg, i_size_read(bdev->bd_inode)); + return put_u64(argp, i_size_read(bdev->bd_inode)); + /* Incompatible alignment on i386 */ case BLKTRACESETUP32: - case BLKTRACESTART: /* compatible */ - case BLKTRACESTOP: /* compatible */ - case BLKTRACETEARDOWN: /* compatible */ - ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); - return ret; - case IOC_PR_REGISTER: - case IOC_PR_RESERVE: - case IOC_PR_RELEASE: - case IOC_PR_PREEMPT: - case IOC_PR_PREEMPT_ABORT: - case IOC_PR_CLEAR: - return blkdev_ioctl(bdev, mode, cmd, - (unsigned long)compat_ptr(arg)); + return blk_trace_ioctl(bdev, cmd, argp); default: - if (disk->fops->compat_ioctl) - ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); - return ret; + break; } + + ret = blkdev_common_ioctl(bdev, mode, cmd, arg, argp); + if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl) + ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); + + return ret; } #endif From patchwork Wed Dec 11 20:42:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181338 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1052ile; Wed, 11 Dec 2019 12:53:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyjjWFKsjVxMVEMMY0yh569BGw+mooIql+NLHzHUiPfpsTQbI93X4IuwIF5Lq+gkDVWK56S X-Received: by 2002:a05:6830:1741:: with SMTP id 1mr4092833otz.295.1576097602832; Wed, 11 Dec 2019 12:53:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576097602; cv=none; d=google.com; s=arc-20160816; b=ThaNHmU2+SgIHjILiZZNvFEIaNSeeTYUAwSldUdzV/gvJgPyN3JEkY/ptvotPjHDBo SAERMECEWB3+x4Iv9spDwuazuqcJRVxvZ0EVP56oLVMpQQxIwgPzArPzKGUrjI1rWzdI EThtFHDYC0/UvlXpsR62W9QC6qLviFNfMXpqpmZ+0gGn1ikRWNizcIJCHP5BdwdAf3Er RCLXfWNb0Dei9CNiobljzfLtsI7FinotE2ODxMyZjqnz9kC3kDoYl4UXfPXav+DM3vGI o39U+wwewLkv4husL4jo4noqQPqzO74NwLtL4zL4ZcQ3JagHJJwyB9ICSaZGSpTQf6s1 /L3A== 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=XSeW0A9nSoRfus6uaEZusK19s2zYe5lanA6tFPHkjgc=; b=aLHlZhvMlJdnwdJAaYiq1OejBZ5SKVjEwexe7f86fZOBdBw4cdCczzuE1rVKuP5UU+ M1Jt0FQbGZ0M2yJd6sMutr7klVEnO0meH5tmVjIl4eNwMoPb28ChDFggocTX+XCO+51o yHTU7fTGp5B199LkVLzHDUT7xfJj5/qzawNIM7px2XwQlkdeoURJGxhTE2QKtzH37WeS wQyLcZ+gntpUfynWEmFa9wPg6xSab6kemRRvw1COiHlh3mWt0x/3rDGaZs/sE8MZw1tf xJYZS7n8MivSsDPFRHhzXAP1T03uxx//1MKov87dO94y2+C3mkIXVfNxHJhYqs1LOjqU m/1w== 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 d11si1735816oti.325.2019.12.11.12.53.22; Wed, 11 Dec 2019 12:53:22 -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 S1727119AbfLKUxV (ORCPT + 27 others); Wed, 11 Dec 2019 15:53:21 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:33265 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbfLKUxV (ORCPT ); Wed, 11 Dec 2019 15:53:21 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MNbxN-1iLXWl00p1-00P20M; Wed, 11 Dec 2019 21:53:04 +0100 From: Arnd Bergmann To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Arnd Bergmann , Mauro Carvalho Chehab , =?utf-8?q?Jonathan?= =?utf-8?q?_Neusch=C3=A4fer?= , Masahiro Yamada , Vladimir Oltean , Kent Overstreet , linux-doc@vger.kernel.org Subject: [PATCH 24/24] Documentation: document ioctl interfaces better Date: Wed, 11 Dec 2019 21:42:58 +0100 Message-Id: <20191211204306.1207817-25-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:aX83qY2gzIb1UH/MGpptCcNx3Fm7jzI7Op46RwEngICWEsKbKJN +aB7rHtumg4Q8zjAEcbg8JF+GwQKoWsmw+eVpuk9HuyhQ6K9c95DCG29r4mNe5FipNvkFN3 67RUuhau+/vsEiZFpWPoXowNU15R94B8sP26iKibS8kY2W8VcXdU+8WT/w3jOCsowLkJuk6 1CjcV4L6aRdT1CxCbkRWA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:1lOjHeULC1c=:jEdbpOrh8ZnOFDTj9moCuP NZ/yy9AdO26TLdpn2YZaWxVYi0oQoCY6GemZOwTMQGVu5ZFPxOlrWtSCLJYu8lF2UihygYaNa KpdquzCEUuUswjQciRokgyfP+XOwNTsepKzA0Nbz5u6qsp1igs8qUcE29q5iaqXzGCdsQ+N9N TDEOc8CoLKkD35EmOcFX4A6MwLytKyFDddcLTQPfrX5op3yLTHtqpFOxj7tyxtPWBD4tnjIjU aB0NdC2k8PMK58sHxugu4yEGTC3ImlyvRrnq+NWQLUV+Qw8hGvDTe9sGY5hN69In2RYI8o/iQ BbtlQI6gieWS6bNAZZTQE03/Zxcw2ZBt+E4c83SLabBVTRcKKyVHkGts8mA/yhLL0BJBVYOt1 x53yvAD6YJWCzjSksDpTcPsJ2mKh9K+T1xxyMgWFrZmC0MDLmhmv9bmIQ5Lz1I0VYm+11jkri kcGb4FmGhMwCFH/mZkCuLCWDD0cJGin3dIFy+Kj5tXZVN9YAiw8IvKtcJKzoQwq0kMAEFEslx S0wzpX4NJ+8DfiR93a+6XxJ/hu+Gqidu90Sv3PNpPznbv2KhZOsnl0k8jVUKVKeZhcVrkUSyd j7Fb3owOK7loApQocdDRgMvc1oNMJNszjHYI5ySLXedbVClebSBsCulyBXyZD9kqzVNZDuxBc dwJvXtcjRU2khOPZF8wrq29nohZtCc48aR0gEzdt58yKg0ZvWHSi9hS6pnBtYRMb/A0Pt70pV GhPE/hZf/0Lbc/0clAF6GW0sAMh8WR7hp3I4lz69tEzUUORDu45Q1Rspa/w3hS6PcPMZE3bZB RSWI8saJ/qvWY+2fNqO5hEMHbdQrn3HUSR1CPKqn8p3R+fWSoU9w3L+DxrDDf5RT7a/RBv2oH rE96sNcEXYcI6x53pkvg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Documentation/process/botching-up-ioctls.rst was orignally written as a blog post for DRM driver writers, so it it misses some points while going into a lot of detail on others. Try to provide a replacement that addresses typical issues across a wider range of subsystems, and follows the style of the core-api documentation better. Signed-off-by: Arnd Bergmann --- Documentation/core-api/index.rst | 1 + Documentation/core-api/ioctl.rst | 250 +++++++++++++++++++++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 Documentation/core-api/ioctl.rst -- 2.20.0 diff --git a/Documentation/core-api/index.rst b/Documentation/core-api/index.rst index ab0eae1c153a..3f28b2f668be 100644 --- a/Documentation/core-api/index.rst +++ b/Documentation/core-api/index.rst @@ -39,6 +39,7 @@ Core utilities ../RCU/index gcc-plugins symbol-namespaces + ioctl Interfaces for kernel debugging diff --git a/Documentation/core-api/ioctl.rst b/Documentation/core-api/ioctl.rst new file mode 100644 index 000000000000..cb2c86ae63e7 --- /dev/null +++ b/Documentation/core-api/ioctl.rst @@ -0,0 +1,250 @@ +====================== +ioctl based interfaces +====================== + +:c:func:`ioctl` is the most common way for applications to interface +with device drivers. It is flexible and easily extended by adding new +commands and can be passed through character devices, block devices as +well as sockets and other special file descriptors. + +However, it is also very easy to get ioctl command definitions wrong, +and hard to fix them later without breaking existing applications, +so this documentation tries to help developers get it right. + +Command number definitions +========================== + +The command number, or request number, is the second argument passed to +the ioctl system call. While this can be any 32-bit number that uniquely +identifies an action for a particular driver, there are a number of +conventions around defining them. + +``include/uapi/asm-generic/ioctl.h`` provides four macros for defining +ioctl commands that follow modern conventions: ``_IOC``, ``_IOR``, +``_IOW``, and ``_IORW``. These should be used for all new commands, +with the correct parameters: + +_IO/_IOR/_IOW/_IOWR + The macro name determines whether the argument is used for passing + data into kernel (_IOW), from the kernel (_IOR), both (_IOWR) or is + not a pointer (_IOC). It is possible but not recommended to pass an + integer value instead of a pointer with _IOC. + +type + An 8-bit number, often a character literal, specific to a subsystem + or driver, and listed in :doc:`../ioctl/ioctl-number` + +nr + An 8-bit number identifying the specific command, unique for a give + value of 'type' + +size + The name of the data type pointed to by the argument, the command + number encodes the ``sizeof(size)`` value in a 13-bit or 14-bit integer, + leading to a limit of 8191 bytes for the maximum size of the argument. + Note: do not pass sizeof(type) type into _IOR/IOW, as that will lead + to encoding sizeof(sizeof(type)), i.e. sizeof(size_t). + + +Interface versions +================== + +Some subsystems use version numbers in data structures to overload +commands with different interpretations of the argument. + +This is generally a bad idea, since changes to existing commands tend +to break existing applications. + +A better approach is to add a new ioctl command with a new number. The +old command still needs to be implemented in the kernel for compatibility, +but this can be a wrapper around the new implementation. + +Return code +=========== + +ioctl commands can return negative error codes as documented in errno(3), +these get turned into errno values in user space. On success, the return +code should be zero. It is also possible but not recommended to return +a positive 'long' value. + +When the ioctl callback is called with an unknown command number, the +handler returns either -ENOTTY or -ENOIOCTLCMD, which also results in +-ENOTTY being returned from the system call. Some subsystems return +-ENOSYS or -EINVAL here for historic reasons, but this is wrong. + +Prior to Linux-5.5, compat_ioctl handlers were required to return +-ENOIOCTLCMD in order to use the fallback conversion into native +commands. As all subsystems are now responsible for handling compat +mode themselves, this is no longer needed, but it may be important to +consider when backporting bug fixes to older kernels. + +Timestamps +========== + +Traditionally, timestamps and timeout values are passed as ``struct +timespec`` or ``struct timeval``, but these are problematic because of +incompatible definitions of these structures in user space after the +move to 64-bit time_t. + +The __kernel_timespec type can be used instead to be embedded in other +data structures when separate second/nanosecond values are desired, +or passed to user space directly. This is still not ideal though, +as the structure matches neither the kernel's timespec64 nor the user +space timespec exactly. The get_timespec64() and put_timespec64() helper +functions canbe used to ensure that the layout remains compatible with +user space and the padding is treated correctly. + +As it is cheap to convert seconds to nanoseconds, but the opposite +requires an expensive 64-bit division, a simple __u64 nanosecond value +can be simpler and more efficient. + +Timeout values and timestamps should ideally use CLOCK_MONOTONIC time, +as returned by ``ktime_get_ns()`` or ``ktime_get_ts64()``. Unlike +CLOCK_REALTIME, this makes the timestamps immune from jumping backwards +or forwards due to leap second adjustments and clock_settime() calls. + +``ktime_get_real_ns()`` can be used for CLOCK_REALTIME timestamps that +may be required for timestamps that need to be persistent across a reboot +or between multiple machines. + +32-bit compat mode +================== + +In order to support 32-bit user space running on a 64-bit machine, each +subsystem or driver that implements an ioctl callback handler must also +implement the corresponding compat_ioctl handler. + +As long as all the rules for data structures are followed, this is as +easy as setting the .compat_ioctl pointer to a helper function such as +``compat_ptr_ioctl()`` or ``blkdev_compat_ptr_ioctl``. + +compat_ptr() +------------ + +On the s/390 architecture, 31-bit user space has ambiguous representations +for data pointers, with the upper bit being ignored. When running such +a process in compat mode, the ``compat_ptr()`` helper must be used to +clear the upper bit of a compat_uptr_t and turn it into a valid 64-bit +pointer. On other architectures, this macro only performs a cast to a +``void __user *`` pointer. + +In an compat_ioctl() callback, the last argument is an unsigned long, +which can be interpreted as either a pointer or a scalar depending on +the command. If it is a scalar, then compat_ptr() must not be used, to +ensure that the 64-bit kernel behaves the same way as a 32-bit kernel +for arguments with the upper bit set. + +The compat_ptr_ioctl() helper can be used in place of a custom +compat_ioctl file operation for drivers that only take arguments that +are pointers to compatible data structures. + +Structure layout +---------------- + +Compatible data structures have the same layout on all architectures, +avoiding all problematic members: + +* ``long`` and ``unsigned long`` are the size of a register, so + they can be either 32 bit or 64 bit wide and cannot be used in portable + data structures. Fixed-length replacements are ``__s32``, ``__u32``, + ``__s64`` and ``__u64``. + +* Pointers have the same problem, in addition to requiring the + use of ``compat_ptr()``. The best workaround is to use ``__u64`` + in place of pointers, which requires a cast to ``uintptr_t`` in user + space, and the use of ``u64_to_user_ptr()`` in the kernel to convert + it back into a user pointer. + +* On the x86-32 (i386) architecture, the alignment of 64-bit variables + is only 32 bit, but they are naturally aligned on most other + architectures including x86-64. This means a structure like + + :: + + struct foo { + __u32 a; + __u64 b; + __u32 c; + }; + + has four bytes of padding between a and b on x86-64, plus another four + bytes of padding at the end, but no padding on i386, and it needs a + compat_ioctl conversion handler to translate between the two formats. + + To avoid this problem, all structures should have their members + naturally aligned, or explicit reserved fields added in place of the + implicit padding. + +* On ARM OABI user space, 16-bit member variables have 32-bit + alignment, making them incompatible with modern EABI kernels. + Conversely, on the m68k architecture, all struct members have at most + 16-bit alignment. These rarely cause problems as neither ARM-OABI nor + m68k are supported by any compat mode, but for consistency, it is best + to completely avoid 16-bit member variables. + + +* Bitfields and enums generally work as one would expect them to, + but some properties of them are implementation-defined, so it is better + to avoid them completely in ioctl interfaces. + +* ``char`` members can be either signed or unsigned, depending on + the architecture, so the __u8 and __s8 types should be used for 8-bit + integer values, though char arrays are clearer for fixed-length strings. + +Information leaks +================= + +Uninitialized data must not be copied back to user space, as this can +cause an information leak, which can be used to defeat kernel address +space layout randomization (KASLR), helping in an attack. + +As explained for the compat mode, it is best to not avoid any padding in +data structures, but if there is already padding in existing structures, +the kernel driver must be careful to zero out the padding using +``memset()`` or similar before copying it to user space. + +Subsystem abstractions +====================== + +While some device drivers implement their own ioctl function, most +subsystems implement the same command for multiple drivers. Ideally the +subsystem has an .ioctl() handler that copies the arguments from and +to user space, passing them into subsystem specific callback functions +through normal kernel pointers. + +This helps in various ways: + +* Applications written for one driver are more likely to work for + another one in the same subsystem if there are no subtle differences + in the user space ABI. + +* The complexity of user space access and data structure layout at done + in one place, reducing the potential for implementation bugs. + +* It is more likely to be reviewed by experienced developers + that can spot problems in the interface when the ioctl is shared + between multiple drivers than when it is only used in a single driver. + +Alternatives to ioctl +===================== + +There are many cases in which ioctl is not the best solution for a +problem. Alternatives include + +* System calls are a better choice for a system-wide feature that + is not tied to a physical device or constrained by the file system + permissions of a character device node + +* netlink is the preferred way of configuring any network related + objects through sockets. + +* debugfs is used for ad-hoc interfaces for debugging functionality + that does not need to be exposed as a stable interface to applications. + +* sysfs is a good way to expose the state of an in-kernel object + that is not tied to a file descriptor. + +* configfs can be used for more complex configuration than sysfs + +* A custom file system can provide extra flexibility with a simple + user interface but add a lot of complexity in the implementation.