Received: by 10.192.165.156 with SMTP id m28csp604139imm; Tue, 17 Apr 2018 16:13:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx48N6zBK+1hx60pp1thEm6dpiYR4oWAaYqLqJ+aPvlAxzbYy82K2EV7yh87oyc8AG0YEIZY7 X-Received: by 10.167.128.81 with SMTP id y17mr3566420pfm.194.1524006827282; Tue, 17 Apr 2018 16:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524006827; cv=none; d=google.com; s=arc-20160816; b=s2nEftCCjpPR+gnvJYKiKhBklKz6VGnbilWa3PACgJQmVQ6kDE/XYHAkASUTMn07Th rFPCJZ1XXmLmROeEuWEP61noE6Xi1QyZ8Pu1k98ZzCXAHfPqpjhfKFD3iFFgIelKUZ5/ QT9de96Grb/4rBG9ed/vFjkI+x92vXYnV+R49sz6xDJZz6VD6Xai6patFT5vSkalzpxR FLtgDrGYMApFy934meycyMbvFO5JP2luOUWyaYKMKOEpuzSw0MDgVEsGGOA1vttz02hP dXDVZ8XPzY7oJ9IDNB/cfEX23rh7ZgSd3fYMiMuPVnm6bneZHnohLOq7fZeS4sHhzi8Y K7oA== 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:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=/qv4PZEbKxeqiibass7dnA5QOkY05w5qj8ZET3/nQDE=; b=aRy+IQ4FmjqprmNzyhPdFIXb5/NB13HxK39KmoCiQzXYVLFmPK6pkxJSeSBhlTU5ty mfTU2c6Bot6n3nkACcJ8E1c+bDpa+7iy939RKH7qQ9SECT8wVzSCoSejgNqogba9rcNc N9IkYRx74ZVWUODJviqx2uiRDJu3NnqrQR2Pc6pswDcgEUVUs0SfLlAjlINShMGijocy wAOPlfZ/H7wVmlwHkiFP6PtMfcY+opvHgeNRPpPHZauNa2gSr1pY89VLA5NIM4Db4sQY f6+i1rkqZjYMVzwPv/U4IpK329gk0I/cPJI6bkLOAFferxTSZoXaO4fY5NQGO3CqlBg8 V2Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=cqJFD4uD; 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 h1si9407179pgs.169.2018.04.17.16.13.32; Tue, 17 Apr 2018 16:13:47 -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=cqJFD4uD; 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 S1751164AbeDQXMW (ORCPT + 99 others); Tue, 17 Apr 2018 19:12:22 -0400 Received: from mail-pl0-f48.google.com ([209.85.160.48]:39336 "EHLO mail-pl0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752707AbeDQXMV (ORCPT ); Tue, 17 Apr 2018 19:12:21 -0400 Received: by mail-pl0-f48.google.com with SMTP id e7-v6so12852551plt.6 for ; Tue, 17 Apr 2018 16:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/qv4PZEbKxeqiibass7dnA5QOkY05w5qj8ZET3/nQDE=; b=cqJFD4uDlMeWlsnTH/ghXAg5j8YijGzgKfgxd5TZpgp1GnHAWLKc39zYuXbHSOGGKS XPMS7Ep6zDWXnvrZl61pZwubYoKSrnuHJb8Sp/cNqxKdSi9RCaoIIRRy5GR3lvT2Md6L 8S+TamJHjKXCwZ+l62yfBFnvMgXCQT03SR5ShGJr3OGT+kMI/RT1xX+7M5eBVeaEKMoJ JT1iv5khpTEWuRAJahpO2XBzrXLP9C4+C8yduTAdYjB/zQIbb/29ShJJboJi3tfdB3Mt RKHaUVijrG6KXZ9z+r/Kc1ToLbn8BXbukdIRJ4TqDjc8gl62pHDCLCJlaaxGo53swObw wQGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/qv4PZEbKxeqiibass7dnA5QOkY05w5qj8ZET3/nQDE=; b=I36lI1Y2aRUOvLzYlPRX6sPOZk1CgTA2guGkFVTgtOIpWT7ZNN/G/thmpiJ3oVk3LJ K4WHHr9V2k2cb0Wys4WFkhhfVG/o/KZviHBAl5l3fmqExxXJP4Gs6Ifbhgx5bPqLoPe9 YIo7tYlDmCjyFTgYUQ62Em0P07SERijTLCHcFcn3DnXWPyw7w4tjSc3XwIx2k/A/QXMB ERdYkpVkJsZG15fH8kbFlPQiDal2CqHcLv9hCYFQESXpl0MuCQUXvB/kcrdsfkVPg4FW ltNd3DuTKsJPYY+kJBEDS4TZAtbdE6sqT32L6wTydN96h9msT0I3j5RCrTO9zgKVx/u7 7ccg== X-Gm-Message-State: ALQs6tBbnCsBvA1Nz2mBtD/556SMJ9nYTmx6lJDbPo7YqgpNtgS4aYU2 d+yJJtOFnNA7y0EjFLUj2fMMYcJ1HTo= X-Received: by 2002:a17:902:86:: with SMTP id a6-v6mr3768250pla.298.1524006740414; Tue, 17 Apr 2018 16:12:20 -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 e14sm9193816pfi.50.2018.04.17.16.12.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 16:12:19 -0700 (PDT) Subject: Re: usercopy whitelist woe in scsi_sense_cache 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> <8473f909-2123-0cfc-43b1-beba0b1aef9b@kernel.dk> <07f263ff-cea6-ac3c-944b-0f36fee8ba25@kernel.dk> <8b32e079-d4e6-3fea-a89d-ff856e4e13b1@kernel.dk> <0fbf2b13-8bae-c7c5-d930-ebaafdc72202@kernel.dk> From: Jens Axboe Message-ID: Date: Tue, 17 Apr 2018 17:12:11 -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: 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 5:06 PM, Kees Cook wrote: > On Tue, Apr 17, 2018 at 3:57 PM, Jens Axboe wrote: >> 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); > > It does! Excellent. :) Sweet! I'll add a comment and queue it up for 4.17 and mark for stable, with your annotations too. -- Jens Axboe