From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1402C5CFC1 for ; Fri, 15 Jun 2018 17:10:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FFC1208AF for ; Fri, 15 Jun 2018 17:10:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FFC1208AF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ZenIV.linux.org.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965881AbeFORKp (ORCPT ); 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...