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.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 1B169C4338F for ; Mon, 23 Aug 2021 07:46:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED82360F3A for ; Mon, 23 Aug 2021 07:46:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235235AbhHWHrV (ORCPT ); Mon, 23 Aug 2021 03:47:21 -0400 Received: from verein.lst.de ([213.95.11.211]:46720 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235115AbhHWHrU (ORCPT ); Mon, 23 Aug 2021 03:47:20 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id D7E5F6736F; Mon, 23 Aug 2021 09:46:36 +0200 (CEST) Date: Mon, 23 Aug 2021 09:46:36 +0200 From: Christoph Hellwig To: sishuaigong Cc: jlbec@evilplan.org, hch@lst.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] configfs: fix a race in configfs_lookup() Message-ID: <20210823074636.GA23822@lst.de> References: <20210820214458.14087-1-sishuai@purdue.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210820214458.14087-1-sishuai@purdue.edu> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 20, 2021 at 05:44:58PM -0400, sishuaigong wrote: > 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 bug by using list_for_each_entry_safe() instead. I don't see how list_for_each_entry_safe would save you there. You need a lock to sychronize the two, list_for_each_entry_safe only ensures the next entry is looked up before iterating over the current one.