From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753177AbdBIO0X convert rfc822-to-8bit (ORCPT ); Thu, 9 Feb 2017 09:26:23 -0500 Received: from smtp-out4.electric.net ([192.162.216.182]:51225 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753157AbdBIO0V (ORCPT ); Thu, 9 Feb 2017 09:26:21 -0500 From: David Laight To: "'Arnd Bergmann'" , Scott Bauer , Jonathan Derrick , Rafael Antognolli CC: Jens Axboe , "linux-kernel@vger.kernel.org" , "linux-nvme@lists.infradead.org" , "linux-block@vger.kernel.org" , Paul Mackerras , "linuxppc-dev@lists.ozlabs.org" Subject: RE: [PATCH] block: sed-opal: reduce stack size of ioctl handler Thread-Topic: [PATCH] block: sed-opal: reduce stack size of ioctl handler Thread-Index: AQHSglEFc8Q+Zu/xBk2sCKEzIQGBwqFgrpaQ Date: Thu, 9 Feb 2017 14:26:02 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6DB0281652@AcuExch.aculab.com> References: <20170208211546.2789607-1-arnd@arndb.de> In-Reply-To: <20170208211546.2789607-1-arnd@arndb.de> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Outbound-IP: 213.249.233.130 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuExch.aculab.com X-TLS: TLSv1:AES128-SHA:128 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann > Sent: 08 February 2017 21:15 > > When CONFIG_KASAN is in use, the sed_ioctl function uses unusually large stack, > as each possible ioctl argument gets its own stack area plus redzone: Why not do a single copy_from_user() at the top of sed_ioctl() based on the _IOC_DIR() and __IOC_SIZE() values? Something like: int sed_ioctl(..., unsigned int cmd, void __user *arg) { u64 buf[??]; /* or a union */ unsigned int cmd_sz = _IOC_SIZE(cmd); if (_IOC_DIR(cmd) & (_IOC_WRITE | _IOC_READ) && cmd_sz > sizeof buf) return -EINVAL; if (_IOC_DIR(cmd) & _IOC_WRITE) { if (copy_from_user(buf, arg, cmd_sz)) return -EFAULT; } else { if (IOC_DIR(cmd) & _IOC_READ)) memzero(buf, cmd_sz); } switch (cmd) { ... rval = ... ... } if (rval >= 0 && (_IOC_DIR(cmd) & _IOC_READ) && copy_to_user(arg, buf, cmd_sz)); return -EFAULT; return rval; } David