From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B51771CD1E4 for ; Tue, 16 Dec 2025 08:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765873509; cv=none; b=fqsO6f+Kz20LtHpDIo8miL3m+WObLtwrk1CIjoYLv9bwEIv2tiW8HA+YeGH5kYtmBllnnIKdNfaaoUyUPteIrE8S8GwOfXWQ0NE+d/oYpTZW6g+ctgxaKm2Z9fhdhfEs7boA7Ik2ciAZeO7H/SpOlYYOyfAWD/1W/HuusdpL3k8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765873509; c=relaxed/simple; bh=t3OYgCEcUgWIjUzyh8Zq9bCLYydXQ6ouxr7WquPZT5A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J172PmdwlTzCmDEiZtUnqPC0evLVvBP/oPv2+gYPg+D6/Ra4KLAimtTyOdVPtWPYvSs6GxIjETrtc26Y6mMteqfjFHJditLZ85Ddsx8YD86rVeET8dtTGtGFhFnNAWcGq5CBb1WX1eSI6j4g8JltF2k/JrH0PtsKocDd+Psd2M8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LKHLNpa/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LKHLNpa/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD3A0C113D0; Tue, 16 Dec 2025 08:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1765873509; bh=t3OYgCEcUgWIjUzyh8Zq9bCLYydXQ6ouxr7WquPZT5A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LKHLNpa/HK9psGF9hDYkOcDHgT1u3d2DIQ0jGlrrZwUmIXzf1EP9g60E8TdFiXOis 2ucqJkNpubYweESo/po3apeXdRfi9+JpjIiPz+TPHH6FlzoxY49138LQaFr3kpy2de VyqUYzGSkoYBMWWECmDDaYNmyV4JKb0OE0l5tuRE= Date: Tue, 16 Dec 2025 09:25:06 +0100 From: Greg Kroah-Hartman To: Will Rosenberg Cc: Paul Moore , syzbot+6aaf7f48ae034ab0ea97@syzkaller.appspotmail.com, Tejun Heo , Oliver Rosenberg , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] fs/kernfs: null-ptr deref in simple_xattrs_free() Message-ID: <2025121653-overfeed-giblet-5bde@gregkh> References: <20251215232612.3880995-1-whrosenb@asu.edu> <20251216003552.3912290-1-whrosenb@asu.edu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251216003552.3912290-1-whrosenb@asu.edu> On Mon, Dec 15, 2025 at 05:35:52PM -0700, Will Rosenberg wrote: > There exists a null pointer dereference in simple_xattrs_free() as > part of the __kernfs_new_node() routine. Within __kernfs_new_node(), > err_out4 calls simple_xattr_free(), but kn->iattr may be NULL if > __kernfs_setattr() was never called. As a result, the first argument to > simple_xattrs_free() may be NULL + 0x38, and no NULL check is done > internally, causing an incorrect pointer dereference. > > Add a check to ensure kn->iattr is not NULL, meaning __kernfs_setattr() > has been called and kn->iattr is allocated. Note that struct kernfs_node > kn is allocated with kmem_cache_zalloc, so we can assume kn->iattr will > be NULL if not allocated. > > An alternative fix could be to not call simple_xattr_free() at all. As > was previously discussed during the initial patch, simple_xattr_free() > is not strictly needed and is included to be consistent with > kernfs_free_rcu(), which also helps the function maintain correctness if > changes are made in __kernfs_new_node(). > > Reported-by: syzbot+6aaf7f48ae034ab0ea97@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=6aaf7f48ae034ab0ea97 > Fixes: 382b1e8f30f7 ("kernfs: fix memory leak of kernfs_iattrs in __kernfs_new_node") > Signed-off-by: Will Rosenberg > --- > > Notes: > v1 -> v2: fix patch formatting issues > > This bug was introduced as part of a patch I made, fixing a memory > leak in the error out case. > > I apologize for the oversight. Further fuzzing revealed the bug, > and after checking, I found that syzbot detected the same issue. > > fs/kernfs/dir.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c > index 5c0efd6b239f..29baeeb97871 100644 > --- a/fs/kernfs/dir.c > +++ b/fs/kernfs/dir.c > @@ -681,8 +681,10 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, > return kn; > > err_out4: > - simple_xattrs_free(&kn->iattr->xattrs, NULL); > - kmem_cache_free(kernfs_iattrs_cache, kn->iattr); > + if (kn->iattr) { > + simple_xattrs_free(&kn->iattr->xattrs, NULL); > + kmem_cache_free(kernfs_iattrs_cache, kn->iattr); > + } > err_out3: > spin_lock(&root->kernfs_idr_lock); > idr_remove(&root->ino_idr, (u32)kernfs_ino(kn)); > > base-commit: d358e5254674b70f34c847715ca509e46eb81e6f > -- > 2.34.1 > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot