Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1040974imm; Fri, 15 Jun 2018 10:11:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK/he1zBkuVGQ2MLx7mKfWa27Cdc0fM5r7Y3qAzfn3iNbcFjJQCzy9BfFghhRcV+jYydMJS X-Received: by 2002:a65:611a:: with SMTP id z26-v6mr2345577pgu.61.1529082687951; Fri, 15 Jun 2018 10:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529082687; cv=none; d=google.com; s=arc-20160816; b=JKcnfrCk7RW69WjnlYRwaR5e9idcKznWUJUUTkRi6LgcfixPyPtlW7pAa0VWPr6W/K DclBDM7XPbTPKlsUVq5DqzEuKMaNI1JXSThMgJ0Pw9db7CpSOFH9CuXNqHnim5MQWpBi dHRCQFCeMw9XpD+mwcQTd8k8GZlFKS7Wn/C/C/Fw6PTNKguLO71D/63fHDxZzb+Ozc/5 xmqDUxtAhjSwkSCYhLV5PVqVsTCXFh+QU9JoT6beSTjekcT0khHLnzcOM2ad3SNMhuAq fALV6NGHU5mZTLrwoKpZk0Wg+W++PzWK+gLhFTlPzceisxzIV/fxBKRTPcRqW4amfYZB d7Ug== 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:arc-authentication-results; bh=e1iQTgxbyxik7JNXW9naYt8fgCX76krXqoaqPyowDWs=; b=D2RGeudFa+ZvV2Zf090F39Yq8X1h0JPrtb8LlCDsZmEJwG94kfroY8R2BLzTZvmBqL MAh6JDIqSYpmyTPsADht6HQXL/XSJyYpST4KGyXDD7JMnBxPWGAl+0sRDVPU97qRr0DX IhRUZE/JpibGu48XIxcyl3y2kThr/T/MPGPHAoSq7ZfRW/jmJhlJ2RlUwBCefXcESusT mS5Q+EJWymZTKO88GellOGIb+jdqEhwnT9zV33GuReaT3XWujClB+UZqunLzW+GD+yAU aENnA3Al1PM9TSbPUkiMaW7DMxe3wZuiKLmf9QOay7f54ReebNgnwA4Mlv6pPxKpGkTK pzHw== 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 t25-v6si8391666pfl.344.2018.06.15.10.11.12; Fri, 15 Jun 2018 10:11:27 -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 S965774AbeFORKp (ORCPT + 99 others); Fri, 15 Jun 2018 13:10:45 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:40772 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756005AbeFORKm (ORCPT ); Fri, 15 Jun 2018 13:10:42 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fTsF7-0006W7-JI; Fri, 15 Jun 2018 17:10:33 +0000 Date: Fri, 15 Jun 2018 18:10:33 +0100 From: Al Viro To: Jann Horn Cc: axboe@kernel.dk, fujita.tomonori@lab.ntt.co.jp, dgilbert@interlog.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, kernel list , Kernel Hardening , security@kernel.org Subject: Re: [PATCH] sg, bsg: mitigate read/write abuse, block uaccess in release Message-ID: <20180615171033.GG30522@ZenIV.linux.org.uk> References: <20180615152335.208202-1-jannh@google.com> <20180615164009.GD30522@ZenIV.linux.org.uk> <20180615165310.GF30522@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180615165310.GF30522@ZenIV.linux.org.uk> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 15, 2018 at 05:53:10PM +0100, Al Viro wrote: > On Fri, Jun 15, 2018 at 06:44:51PM +0200, Jann Horn wrote: > > On Fri, Jun 15, 2018 at 6:40 PM Al Viro wrote: > > > > > > On Fri, Jun 15, 2018 at 05:23:35PM +0200, Jann Horn wrote: > > > > > > > I've mostly copypasted ib_safe_file_access() over as > > > > scsi_safe_file_access() because I couldn't find a good common header - > > > > please tell me if you know a better way. > > > > The duplicate pr_err_once() calls are so that each of them fires once; > > > > otherwise, this would probably have to be a macro. > > > > > > > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > > > > Cc: > > > > Signed-off-by: Jann Horn > > > > --- > > > > > > WTF do you mean, in ->release()? That makes no sense whatsoever - > > > what kind of copy_{to,from}_user() would be possible in there? > > > > bsg_release -> bsg_put_device -> bsg_complete_all_commands -> > > blk_complete_sgv4_hdr_rq -> bsg_scsi_complete_rq -> copy_to_user. > > I don't think that was intentional. > > > > Basically, the sense buffer is copied to a userspace address supplied > > in the previous ->write() when you ->read() the reply. But when you > > ->release() the file without reading the reply, they have to clean it > > up, and for that, they reuse the same code they use for ->read() - so > > the sense buffer is written to userspace on ->release(). > > Pardon me, that has only one fix - git rm. This is too broken for words - > if your reading is correct, the interface is unsalvagable. I hope you > *are* misreading it, but if not... how did that insanity get through > review at merge time? AFAICS, it went in as part of commit 3d6392cfbd7d "bsg: support for full generic block layer SG v3", so your 2.6.12-rc2 is too old...