Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp801753pxb; Thu, 24 Mar 2022 07:15:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1iru05t30PxlnrTvqlDxPeZ+QhESDQcmzpg/K1AOyUKeOlxk6U0WENHuai6qNs2CCl9js X-Received: by 2002:a05:6870:9612:b0:ce:c0c9:658 with SMTP id d18-20020a056870961200b000cec0c90658mr6484966oaq.170.1648131342750; Thu, 24 Mar 2022 07:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648131342; cv=none; d=google.com; s=arc-20160816; b=BjpKqNzgp+9I0uQxcVys6SwB2ybtN2tfw/iGRHRzdPyuiBVHKFI+fefW0e6h4MMR7n +PS0gEQmv6HfxdTIW5xMAQy7uwbaTcKE8twBYkAmmY1sLqfVqTGpqvq37U3bk2XgEJs0 9vz380Tskro4E2EqckzLTvbDVmrVyjaBaT+SoG8nTku4upKFHuKq6r7+1Jj7LyZNURsq 121ZddCvF9XaGVU8tu1Br/zvuxSiPM83v3Tij2WJ0Os0Q0qPO1F6FOdeXk3b0sjcXe1l LNlpCgfuvM2kAhzpfNeGjxmYQbRUThHXMu2QYp33tSIq85/lxA0zHUyUWXc8uPyDzwvC ZJ8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tZzHA745yMNG0CGi0w7nKGLCvOOf60jkvqsbdnRb89M=; b=F8UPbTPy7zU+++VHEzu97leSuP+VjA93N1j32XCfRLO12giif4R6OPDlDsqSsHjSoh 02CwsRbTYUtigN5wcx4YmhcFHqgkED2sgcxu3IN2+dwCn6BtbBEfmuiNf4SoCUFyA4Om 0H3mAuvjZ23krEX5oU4WBXzmzKzkRtx3/20SBPxHinH0/1cYJy8hgqOqdziH0UT2wnF0 aP17mEdGxgweK0NjmHFJMd95P3/johGNnE+ejWNXBt7GEZhS7ISSrzBL70Mot4XyUAuJ R2sJdVRelpk5//SwcEG6eogJsQm5+Wy6sjutY9yJSdlGXXRgsCJ9kYUjZra5IU0IldYe 3RQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iNLTx1Mk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a056808158f00b002ef1d1e840dsi11737363oiw.261.2022.03.24.07.15.30; Thu, 24 Mar 2022 07:15:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iNLTx1Mk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238177AbiCWPmE (ORCPT + 99 others); Wed, 23 Mar 2022 11:42:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238021AbiCWPmC (ORCPT ); Wed, 23 Mar 2022 11:42:02 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A5153B578 for ; Wed, 23 Mar 2022 08:40:32 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id t5so1784892pfg.4 for ; Wed, 23 Mar 2022 08:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tZzHA745yMNG0CGi0w7nKGLCvOOf60jkvqsbdnRb89M=; b=iNLTx1MkU692XhbU/pjEg6oXIWD15fomaPRZ4oW3JJzH3KzlvOHBxqYr3RP16I8BsM PQB/aJJCoSn3Bf5C0iUtZUgR/DiaO2QauRmpfS9c/26CRq2dWzEV6G+MzRR7m7sDBrA9 9I1dVEv+ES/8kqvSV10MRviLD3mH5S69ZCr5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tZzHA745yMNG0CGi0w7nKGLCvOOf60jkvqsbdnRb89M=; b=ATLxm6PDpbrw26Bh4QPr5Eb0EFC3D2UcXEXJp6mOBQpwrhms6Iwr0GuqcpemxpsV8s 05XwAR0KJ3UkyQVyCrKdk/nRmSMkPU1tZ2s7aWdODiHCN3D6g6kSLNzboJ/w3h+kFTFi 3hLhZVxS6peABBjCOQw/MAtuvG6JOt3scfsMQB64WvQEI24sp39vU0Pe3HpiU1hEpPy9 vSpbiQYkOTmxwdSxzR/batq6iDWVmWrxxvkI53arSN7qmUOiwd27OEmnpeymsg3a/ydX esRDynhUyefNfQ5rqq1p3HmjiEpUWuEO5oqlvwjt4NsP+fv2Kvhqqhk2Sw1dgHo4DSh+ gr3g== X-Gm-Message-State: AOAM531Ucrn5Nh5HA8KpFC2fRHDnfYyrhpTnHpkLx30NO5F/+obTyKEY WQfuy+rY5QMegIrak3FXmzZJoTcW7BozZA== X-Received: by 2002:aa7:91d5:0:b0:4fa:6d3c:55d9 with SMTP id z21-20020aa791d5000000b004fa6d3c55d9mr544396pfa.41.1648050031778; Wed, 23 Mar 2022 08:40:31 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 2-20020a620502000000b004f6d2975cbesm304447pff.116.2022.03.23.08.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 08:40:31 -0700 (PDT) Date: Wed, 23 Mar 2022 08:40:30 -0700 From: Kees Cook To: Christoph Hellwig Cc: kernel test robot , "Martin K. Petersen" , Bart Van Assche , John Garry , LKML , lkp@lists.01.org, lkp@intel.com, "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [scsi] 6aded12b10: kernel_BUG_at_mm/usercopy.c Message-ID: <202203230809.D63BF9511@keescook> References: <20220320143453.GD6208@xsang-OptiPlex-9020> <20220323071409.GA25480@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220323071409.GA25480@lst.de> X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 23, 2022 at 08:14:10AM +0100, Christoph Hellwig wrote: > The actual warning is; > > [ 34.496096][ T331] usercopy: Kernel memory overwrite attempt detected to spans multiple pages (off set 0, size 6)! > > This is for the cmnd field in struct scsi_cmnd, which is allocated by > the block layer as part of the request allocator. So with a specific > packing it can legitimately span pages. > > Kees: how can we annotate that this is ok? The main problem is that CONFIG_HARDENED_USERCOPY_PAGESPAN=y is broken (and nothing should be setting it). This series removes it: https://lore.kernel.org/linux-hardening/20220110231530.665970-1-willy@infradead.org/ Matthew, what's the status of that series? Will it make the current merge window? As for the SCSI changes, I'm a bit worried about type confusion, as I don't see anything actually validating types/sizes when converting: static inline void *blk_mq_rq_to_pdu(struct request *rq) { return rq + 1; } But I guess that ship has sailed. :P Regardless, I'm concerned that disabling PAGESPAN will just uncover further checks, though. Where is allocation happening? The check is here: static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq, struct sg_io_hdr *hdr, fmode_t mode) { struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq); if (hdr->cmd_len < 6) return -EMSGSIZE; if (copy_from_user(scmd->cmnd, hdr->cmdp, hdr->cmd_len)) return -EFAULT; ... } I don't see any earlier marking for this copy_from_user(), so I assume the old allocation was a plain kmalloc(). For comparision, a related marking can be seen for a copy_to_user() case in commit 0afe76e88c57 ("scsi: Define usercopy region in scsi_sense_cache slab cache") I *think* the allocation is happening in scsi_ioctl_reset()? But that's a plain kmalloc(), so I'm not sure why PAGESPAN would have tripped... are there other allocation paths? -- Kees Cook