Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1646068pxb; Mon, 23 Aug 2021 00:47:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGNXoMuwY7cRH9K9MSO3jgY7X+XN2XhskF7ei5Homfbb+i3FbMMkbygBQ/I0wLMjpf+1s/ X-Received: by 2002:a05:6e02:4c3:: with SMTP id f3mr22243906ils.248.1629704851781; Mon, 23 Aug 2021 00:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629704851; cv=none; d=google.com; s=arc-20160816; b=sIf+3fo1GKFAMgQuQ4prXb6Cd4s1eizGmBRekYpXfOlcoScbEP9mWOg21epoKggRKo N1tPxNJKBPPjjeVduqYZzeEhPH/2yMfiic1WonTEBj6OffONV0Ywhyc6GdvIoED7Etga cg+YZuAGO+Y45lPlLlSLVcjM2lwgI1AngoP/iASAGGb43OyAVZRHH9jX2IvruqyXe7BA fC1zpR5ZkHRa28f8e34rPwCXU8yeUmhgtFI+mT/Yyyl4c0IWTT189W0dV89SX46iqRn+ zzpX+ut70ynEgaF9d1MS1h9EDlrjJqMrG7l9QVQPeNDv8maT9SkPAoc+RKFjpT6yItGp 37Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=UnOD+zRgiaLcpqM8/t6Kj4qh1sZRomFSRND9GkVR6kA=; b=gL3If5Ozk/wwPk5ZX5iQCcdp4pGvGubVZAFWlByiJsIfOCHHDrEjQLa+M+X3BpXLE0 3V09DhJK0wqFZ8e6mSSjn9BgvzMeCgfnAkrYamGDSZDXjWS3lIQCW+A5hXEgZRidtAp/ nBA1N7rW8oNn8sK3RV91jdGj/Gv2sWJSz5FkN0OZ7K4mIHZ8fdMIc94g4Vzja09GBKKj pUhY7SCJM6Y7nT1T1V3npUdrUEVg+tN+ASlDft2foV/T8KusUIZPHf0nj1iCvWepGcFP 8z8YP5t8iHlXQgqiMI/JAjq0LT2HtZ7EjnWhb4HH92bK39SjHg1reTlojkuGBuw4yw+n fpLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si13097914jam.32.2021.08.23.00.47.21; Mon, 23 Aug 2021 00:47:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235140AbhHWHrV (ORCPT + 99 others); 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.