From patchwork Tue Apr 17 21:42:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10346943 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 4ED3E601D7 for ; Tue, 17 Apr 2018 21:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A5B628306 for ; Tue, 17 Apr 2018 21:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EDB42846F; Tue, 17 Apr 2018 21:42:24 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, 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 22D3F28306 for ; Tue, 17 Apr 2018 21:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753166AbeDQVmW (ORCPT ); Tue, 17 Apr 2018 17:42:22 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:45924 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeDQVmV (ORCPT ); Tue, 17 Apr 2018 17:42:21 -0400 Received: by mail-pf0-f195.google.com with SMTP id l27so12770207pfk.12 for ; Tue, 17 Apr 2018 14:42:21 -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:mime-version:content-disposition; bh=9dCpSt7DBK7mg208B4/EKYEqUMduA2L2PeWie/72f2g=; b=bEDmnyXCmuWKE6RnM+/MKzrudS9oOWe3wl7/Y0i2AlS37xUy7ABYGyz36WrqSTPjhU VG/fETuLpknziWgU0A8fpyGjNWvsLWg3MUPiZdeNyQPRvSG1OtL0eqs6yoK92tzCVFg3 nvFjJ8ZwtlmriGRshsQZvF1hlshg0XZLlESik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=9dCpSt7DBK7mg208B4/EKYEqUMduA2L2PeWie/72f2g=; b=Mhnyc/EH4BTJvYKTlzwN4Lhu3wCpOygmIQPGBrp959Hs5k2EV4nkYwQsm4wMXo0auf h8abT8UZVMdOPnC4KnBBOImdVFgUzgsX/aA6hVhHd3aYXHvEIL9kPgXFwHP8zIubmxrH /l4Li6niyvx8DwWGOdbEqQmLwbVSJlOZl8QYDfHkcrOjvM60dOdPyLz3CUfMpsWNLWxj eEeoqzyXh5DyhqCefiwe5HJ4QJACxceZH4Y2DmYkDhVQgz8W4YYmC3KD0YYZ6u53gW2C 1XVE9DkGNmWSmkcEdf0XxG3PkLkA39SddYGc1FoIspr2HjpNDb3hLQf0aEJ2IcIbLq3a 79kQ== X-Gm-Message-State: ALQs6tBDRgY+p119bZTZX8v/sVvivHDYTOgybSxjxMfICD06rulrAh2e qyvNsuWpo+3GmmNGCQmQjradsQ== X-Google-Smtp-Source: AIpwx49cKFS3nuEOhQIfyWMLHFkx6hz5aBC0ry1dnl/z+m9D63xwK6jph5bvtTCLUOabGp5o9rKGNg== X-Received: by 10.98.67.217 with SMTP id l86mr3472958pfi.40.1524001340765; Tue, 17 Apr 2018 14:42:20 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id y3sm25387807pgc.81.2018.04.17.14.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 14:42:19 -0700 (PDT) Date: Tue, 17 Apr 2018 14:42:18 -0700 From: Kees Cook To: Jens Axboe Cc: Oleksandr Natalenko , linux-kernel@vger.kernel.org, Paolo Valente , Bart Van Assche , David Windsor , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , linux-block@vger.kernel.org Subject: [PATCH] blk-mq: Clear out elevator private data Message-ID: <20180417214218.GA44753@beast> MIME-Version: 1.0 Content-Disposition: inline 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 Some elevators may not correctly check rq->rq_flags & RQF_ELVPRIV, and may attempt to read rq->elv fields. When requests got reused, this caused BFQ to think it already had a bfqq (rq->elv.priv[1]) allocated. This could lead to odd behaviors like having the sense buffer address slowly start incrementing. This eventually tripped HARDENED_USERCOPY and KASAN. This patch wipes all of rq->elv instead of just rq->elv.icq. While it shouldn't technically be needed, this ends up being a robustness improvement that should lead to at least finding bugs in elevators faster. Reported-by: Oleksandr Natalenko Fixes: bd166ef183c26 ("blk-mq-sched: add framework for MQ capable IO schedulers") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook --- In theory, BFQ needs to also check the RQF_ELVPRIV flag, but I'll leave that to Paolo to figure out. Also, my Fixes line is kind of a best-guess. This is where icq was originally wiped, so it seemed as good a commit as any. --- block/blk-mq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)); } }