Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1288666ybg; Fri, 18 Oct 2019 15:16:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxF6mIYlwQXdNyR21hvDXlapG7zBN6eeha30sgAMR3vlMn+Ak1EJBdwpekcbbupJV0j25b X-Received: by 2002:a50:ed05:: with SMTP id j5mr12193568eds.251.1571437012585; Fri, 18 Oct 2019 15:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571437012; cv=none; d=google.com; s=arc-20160816; b=G8BCPZcAp3/3/scwJT72ht6kBjHBBsh1rA8G0/f955IbFDVVT2L2uHm/5jZKzHEZRp 843Pf1NaPTzKZm61lWCnchwguAX2r5XUoJLJAB2EZJcu+CYdpiXRM+e17L/RoYtLzzCx 9b/t7X1Nv/nrnwNpiABxQaUsf8X7yxvHhVQR+y777U0D/vind2S6HjWCd3JdVvE5Th9R dSW/zdzXOq6RLT3TKsNJ5WB4vyo64XVQJ8/u3Nrjc25mDXslHTk4ziDl7zqJ/azWrsZi 6jM7bAXGD9Ut2t8BZFc+NdxbbH4KrkrdrGXYZai8D838V27qn7i8U/pfa/94PSywJkQL CIYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=baz6iC9b5YL8XDFNr+VOWdnY2n80H4BwtVKT/Rng9vE=; b=E3zBs61jot4DQW3bf9wUBQFPdZoetrfcXPpFzH6yMnDPg8wjVYtzfbBCef3RRb1uXu fQhK2d4lmAQCb3EVaZ0+sBysmYcba+x6rqa2ohit9BTAHE5Nn44Zx5MmaekaHtGaKc8g yB5gZGoRLr0NtnN3j2OpiwIyNgcDb8OpDyNUugbdDAxM7oMNPr63ilKhv9fdzDNWPT3N auA1xshoHNKSD1ZwKmOQNtMH2IlUx+fI/fFY1L4i3wwIdM78C/mpVD1eroteZds2ybZg UiSIBuqyE+kwnFaT7LxuKdwL9I3IAZ6eEGAUVz4p/owqv1kBEYwPRq7QEDopmNEMnTGk 91rA== 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 v6si292423ejh.280.2019.10.18.15.16.29; Fri, 18 Oct 2019 15:16:52 -0700 (PDT) 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 S2393663AbfJQThB (ORCPT + 99 others); Thu, 17 Oct 2019 15:37:01 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:44990 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728856AbfJQThA (ORCPT ); Thu, 17 Oct 2019 15:37:00 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iLBZz-0006VG-Aq; Thu, 17 Oct 2019 19:36:59 +0000 Date: Thu, 17 Oct 2019 20:36:59 +0100 From: Al Viro To: Linus Torvalds Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC][PATCHES] drivers/scsi/sg.c uaccess cleanups/fixes Message-ID: <20191017193659.GA18702@ZenIV.linux.org.uk> References: <20191010195504.GI26530@ZenIV.linux.org.uk> <20191011001104.GJ26530@ZenIV.linux.org.uk> <20191013181333.GK26530@ZenIV.linux.org.uk> <20191013191050.GL26530@ZenIV.linux.org.uk> <20191016202540.GQ26530@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191016202540.GQ26530@ZenIV.linux.org.uk> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 16, 2019 at 09:25:40PM +0100, Al Viro wrote: > FWIW, callers of __copy_from_user() remaining in the generic code: > 6) drivers/scsi/sg.c nest: sg_read() ones are memdup_user() in disguise > (i.e. fold with immediately preceding kmalloc()s). sg_new_write() - > fold with access_ok() into copy_from_user() (for both call sites). > sg_write() - lose access_ok(), use copy_from_user() (both call sites) > and get_user() (instead of the solitary __get_user() there). Turns out that there'd been outright redundant access_ok() calls (not even warranted by __copy_...) *and* several __put_user()/__get_user() with no checking of return value (access_ok() was there, handling of unmapped addresses wasn't). The latter go back at least to 2.1.early... I've got a series that presumably fixes and cleans the things up in that area; it didn't get any serious testing (the kernel builds and boots, smartctl works as well as it used to, but that's not worth much - all it says is that SG_IO doesn't fail terribly; I don't have any test setup for really working with /dev/sg*). IOW, it needs more review and testing - this is _not_ a pull request. It's in vfs.git#work.sg; individual patches are in followups. Shortlog/diffstat: Al Viro (8): sg_ioctl(): fix copyout handling sg_new_write(): replace access_ok() + __copy_from_user() with copy_from_user() sg_write(): __get_user() can fail... sg_read(): simplify reading ->pack_id of userland sg_io_hdr_t sg_new_write(): don't bother with access_ok sg_read(): get rid of access_ok()/__copy_..._user() sg_write(): get rid of access_ok()/__copy_from_user()/__get_user() SG_IO: get rid of access_ok() drivers/scsi/sg.c | 98 ++++++++++++++++++++++++++++++++---------------------------------------------------------------- 1 file changed, 32 insertions(+), 66 deletions(-)