From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F6B3C3A5A0 for ; Mon, 20 Apr 2020 00:04:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F338521974 for ; Mon, 20 Apr 2020 00:04:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F338521974 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 8D30F8E0005; Sun, 19 Apr 2020 20:04:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8830C8E0003; Sun, 19 Apr 2020 20:04:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7995E8E0005; Sun, 19 Apr 2020 20:04:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 5E9C48E0003 for ; Sun, 19 Apr 2020 20:04:40 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0CA4E824556B for ; Mon, 20 Apr 2020 00:04:40 +0000 (UTC) X-FDA: 76726287120.23.jewel59_b98c4bd23701 X-HE-Tag: jewel59_b98c4bd23701 X-Filterd-Recvd-Size: 5782 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Apr 2020 00:04:39 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id o185so3638421pgo.3 for ; Sun, 19 Apr 2020 17:04:39 -0700 (PDT) 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kh1k2fqld2X6QVBNO1w5sZUDXzr6Qg5ZBK70v1ls5f8=; b=uehjj86AQf4tGPIvSf8O8gXMj+OC2rteh6dVHU3txZo2l06fv8FHvlBwx6GOMw5LfL oCEYTduAyJp2z1nAnbZqm9NzNZ75bn1neDmpu5AxLDvKTTiSvPUTqU3nAiwY0MvV895U 6lEeuAGHjb8nuykE3ImyZAso93M8xk1GkWzf1Q+qh3YbSv//wKn7V27J7p/B0ODlqucJ 2zNZTdB5gSyljK+FGw0ORdX+kAEULBKFZKKTxemyaUbcMj0tlDl2xUouKOQTIQ636RAI 6PVPj2PJ5ykyHNBVYE/E5uzMcH1Nqn3GRSBsT8y1Xax8LbO6jslwGYqW/DOk0sJGeW2K FF2A== X-Gm-Message-State: AGi0PuaWO4GOADyq/bewKAKS1Nd4DA87U8QT6xOFC1S60/dskyiOkKop l8CGRlVjDUnvGg+9SjekJyY= X-Google-Smtp-Source: APiQypKByK9nGxLgzdmeIoOk4RejCW0M5WnXjnSVh+/H8BFqlKseFoMbp59ib8yYPJc/EWdaO7a6pw== X-Received: by 2002:a63:4d5e:: with SMTP id n30mr14012899pgl.154.1587341078621; Sun, 19 Apr 2020 17:04:38 -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 s10sm25127565pfd.124.2020.04.19.17.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 17:04:37 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id 7FC2140858; Mon, 20 Apr 2020 00:04:36 +0000 (UTC) Date: Mon, 20 Apr 2020 00:04:36 +0000 From: Luis Chamberlain To: Bart Van Assche Cc: axboe@kernel.dk, viro@zeniv.linux.org.uk, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org, mhocko@suse.com, yukuai3@huawei.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Omar Sandoval , Hannes Reinecke , Michal Hocko , syzbot+603294af2d01acfdd6da@syzkaller.appspotmail.com Subject: Re: [PATCH v2 03/10] blktrace: fix debugfs use after free Message-ID: <20200420000436.GI11244@42.do-not-panic.com> References: <20200419194529.4872-1-mcgrof@kernel.org> <20200419194529.4872-4-mcgrof@kernel.org> <91c82e6a-24ce-0b7d-e6e4-e8aa89f3fb79@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <91c82e6a-24ce-0b7d-e6e4-e8aa89f3fb79@acm.org> User-Agent: Mutt/1.10.1 (2018-07-13) 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: On Sun, Apr 19, 2020 at 02:55:42PM -0700, Bart Van Assche wrote: > On 4/19/20 12:45 PM, Luis Chamberlain wrote: > > +int __must_check blk_queue_debugfs_register(struct request_queue *q) > > +{ > > + struct dentry *dir = NULL; > > + > > + /* This can happen if we have a bug in the lower layers */ > > What does "this" refer to? Which layers does "lower layers" refer to? Most > software developers consider a module that calls directly into another > module as a higher layer (callbacks through function pointers do not count; > see also https://en.wikipedia.org/wiki/Modular_programming). According to > that definition block drivers are a software layer immediately above the > block layer core. > > How about changing that comment into the following to make it unambiguous > (if this is what you meant)? > > /* > * Check whether the debugfs directory already exists. This can > * only happen as the result of a bug in a block driver. > */ But I didn't mean on a block driver. I meant the block core. In our case, the async request_queue removal is an example. There is nothing that block drivers could have done to help much with that. I could just change "lower layers" to "block layer" ? > > + dir = debugfs_lookup(kobject_name(q->kobj.parent), blk_debugfs_root); > > + if (dir) { > > + pr_warn("%s: registering request_queue debugfs directory twice is not allowed\n", > > + kobject_name(q->kobj.parent)); > > + dput(dir); > > + return -EALREADY; > > + } > > + > > + q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent), > > + blk_debugfs_root); > > + if (!q->debugfs_dir) > > + return -ENOMEM; > > + > > + return 0; > > +} > > kobject_name(q->kobj.parent) is used three times in the above function. How > about introducing a local variable that holds the result of that expression? Sure. > > +static bool blk_trace_target_disk(const char *target, const char *diskname) > > +{ > > + if (strlen(target) != strlen(diskname)) > > + return false; > > + > > + if (!strncmp(target, diskname, > > + min_t(size_t, strlen(target), strlen(diskname)))) > > + return true; > > + > > + return false; > > +} > > The above code looks weird to me. When the second if-statement is reached, > it is guaranteed that 'target' and 'diskname' have the same length. So why > to calculate the minimum length in the second if-statement of two strings > that have the same length? True, no need that that point. Will fix. > Independent of what the purpose of the above code is, can that code be > rewritten such that it does not depend on the details of how names are > assigned to disks and partitions? Would disk_get_part() be useful here? I did try, but couldn't figure out a way. I'll keep looking but likewise let me know if you find a way. Luis