From patchwork Thu May 4 07:31:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9710909 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 D8E4560362 for ; Thu, 4 May 2017 07:31:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB89A28682 for ; Thu, 4 May 2017 07:31:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFCD528687; Thu, 4 May 2017 07:31:51 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 4C19428682 for ; Thu, 4 May 2017 07:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751485AbdEDHbu (ORCPT ); Thu, 4 May 2017 03:31:50 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35593 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752545AbdEDHbu (ORCPT ); Thu, 4 May 2017 03:31:50 -0400 Received: by mail-pf0-f172.google.com with SMTP id v14so3725115pfd.2 for ; Thu, 04 May 2017 00:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=64DoXCQInlKPN08Z/mWWF/TCzCNQFkKdKp2Q7nlntz0=; b=tkYYtXgjSsyamelCKnJTi1PvVF3pup3ZrcPYLOuG9wqoGx6GduW4v0unOslUfWVT4x mo2CaL93ksqMNenw8LulhXJabMXZzSyJOuDO9L5/6qCboSYV0A2F8c6f50n39MxiVLtU /2XE/6wicb5KXznGZOV/IPjjbHdKkRiumL88naXScJX26kPwUIzXCvoKogkdOdVXcJ5r Jwh7PhnnGdGRN+pae3a3GcjgK3Lp8dmL4gxNrzaJ76HKUhms2UAa6aaYqCs12pCwwQ0F SYU3RyQ75DcRmRQ8RKPmghJxonz92e9e83lbjiDcZMityqJyqD2jQDqQYyg99T8MGeRD RQzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=64DoXCQInlKPN08Z/mWWF/TCzCNQFkKdKp2Q7nlntz0=; b=gAwyOsOPfAR9PBkWBps92TVGIRH/kEo8jhdBkdg2E6Edz7c6kR6VVJzU1U/hzEo4ZB 7jxtFun3BB+/rvTYfwwRfDRq5ql/rNBtVXL1kWUSFcdR7kWnNyXm5Yio/N9n1EnmZ6oZ 38esikw4NNFD9SqjxCMb+rQe5DoCAViUiPBVq6vrmWp682HzNi07EELhfkt9nvpk/pwM pkS0EZTABwsR/70srCbgQ7bZZH4yQ39njT04OHvN373ErqzQkY0exgmt9oM7SM4bEQpn AvTwPUhnz31zdJwUNTWwg0HMgHL3F29vfcrMuxXAjMAAwMMfzOm+NokG8jARTG7OY4Z1 jwig== X-Gm-Message-State: AN3rC/5s9MHVSqdrdJRT6WRcyx3YhKszLvgh8FOtiICd+5JgAavQLTOf 0ZjJ8vcQvVgwBUPi X-Received: by 10.98.192.150 with SMTP id g22mr9524225pfk.134.1493883109342; Thu, 04 May 2017 00:31:49 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:1d23]) by smtp.gmail.com with ESMTPSA id q6sm2272168pfq.18.2017.05.04.00.31.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 00:31:48 -0700 (PDT) From: Omar Sandoval To: Jens Axboe , linux-block@vger.kernel.org Cc: Bart Van Assche , kernel-team@fb.com Subject: [PATCH v2 07/12] blk-mq: Do not invoke queue operations on a dead queue Date: Thu, 4 May 2017 00:31:29 -0700 Message-Id: <71712db1ecbe0432055c4976314a57485fff7f18.1493882751.git.osandov@fb.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bart Van Assche In commit e869b5462f83 ("blk-mq: Unregister debugfs attributes earlier"), we shuffled the debugfs cleanup around so that the "state" attribute was removed before we freed the blk-mq data structures. However, later changes are going to undo that, so we need to explicitly disallow running a dead queue. [Omar: rebased and updated commit message] Signed-off-by: Omar Sandoval Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- block/blk-mq-debugfs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 1579af6fcbed..347fbb8e059c 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -102,6 +102,14 @@ static ssize_t queue_state_write(void *data, const char __user *buf, struct request_queue *q = data; char opbuf[16] = { }, *op; + /* + * The "state" attribute is removed after blk_cleanup_queue() has called + * blk_mq_free_queue(). Return if QUEUE_FLAG_DEAD has been set to avoid + * triggering a use-after-free. + */ + if (blk_queue_dead(q)) + return -ENOENT; + if (count >= sizeof(opbuf)) { pr_err("%s: operation too long\n", __func__); goto inval;