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=-5.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 B2993C54E4A for ; Mon, 11 May 2020 14:03:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F4A820736 for ; Mon, 11 May 2020 14:03:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F4A820736 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 18A7C900057; Mon, 11 May 2020 10:03:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1144D900036; Mon, 11 May 2020 10:03:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF636900057; Mon, 11 May 2020 10:03:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id D23ED900036 for ; Mon, 11 May 2020 10:03:32 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7EB2D4DAB for ; Mon, 11 May 2020 14:03:32 +0000 (UTC) X-FDA: 76804605864.06.test96_762cf6e41a046 X-HE-Tag: test96_762cf6e41a046 X-Filterd-Recvd-Size: 5696 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Mon, 11 May 2020 14:03:31 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id b8so4587597pgi.11 for ; Mon, 11 May 2020 07:03:31 -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=Vf5eO08K8TQtqLIZ8vTORrxsJc6yUCjJkazs1Bh1bj4=; b=FeDHuPWa+m8rQsFjgd0XLNwss0G8MBCqDgWjpIb3NVS5MMbBqAl3VCwQnZ3qdZ5r0e 1wMjSeZKgkr+Zvypnju8H7EpmM9B2dJk5rjlspSe41tdVL+uTWsiFO/l0PES7LxHKiX3 jnvP8zweJJORfIVDsbOG1AWRProJ3VkbF3JPi1NYBb57aKMF0dPQEwZdo8C7e2nZMaQF jwY4tv1sPPMJmAEBpUNOc8kixjXW5sh8oRvRmwI4JzO+HxEWVVZjz9hWqEBxzSuFigC+ 5qi9dt1gWINzBzG4okuB/o/BA/zdQLrnWOvJ5y1BWvFJJnsnI3EG8s3oCQ7eJWLqng1I cH1Q== X-Gm-Message-State: AGi0PuYlNfqz2f3un7azwABHebcu7tKXtPQLl1IBteoG6mtCN2waBiEV AgwK/tJEYLRTjdWDPO1iB2o= X-Google-Smtp-Source: APiQypLEaFgNrNPd13k7XF1jNCRRMz3QrV3XwtPkQkwwm+0cvcB2J8SaXWT82L5S5cHirPigs0BYhQ== X-Received: by 2002:a62:81c1:: with SMTP id t184mr16312244pfd.236.1589205810901; Mon, 11 May 2020 07:03:30 -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 x10sm8078137pgq.79.2020.05.11.07.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 07:03:28 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id 12F9040605; Mon, 11 May 2020 14:03:27 +0000 (UTC) Date: Mon, 11 May 2020 14:03:27 +0000 From: Luis Chamberlain To: Greg KH Cc: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.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 , Christof Schmitt , syzbot+603294af2d01acfdd6da@syzkaller.appspotmail.com Subject: Re: [PATCH v4 3/5] blktrace: fix debugfs use after free Message-ID: <20200511140327.GO11244@42.do-not-panic.com> References: <20200509031058.8239-1-mcgrof@kernel.org> <20200509031058.8239-4-mcgrof@kernel.org> <20200510062636.GA3400311@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200510062636.GA3400311@kroah.com> 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, May 10, 2020 at 08:26:36AM +0200, Greg KH wrote: > On Sat, May 09, 2020 at 03:10:56AM +0000, Luis Chamberlain wrote: > > diff --git a/block/blk-debugfs.c b/block/blk-debugfs.c > > index 19091e1effc0..d40f12aecf8a 100644 > > --- a/block/blk-debugfs.c > > +++ b/block/blk-debugfs.c > > +static struct dentry *queue_debugfs_symlink_type(struct request_queue *q, > > + const char *src, > > + const char *dst, > > + enum blk_debugfs_dir_type type) > > +{ > > + struct dentry *dentry = ERR_PTR(-EINVAL); > > + char *dir_dst; > > + > > + dir_dst = kzalloc(PATH_MAX, GFP_KERNEL); > > + if (!dir_dst) > > + return dentry; > > + > > + switch (type) { > > + case BLK_DBG_DIR_BASE: > > + if (dst) > > + snprintf(dir_dst, PATH_MAX, "%s", dst); > > + else if (!IS_ERR_OR_NULL(q->debugfs_dir)) > > + snprintf(dir_dst, PATH_MAX, "%s", > > + q->debugfs_dir->d_name.name); > > How can debugfs_dir be NULL/error here? If someone were to move blk_queue_debugfs_symlink() to sg_add_device(), this can happen as the sd_probe() will run asynchronously. The comment in blk_queue_debugfs_symlink() suggest to be mindful of async probes. I can do-away with this *iff* we add an probe_complete call to the driver core class interface. > And grabbing the name of a debugfs file is sketchy, just use the name > that you think you already have, from the device, don't rely on debugfs > working here. > > And why a symlink anyway? As the commit log explains, and the comment to the calling functions explains, we have a shared request_queue, and this has been the way, the symlink makes that sharing explicit. The next patch explains why using two blktraces on two separate devices would fail, the symlink makes this sharing quite obvious. It also simplifies the trace/kernel/blktrace.c code to just use the debugfs_dir only. > THat's a new addition, what is going to work > with that in userspace? This already works in userspace with blktrace. If you see a regression, please let me know. > > +#ifdef CONFIG_DEBUG_FS > > + p->debugfs_sym = blk_queue_debugfs_symlink(disk->queue, dev_name(pdev), > > + disk->disk_name); > > +#endif > > No need to #ifdef this, right? It is needed because of the p->debugfs_sym. > I feel like this patch series keeps getting more complex and messier > over time :( I'm afraid that use of blktrace in scsi-generic is the culprit, the technical debt of the complexities around how the request_queue is shared and properly providing backward compatibilty by removing the debufs_looksup() has caught up to us. If we were to agree to remove scsi-generic support from blktrace first, that would simplify things hugely. Luis