History

blktrace: ensure our debugfs dir exists

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.

Luis Chamberlain committed 6 years ago

Commit b431ef81 parent bad8e641 file · +12 −0Browse files

Unified · Split

kernel/trace/blktrace.c+12−0
@@ -538,6 +538,18 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, · 537 unmodified lines
538538 #endif
539539 bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);
540540
541+ /*
542+ * As blktrace relies on debugfs for its interface the debugfs directory
543+ * is required, contrary to the usual mantra of not checking for debugfs
544+ * files or directories.
545+ */
546+ if (IS_ERR_OR_NULL(dir)) {
547+ pr_warn("debugfs_dir not present for %s so skipping\n",
548+ buts->name);
549+ ret = -ENOENT;
550+ goto err;
551+ }
552+
541553 bt->dev = dev;
542554 atomic_set(&bt->dropped, 0);
543555 INIT_LIST_HEAD(&bt->running_list);