Received: by 10.192.165.156 with SMTP id m28csp532341imm; Tue, 17 Apr 2018 14:44:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx49avMFqKIlZsJR+nBjKcsEqosEAXVtByNEO3pXG6YKeHGL+E/iOsOiFsf9U0HogfKh/0aKH X-Received: by 2002:a17:902:76c3:: with SMTP id j3-v6mr3603266plt.257.1524001455130; Tue, 17 Apr 2018 14:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524001455; cv=none; d=google.com; s=arc-20160816; b=DHY3/qRmc3lXtsiNpZGfC396zXnIJOjdaI3Ag40kUtsAgUdoG0OvlMW21kkZJOTJUe EjDr3OX9ARDRkgz2rRYrhueSCfY4XpnCAcbGuKljccJ4iYbNI5SM0637f0OHEk9k3L4P DWoH6PpIuWeeWmCX5Njl4zlneUnuLJu2Zv6REDxW/doc2/4dUIshAQELbjyVRff1hg6l Ep4LHbtg1kWxQCYB/6dblkf1+ZnJ9NRCXvST3d/ovopcCBRhtVOHv10h7F05luch8Fxj 4mqrEntEZy6USlZbB8k2un5uTYBQcGgOuuW3f7WPP3hH0/oO6diNZYmuNLhhLnUK5Dqn Dx6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=9dCpSt7DBK7mg208B4/EKYEqUMduA2L2PeWie/72f2g=; b=o3nH/YVO9iE/nDTrA/RofmUvBJP0tC4i/BohaSt+l/7/LP+e0/Xz+780x8XOCFhM6k qWc1esFAg3+6meCgH2ZQfB8Ld1cJToAOyhfIWVnIomEnntv85qFpXiLi/GVB6l2oX162 aP71bCVtEyuSqjksmzwTGcd2sY3p44XHPHIXX2KuWkREBKfQcQo1UO+ojL7FJQ7NDc3g EUMhvx+UbkcHHATU32l1TQDWgZqAUY4XRv1rCIE/zJ1jo8wfzP/Bh8LPnjWWmKCLN1P5 fYipWsjBscib9/EZIodfAoIFPLDqlzcd54hNXWaqeB78sg4XA3Sa3IOilBqkjaMmgpRw jsJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bEDmnyXC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 142si12359750pgg.29.2018.04.17.14.44.01; Tue, 17 Apr 2018 14:44:15 -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=@chromium.org header.s=google header.b=bEDmnyXC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753196AbeDQVmX (ORCPT + 99 others); Tue, 17 Apr 2018 17:42:23 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34037 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752427AbeDQVmV (ORCPT ); Tue, 17 Apr 2018 17:42:21 -0400 Received: by mail-pf0-f194.google.com with SMTP id q9so12784239pff.1 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=AU0R2WZnA9qofh08R1dEagXLN76c2FOF7SuvQqxezjgCqmeynDhdVkYJjN0u9R/Zhs tabl4OyGIkw39zLvSoJjfWJOy3KGBfKOD4N3K6jHZZmLnZk7erymt/Xwm3RU5Wk0XkuG 4/7ISDSruTsKYeWD1XIGVwxsm4USOASQXUVf6cHl67iJ/kdbMfBJAcI80B5UYD4qYP/9 tvnyCjXtaSoSt4sJp+1ofVOk6t9BzyeHAeXiO+CGPU5JbdwkniUS6YnImeNJLjJCWFpq KvM7QzRW7+F7aexH1o2omBeDg8/8FgFsj3gAX3wrdLzIUhZdf1zG0iBZc32fs/5vVSu8 8f9g== X-Gm-Message-State: ALQs6tA+rXUBe078ZI+8whW7l6hYyB+i17Ala9Qz3oAZi4zlLqt7qcMU LzJm+yJXCQNEPId0uSUu9h3+rg== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)); } } -- 2.7.4 -- Kees Cook Pixel Security