From patchwork Fri Jun 19 20:47:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 11615049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F360713B1 for ; Fri, 19 Jun 2020 20:47:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA54121527 for ; Fri, 19 Jun 2020 20:47:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA54121527 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8911C8D0100; Fri, 19 Jun 2020 16:47:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2048D00FD; Fri, 19 Jun 2020 16:47:45 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 621DE8D0100; Fri, 19 Jun 2020 16:47:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 2B0418D00FD for ; Fri, 19 Jun 2020 16:47:45 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E2DAB181ACC80 for ; Fri, 19 Jun 2020 20:47:44 +0000 (UTC) X-FDA: 76947147648.24.hands43_4a1853126e1b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id C36F61A4A5 for ; Fri, 19 Jun 2020 20:47:44 +0000 (UTC) X-Spam-Summary: 2,0,0,77d1c0657fdd25bc,d41d8cd98f00b204,mcgrof@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:2903:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:5007:6261:7903:7974:9389:10004:11026:11473:11658:11914:12043:12048:12296:12297:12517:12519:12555:12895:13141:13149:13230:13894:14181:14394:14721:21063:21080:21444:21627:30029:30054:30056:30070,0,RBL:209.85.216.65:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: hands43_4a1853126e1b X-Filterd-Recvd-Size: 4783 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Fri, 19 Jun 2020 20:47:44 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id h95so4777664pje.4 for ; Fri, 19 Jun 2020 13:47:44 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=WAnSKbcOgD9mh5TKczvQeK3USc0HG+X2VK1Fl/2VodI=; b=qVyCN8TV4GW3WwXd2dNmgYklnAvAdyXaIPmq/GYE4qFLjd2SvoYFDEGCXTyCJ04LEl 7/m1nRWZVNXR+TLefCpgTdRxfHcBUF9ktpxfU3BzowgGde9Rv5w1QO+j14GBqBeqWS7L 3+JP+J7RwUKkmV8Yv9i97LDnTWpzuDc8T6Q93fXI1MhHmhB7/6hgu0TdWuwqkw1W+Ibk xc7HNFP/NBVi9tslLRs47iNPirOG2XUsggG/9COhbgMHrQFeKJNlb6YRvY491w5537p8 U/8Wp2SM7tNZzjvOJd3lBGRb0Gtdeq0ZFIV85zZL9sDJvR5m3ZeEBrP/+Y/1DY4PDA39 XMXw== X-Gm-Message-State: AOAM532NhBIb/G1RdSAHmcIDQnM3Vqi05Hl5bgek3v+v9uHpjEMdf1iy 9nCqAelv2JK6O0phUEAsZLg= X-Google-Smtp-Source: ABdhPJyt+q2/jgY/ucUkJNHL+DMXosz4eR8RKCOdVty3Tudmz1nHdpy8UFn8y3lmFu7CwHtJNrHb/w== X-Received: by 2002:a17:902:d889:: with SMTP id b9mr9091448plz.206.1592599663520; Fri, 19 Jun 2020 13:47:43 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id d189sm6688611pfc.51.2020.06.19.13.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 13:47:39 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id 99B6242340; Fri, 19 Jun 2020 20:47:32 +0000 (UTC) From: Luis Chamberlain To: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org Cc: mhocko@suse.com, yukuai3@huawei.com, martin.petersen@oracle.com, jejb@linux.ibm.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH v7 7/8] blktrace: ensure our debugfs dir exists Date: Fri, 19 Jun 2020 20:47:29 +0000 Message-Id: <20200619204730.26124-8-mcgrof@kernel.org> X-Mailer: git-send-email 2.23.0.rc1 In-Reply-To: <20200619204730.26124-1-mcgrof@kernel.org> References: <20200619204730.26124-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C36F61A4A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- kernel/trace/blktrace.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index e6e2d25fdbd6..098780ec018f 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -538,6 +538,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);