From patchwork Sun Feb 19 07:15:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 9581479 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 E87416043A for ; Sun, 19 Feb 2017 07:16:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C439A2872E for ; Sun, 19 Feb 2017 07:16:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6D572879B; Sun, 19 Feb 2017 07:16:27 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 3D4192872E for ; Sun, 19 Feb 2017 07:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751028AbdBSHQM (ORCPT ); Sun, 19 Feb 2017 02:16:12 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:58426 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750978AbdBSHQL (ORCPT ); Sun, 19 Feb 2017 02:16:11 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1cfLiR-0004EU-9R; Sun, 19 Feb 2017 07:15:34 +0000 Date: Sun, 19 Feb 2017 07:15:27 +0000 From: Al Viro To: James Bottomley Cc: Dmitry Vyukov , Johannes Thumshirn , "Martin K. Petersen" , linux-scsi , LKML , syzkaller , Hannes Reinecke , Linus Torvalds Subject: Re: scsi: BUG in scsi_init_io Message-ID: <20170219071522.GI29622@ZenIV.linux.org.uk> References: <20170131092048.GB3687@linux-x5ow.site> <1485877311.3199.4.camel@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1485877311.3199.4.camel@linux.vnet.ibm.com> User-Agent: Mutt/1.7.1 (2016-10-04) 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 Tue, Jan 31, 2017 at 07:41:51AM -0800, James Bottomley wrote: > > Please-please-please, let's not use WARN for something that is not a > > kernel bug and is user-triggerable. > > It is a kernel bug and it should not be user triggerable, so it should > have a warn_on or bug_on. It means something called a data setup > function with no data. There's actually a root cause that patches like > this won't fix, can we find it? The root cause is unfixable without access to TARDIS and dose of antipsychotics sufficient to prevent /dev/sg API creation. What happens is that write to /dev/sg is given a request with non-zero ->iovec_count combined with zero ->dxfer_len. Or with ->dxferp pointing to an array full of empty iovecs. AFAICS, the minimal fix would be something like this: YAMissingSanityCheck in /dev/sg write permission to /dev/sg shouldn't be equivalent to the ability to trigger BUG_ON() while holding spinlocks... Cc: stable@vger.kernel.org Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index dbe5b4b95df0..121de0aaa6ad 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1753,6 +1753,10 @@ sg_start_req(Sg_request *srp, unsigned char *cmd) return res; iov_iter_truncate(&i, hp->dxfer_len); + if (!iov_iter_count(&i)) { + kfree(iov); + return -EINVAL; + } res = blk_rq_map_user_iov(q, rq, md, &i, GFP_ATOMIC); kfree(iov);