From patchwork Tue Jul 10 00:41:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 10515993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B8CAA604D4 for ; Tue, 10 Jul 2018 00:42:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7F2528CCE for ; Tue, 10 Jul 2018 00:42:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AF5528CD6; Tue, 10 Jul 2018 00:42:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2666D28CCE for ; Tue, 10 Jul 2018 00:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754599AbeGJAlu (ORCPT ); Mon, 9 Jul 2018 20:41:50 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:35920 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754582AbeGJAlq (ORCPT ); Mon, 9 Jul 2018 20:41:46 -0400 Received: by mail-io0-f196.google.com with SMTP id k3-v6so18749544iog.3; Mon, 09 Jul 2018 17:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IwSpVBpE0y2egaTgMUoAQt0MBSbqtHckdzgevhex1qo=; b=Pup+Aggqifwgt2WYJR5e6rVLfy4DqbietT6B2bCeKhXgoQ/kH6i5HR4j4gTWs5VVz8 EmrOeqcU492fXawEyfTVDNZl5tPbJL7AjLtO7zwL6FMZwu+1Wz8uat89NeZCE4z3MBhh /tnLYRvTl/Iee7jW9MKubmMalRt2KuRWSD9pQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IwSpVBpE0y2egaTgMUoAQt0MBSbqtHckdzgevhex1qo=; b=Bt+g9oWWvoLM3cv3rjL+9oyveq/RFkqnMJynaCNEW5NkCqxS08J7hOZ5Y9uusLiFVC AnIkzYvDLw3Lz42RAh8FYC+e7cqQnJdGu63Q/7kAQ8lt7+u9lFwqrlv/2I8xzcQiRkrP 0lpjrHsHqhlwRudUwHhF2c1NWyZSScA7lCmctKqMy5yhfUnD/fz0FgYCC+hQ/QCepd0z dynOAat60/DMuQteoztwHsX08eTZb3I04cVIthZZdQ1HUOAfz0mfXJY9WxlfRAhuQ8tz KH9GI6Bz0Eom9xoG9Dl1ApIcDGzYzZv0fd4kz68U0zK5vO1PYD3yn18H2yiSBHTvpMVe wGFw== X-Gm-Message-State: APt69E0UrKqjrLD4wlMpIy9ux1TkScg9Yv6+puQPv9NcxMIbBpPyCmxk +v0pm7r1Zpv+UJuzTCuJXFd5y3r7uoHe97oZvc8= X-Google-Smtp-Source: AAOMgpe1oZlJZ/ZkIQgyCfh036CM7qb6f8Q2HeBdRBiTOw5cDobowCi+d7jw+e9r3PSzhrUJWVw3HeU2TfxBWroX6DI= X-Received: by 2002:a6b:1502:: with SMTP id 2-v6mr20153538iov.203.1531183305992; Mon, 09 Jul 2018 17:41:45 -0700 (PDT) MIME-Version: 1.0 References: <1530913134.3135.2.camel@HansenPartnership.com> <1530940958.3135.4.camel@HansenPartnership.com> In-Reply-To: <1530940958.3135.4.camel@HansenPartnership.com> From: Linus Torvalds Date: Mon, 9 Jul 2018 17:41:34 -0700 Message-ID: Subject: Re: [GIT PULL] SCSI fixes for 4.18-rc3 To: James Bottomley Cc: Jann Horn , Andrew Morton , Linux SCSI List , Linux Kernel Mailing List Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Jul 6, 2018 at 10:22 PM James Bottomley wrote: > > We did discuss removing the r/w interface, but, as you say, it's been > around for ages so it's not clear what regressions would surface if we > did. So since nobody else followed up on this, the attached patch is what I was thinking of just committing. It removes the warnings from the access check, and just puts them (unconditionally) at the top of the read/write function instead. Hmm? Linus drivers/scsi/sg.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index cd2fdac000c9..09325b8fbc9f 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -222,18 +222,12 @@ static void sg_device_destroy(struct kref *kref); * This function provides protection for the legacy API by restricting the * calling context. */ -static int sg_check_file_access(struct file *filp, const char *caller) +static int sg_check_file_access(struct file *filp) { - if (filp->f_cred != current_real_cred()) { - pr_err_once("%s: process %d (%s) changed security contexts after opening file descriptor, this is not allowed.\n", - caller, task_tgid_vnr(current), current->comm); + if (filp->f_cred != current_real_cred()) return -EPERM; - } - if (uaccess_kernel()) { - pr_err_once("%s: process %d (%s) called from kernel context, this is not allowed.\n", - caller, task_tgid_vnr(current), current->comm); + if (uaccess_kernel()) return -EACCES; - } return 0; } @@ -421,11 +415,14 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) struct sg_header *old_hdr = NULL; int retval = 0; + pr_err_once("process %d (%s) does direct read on /dev/sg", + task_tgid_vnr(current), current->comm); + /* * This could cause a response to be stranded. Close the associated * file descriptor to free up any resources being held. */ - retval = sg_check_file_access(filp, __func__); + retval = sg_check_file_access(filp); if (retval) return retval; @@ -618,7 +615,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) unsigned char cmnd[SG_MAX_CDB_SIZE]; int retval; - retval = sg_check_file_access(filp, __func__); + pr_err_once("process %d (%s) does direct write on /dev/sg", + task_tgid_vnr(current), current->comm); + + retval = sg_check_file_access(filp); if (retval) return retval;