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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 5D787C432BE for ; Tue, 31 Aug 2021 05:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41C3D6102A for ; Tue, 31 Aug 2021 05:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239151AbhHaFyh (ORCPT ); Tue, 31 Aug 2021 01:54:37 -0400 Received: from zeniv-ca.linux.org.uk ([142.44.231.140]:52350 "EHLO zeniv-ca.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238882AbhHaFye (ORCPT ); Tue, 31 Aug 2021 01:54:34 -0400 Received: from jlbec by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mKwiG-00HUqS-RW; Tue, 31 Aug 2021 05:53:36 +0000 Date: Tue, 31 Aug 2021 05:53:36 +0000 From: Joel Becker To: Christoph Hellwig Cc: Sishuai Gong , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 4/4] configfs: fix a race in configfs_lookup() Message-ID: Mail-Followup-To: Christoph Hellwig , Sishuai Gong , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org References: <20210825064906.1694233-1-hch@lst.de> <20210825064906.1694233-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210825064906.1694233-5-hch@lst.de> X-Burt-Line: Trees are cool. X-Red-Smith: Ninety feet between bases is perhaps as close as man has ever come to perfection. Sender: Joel Becker Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Acked-by: Joel Becker On Wed, Aug 25, 2021 at 08:49:06AM +0200, Christoph Hellwig wrote: > From: Sishuai Gong > > When configfs_lookup() is executing list_for_each_entry(), > it is possible that configfs_dir_lseek() is calling list_del(). > Some unfortunate interleavings of them can cause a kernel NULL > pointer dereference error > > Thread 1 Thread 2 > //configfs_dir_lseek() //configfs_lookup() > list_del(&cursor->s_sibling); > list_for_each_entry(sd, ...) > > Fix this by grabbing configfs_dirent_lock in configfs_lookup() > while iterating ->s_children. > > Signed-off-by: Sishuai Gong > Signed-off-by: Christoph Hellwig > --- > fs/configfs/dir.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c > index fc20bd8a6337..1466b5d01cbb 100644 > --- a/fs/configfs/dir.c > +++ b/fs/configfs/dir.c > @@ -439,13 +439,13 @@ static struct dentry * configfs_lookup(struct inode *dir, > if (!configfs_dirent_is_ready(parent_sd)) > return ERR_PTR(-ENOENT); > > + spin_lock(&configfs_dirent_lock); > list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { > if ((sd->s_type & CONFIGFS_NOT_PINNED) && > !strcmp(configfs_get_name(sd), dentry->d_name.name)) { > struct configfs_attribute *attr = sd->s_element; > umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG; > > - spin_lock(&configfs_dirent_lock); > dentry->d_fsdata = configfs_get(sd); > sd->s_dentry = dentry; > spin_unlock(&configfs_dirent_lock); > @@ -462,10 +462,11 @@ static struct dentry * configfs_lookup(struct inode *dir, > inode->i_size = PAGE_SIZE; > inode->i_fop = &configfs_file_operations; > } > - break; > + goto done; > } > } > - > + spin_unlock(&configfs_dirent_lock); > +done: > d_add(dentry, inode); > return NULL; > } > -- > 2.30.2 > --