Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1876273pxk; Tue, 1 Sep 2020 09:48:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7heuP1149qdIc/mttb+CNtcVJL/ngY7GzCeft9W+H0HS5c9UbGNz5tG9j6z9Xl+SdJm36 X-Received: by 2002:a17:906:c2d2:: with SMTP id ch18mr2468745ejb.79.1598978897905; Tue, 01 Sep 2020 09:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598978897; cv=none; d=google.com; s=arc-20160816; b=qFpPt3uyZOkdXHcClnctkyQzd+lTZ/Mt+ctarxnyD130qQRnNOrHYJhGmCMqkJ9XV1 BS5Kw7EHCqT8RrlwmNgWm3UVG11XhuxK/h/HyeLCcWO/tx8uagKIWA4qwq0xkDBGr+49 5V8HulU8qys/EXJrjikOFhTrGRq56y6iOYnnYbVsB9IFoLK5jhsa/Z9wAdwvXwCYKLVL flH2GwAdZXpVRhQMOXEcjRHrxkC5B7Kk7xrrVZ9F2pTF50FZ+c1n6DCVziBFRaS75d7D VxAIH1PinJHODUePt7pC37PY5MRyBeIULncM8Je6ssl6tTx6jAKM2dLtMLMQKlcXf1oP Qk9Q== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YPscWljWi0HGx0/R3i+CyCtxf31i8Udd4K2AbUDFbnE=; b=wvSXmTPGOyjeIORF5iTgNZYP6PgMGNfODFMadturqlY3YH6SbQo3GU3PjqpVvCaQhx x409Adsy5N0OgKDhr89I3BgcllN7m7sQtmQ0oHAFZ0CweNEP3JcxALuJo3ofrH72/e4e KDfvS0/LRUJKLczZ4UlQ5DtfQSw7+kIjfg9N+HsyC1SOaZiBTThuvjIZrsMRC8Zf8slu fpDZm4Ay6P2nUquEIkIiA4sZG5c01Yrz3U5Tv26TvL8SHSc8QDhnzQJpyBhB99rlTfEc 6d1wsxFWLSstQDVWsY04HO/kjbwJJtG/I/IcI6PRMX7L5e6Bfd2M60xAJQB66YPNw/Cy 2lPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GfDlJzRC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k30si844881edk.76.2020.09.01.09.47.54; Tue, 01 Sep 2020 09:48:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GfDlJzRC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730504AbgIAQpP (ORCPT + 99 others); Tue, 1 Sep 2020 12:45:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:54542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730202AbgIAP1a (ORCPT ); Tue, 1 Sep 2020 11:27:30 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BBAE520684; Tue, 1 Sep 2020 15:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974050; bh=ps+HJouMxS0MKhtsq4HA6ltIRrGt1y5G3/30b95tvho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfDlJzRCdvuIzg1t/QIHgkNHVVFSrMjP0cg/NHqRyKcbPpeN0YGFTH9JWkhbUA3wT BvvhH8zlu7T5qZxOSJXQMv/AsXE3EeH80q+I5M0Q5wcSr9dgxnP72PMlqXn2Cz2g7f VsdEc8YNQGcqo/0P3fhE1zLkuv7VgesVQ3radtDU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luis Chamberlain , Christoph Hellwig , Bart Van Assche , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 024/214] blktrace: ensure our debugfs dir exists Date: Tue, 1 Sep 2020 17:08:24 +0200 Message-Id: <20200901150954.130300809@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150952.963606936@linuxfoundation.org> References: <20200901150952.963606936@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luis Chamberlain [ Upstream commit b431ef837e3374da0db8ff6683170359aaa0859c ] We make an assumption that a debugfs directory exists, but since this can fail ensure it exists before allowing blktrace setup to complete. Otherwise we end up stuffing blktrace files on the debugfs root directory. In the worst case scenario this *in theory* can create an eventual panic *iff* in the future a similarly named file is created prior on the debugfs root directory. This theoretical crash can happen due to a recursive removal followed by a specific dentry removal. This doesn't fix any known crash, however I have seen the files go into the main debugfs root directory in cases where the debugfs directory was not created due to other internal bugs with blktrace now fixed. blktrace is also completely useless without this directory, so this ensures to userspace we only setup blktrace if the kernel can stuff files where they are supposed to go into. debugfs directory creations typically aren't checked for, and we have maintainers doing sweep removals of these checks, but since we need this check to ensure proper userspace blktrace functionality we make sure to annotate the justification for the check. Signed-off-by: Luis Chamberlain Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- kernel/trace/blktrace.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index a4c8f9d9522e4..884333b9fc767 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -535,6 +535,18 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, #endif bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root); + /* + * As blktrace relies on debugfs for its interface the debugfs directory + * is required, contrary to the usual mantra of not checking for debugfs + * files or directories. + */ + if (IS_ERR_OR_NULL(dir)) { + pr_warn("debugfs_dir not present for %s so skipping\n", + buts->name); + ret = -ENOENT; + goto err; + } + bt->dev = dev; atomic_set(&bt->dropped, 0); INIT_LIST_HEAD(&bt->running_list); -- 2.25.1