Received: by 10.192.165.156 with SMTP id m28csp590819imm; Tue, 17 Apr 2018 15:58:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+8wEuvF8omEZRFANBkaiFSgOmgs0BKEc9a0NMGyWfaubt/nrYFs9jaBTXM0ukcVR47dEe+ X-Received: by 10.99.126.69 with SMTP id o5mr3201343pgn.18.1524005917151; Tue, 17 Apr 2018 15:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524005917; cv=none; d=google.com; s=arc-20160816; b=aPgI1qQyHcIdEbk9Qxm3kStM/uCy+fp8b2kfEH4vVHcwnbq+1cPhydoUgbzQC8eYB2 ogSKjps7JF0U+aEW5LKcXoykb8h+TcXBj7BkZGko9w6ZiMq2E+otdE1W+sFEWl5zBBh3 Undj6iGeYQaV8gFbUuEZoINXYCXsaYwmqEP/jgNuVDOCDWdUhNaTMkAJQf11Wwu1eLwH Vrz6JAw3ngyYN3KRSTvw7x7N+oo29um8ivjLaEqHlyEzkkupbeGTIykCeK3Vc8rdYIfs u17ncncz+4NStDGLtdTcOb9n8tI06gUePPO3MCvHdyw0OC57JfZN5GCUSCPH9G/h0nYz 4Rug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature :arc-authentication-results; bh=l2ZJAUQKw5qSZoKvIGmrioc33cGUi3Kb6UQL145DRt4=; b=ICBeCkA6L+kY2deplzAuAzIYlkF/U5cRXPGoBjdcVcTH1iMDtwXcqV6IqGE480qLb0 gCRIflNHNqWfrqjaU/SAHu7zzJqFzw8+OgCc/M7XL3znEQCp85lI6gDdKvgDZhaiJ9rp 3J5C+1QWD4H9177ktq8wmSodaJNssFYhiqWUYYvOo438Z2Ru1AiLIm2zxtt52CTuaxPi tfvwTk0ckuZiwmpqGyw28DMxKU/53Sqx2MyLfVqoZrHKJnvliw+JY/b3SDMN+ufpmsVz scajj87mpdTD5l363EwFKFXC9Jwuzd4/TOTpwKPf7QnKyDJO7GinL11IiYZfhQ94Orbd b7ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=a5ZuFclp; 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 7-v6si15108071pll.132.2018.04.17.15.58.23; Tue, 17 Apr 2018 15:58:37 -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; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=a5ZuFclp; 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 S1752819AbeDQW5R (ORCPT + 99 others); Tue, 17 Apr 2018 18:57:17 -0400 Received: from mail-pg0-f47.google.com ([74.125.83.47]:36033 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752655AbeDQW5N (ORCPT ); Tue, 17 Apr 2018 18:57:13 -0400 Received: by mail-pg0-f47.google.com with SMTP id i6so370449pgv.3 for ; Tue, 17 Apr 2018 15:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=l2ZJAUQKw5qSZoKvIGmrioc33cGUi3Kb6UQL145DRt4=; b=a5ZuFclpW5CjWjS6E9GjXdxkS+2yDKU7f9f/o1UsrY6Y3/93W4VIUr+5FNFoj+qKtr CjTmz+QhJakTdBld5dWdu3RRu2aP3sJdO56ljdTo2VwBurY+tnKXE6TqwGKUl2gd7zXR BSHm2p1XGuGCnvGWnVZ2finvtCKJlISVPT+0zbCrQwlqisxBRIEWNyzFRQUBrr4rzhwZ 1tPhcZxJhxhHdRjh4FArXXQmQm63vb4OKXKj2xZueewvOTUfYpowwdp1LVEe7Sr37GUZ G1vQubhYbjxUkGNHq/M5fEghgnxSLyFd/QuZAT58kCpJYMQHDcAWPAgzh/DtyXFzjRY5 vAfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=l2ZJAUQKw5qSZoKvIGmrioc33cGUi3Kb6UQL145DRt4=; b=rw8jRkF3FzdHEBSTHXBqVE/Sc8OaWjr1GnFFUZaWTt7BUDng4JNc5v7qMchSNxiEGp xFhcXVZRM3iS9JzrfH8L6ZAiKxPstvC9xaDhNVp+UO4k/v6Tt9mcYHqA9qpnjavuKOPh Bkub6byuz09R5JbUBmI2i7hN0u1RsVvzS7zISO+i7Z3hi1gvwaIdN/T+YTDEQAK5tuMi 7CJOCM+N/A1VkccHvaY+lGFAs4D7bSvQDDhdc0ayy/ndTFuYRnfdpXakFjRmihXakRur uGK/wk76vPxSjm+8a5TfIE5Po7fPv02tpEM+i9Zsno93i8PaZ26eXrJsgTBapRCgCOaM iDmQ== X-Gm-Message-State: ALQs6tDEm+KBgoM54CcjG0bMic6wnC8l7xP9tJQIZPSzpuJKdHygGq94 +6R+gDvxjmSoICDe5v7e9O+ixQ== X-Received: by 10.101.82.133 with SMTP id y5mr3201131pgp.27.1524005832957; Tue, 17 Apr 2018 15:57:12 -0700 (PDT) Received: from [192.168.1.211] (107.191.0.158.static.utbb.net. [107.191.0.158]) by smtp.gmail.com with ESMTPSA id t137sm30116351pgc.16.2018.04.17.15.57.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 15:57:10 -0700 (PDT) Subject: Re: usercopy whitelist woe in scsi_sense_cache From: Jens Axboe To: Kees Cook Cc: Paolo Valente , Oleksandr Natalenko , Bart Van Assche , David Windsor , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, LKML , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , linux-block@vger.kernel.org References: <10360653.ov98egbaqx@natalenko.name> <2864697.7uzmEJovl2@natalenko.name> <8473f909-2123-0cfc-43b1-beba0b1aef9b@kernel.dk> <07f263ff-cea6-ac3c-944b-0f36fee8ba25@kernel.dk> <8b32e079-d4e6-3fea-a89d-ff856e4e13b1@kernel.dk> Message-ID: <0fbf2b13-8bae-c7c5-d930-ebaafdc72202@kernel.dk> Date: Tue, 17 Apr 2018 16:57:08 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <8b32e079-d4e6-3fea-a89d-ff856e4e13b1@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/17/18 3:48 PM, Jens Axboe wrote: > On 4/17/18 3:47 PM, Kees Cook wrote: >> On Tue, Apr 17, 2018 at 2:39 PM, Jens Axboe wrote: >>> On 4/17/18 3:25 PM, Kees Cook wrote: >>>> On Tue, Apr 17, 2018 at 1:46 PM, Kees Cook wrote: >>>>> I see elv.priv[1] assignments made in a few places -- is it possible >>>>> there is some kind of uninitialized-but-not-NULL state that can leak >>>>> in there? >>>> >>>> Got it. This fixes it for me: >>>> >>>> diff --git a/block/blk-mq.c b/block/blk-mq.c >>>> index 0dc9e341c2a7..859df3160303 100644 >>>> --- a/block/blk-mq.c >>>> +++ b/block/blk-mq.c >>>> @@ -363,7 +363,7 @@ static struct request *blk_mq_get_request(struct >>>> request_queue *q, >>>> >>>> rq = blk_mq_rq_ctx_init(data, tag, op); >>>> if (!op_is_flush(op)) { >>>> - rq->elv.icq = NULL; >>>> + memset(&rq->elv, 0, sizeof(rq->elv)); >>>> if (e && e->type->ops.mq.prepare_request) { >>>> if (e->type->icq_cache && rq_ioc(bio)) >>>> blk_mq_sched_assign_ioc(rq, bio); >>>> @@ -461,7 +461,7 @@ void blk_mq_free_request(struct request *rq) >>>> e->type->ops.mq.finish_request(rq); >>>> if (rq->elv.icq) { >>>> put_io_context(rq->elv.icq->ioc); >>>> - rq->elv.icq = NULL; >>>> + memset(&rq->elv, 0, sizeof(rq->elv)); >>>> } >>>> } >>> >>> This looks like a BFQ problem, this should not be necessary. Paolo, >>> you're calling your own prepare request handler from the insert >>> as well, and your prepare request does nothing if rq->elv.icq == NULL. >> >> I sent the patch anyway, since it's kind of a robustness improvement, >> I'd hope. If you fix BFQ also, please add: > > It's also a memset() in the hot path, would prefer to avoid that... > The issue here is really the convoluted bfq usage of insert/prepare, > I'm sure Paolo can take it from here. Does this fix it? diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index f0ecd98509d8..d883469a1582 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -4934,8 +4934,11 @@ static void bfq_prepare_request(struct request *rq, struct bio *bio) bool new_queue = false; bool bfqq_already_existing = false, split = false; - if (!rq->elv.icq) + if (!rq->elv.icq) { + rq->elv.priv[0] = rq->elv.priv[1] = NULL; return; + } + bic = icq_to_bic(rq->elv.icq); spin_lock_irq(&bfqd->lock); -- Jens Axboe