From nobody Sun Feb 8 19:24:31 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05AC823B61B for ; Tue, 16 Dec 2025 00:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845820; cv=none; b=KJtYvkNbxWPxmUaSesG6IxO9k7nlCzTFy7HsF2/GfGvtI8MKhXR/dFuH8Y9C1OMCckm0tXO338m4eOXnVaEUN6MlCrYGc8LmlGioK0Tp2xJ7A77ZBPn43SRm6SKsRa2CN61CDAl+obcRjfHxrnStKBY6CFZurFskdeQHo/uN62U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765845820; c=relaxed/simple; bh=MbZx9D6lg9luMlxqS3o0j/0ot+YNQnLQ+Isjs4svZ3Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zn+flNo8vvbogulIB3rw3f3I4gEDWgeW24HS5VQ0TeDhOw+c3/iwpT9x3dh1lzSOQd2PsPpBz5rLvmJ9unEUQjFM8o8wonb0cNSwQ55/B/7UsTLDmKC3Ng8HcAjLJlinXB+lW7MGMPnBcMZcH5Slcd/ersDNqKbTrcPk7NDNCNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu; spf=pass smtp.mailfrom=asu.edu; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b=UcerExzN; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b="UcerExzN" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2a110548cdeso14867785ad.0 for ; Mon, 15 Dec 2025 16:43:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1765845818; x=1766450618; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fxu4K01CUWClU7qLrNuM9MkDAwZFr98Z5rveTCKClOw=; b=UcerExzNQD5lAsIM93sbI9ZVyPu0VjJz4nDPWG823WZz/Q5JreU/uFxYJ26NvY5U2Y UvLeKPqcKTagfdwUbXx7u1tCb53gs0pIwcQqCGPqoob72qCMTNCMTFKV+aDzrXb5IfLN iQ4q4hLMmsh6jpgBEkzGqWbjPoKywjxWR/yMZsUvA2i957n6U3B/tlcaQrFrgOIDNP2a nhHt9IE8SpL0OvdTvXhawOOBrq3q48i8Q6Qqr4ZDMD3eY5pepMW18/hmv2gXJDK2cyHB 4NBz8awvFxwtw94BQrPLFUF+5DnmbmZCnyQvT921Pj99Mre7HjNE8ldSGAZyLOxnxHK2 nBPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765845818; x=1766450618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Fxu4K01CUWClU7qLrNuM9MkDAwZFr98Z5rveTCKClOw=; b=nAkUxGRJcYw3VBLYZ/NOn2VeYGYiAtZIkALf8YEFOHpXf+XBK29tdozok3+CdBhtfo k3a8VRBGYlBhSGjPipu9v3O/NHtcqMNvO9yAcnDP6HJ7wiocMU1twDGXsUxT3kvv+ezA buddqGUxvx2xfpIlgV7C9GuYEr6D9kMo4pZNA8O4MdBVUcEjIKkTBLg4KpoPtusdv6T/ 39QQmdePwrCzPyA1jzu+S9/AEThh2fPZ4Npp4GIAKoVueLW0nhh6kkaTTuR+Fz7vKqvg xWC+KQqtcoF01HqvjQ8tWkoQcKpw939J9IBwd7MLYgwFdUMeWjFRqMgMNcw3wSn7RapS PXUA== X-Forwarded-Encrypted: i=1; AJvYcCWblMWcRD/puW0tQzrE6viQwQ4kv0ubKIqqM7IZ7EbVwPWOVFc9G+hH2b+YyjWeWxLd+8SJWQP/4oay8c0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxdi5iN9Utp1+QChykYm43ReT8t0Rbma0dvZY7HsaVIc5t3mx9k BrlOoANUJ626q9N4AvLGeQkirp2ucuXJYieXcAgXY/l4GSonuDxM9IceRCyHCsifxQ== X-Gm-Gg: AY/fxX5DbNVJG6gZbMl6VApH1Nl7h2gSZ8lYSs7uu369xX4NdtsOpAfcBGAisnXJH9v 8YbsK2jLCQcWB2kD/Hytn11VovA622v7HBHDKPmTLmALayW43LygxFRZ4QIX0xbjL7lBDQJ4cxO RZ+NluMLQUOTtUKKvRAaMcN5/tl7ImmZmm29sdfxheUlI2wFgEopHTJ8C9gLLY2bB6jVs30s534 OgZEYORZo9JAlARLeqT0xhJeyUlxkCtwZriXEiHIE/RqmwyOnrMObO7iUekURITNin2LekkqUKH fCbDW99Jwr+sUmgv+GRWJosKjFgisnsyTeBGA0PH2fz87GdXluI2mCTx6NO//cNY2RECQVTZTD4 SsPlWA7iNO7gvkh+f3407jiKy2dHy2hIqWvZ3klc5AwaxrK22ZimOnXTc+x6NV9Ut0BUwze9Ezz 3c9S0EP648zxWRYq7IqZwkDEA4tl+bYikxGbzRoNbd4l7dggdOAA== X-Google-Smtp-Source: AGHT+IHJz4dmxjwnK097FxhCstfNGnKwMBqUpVRBMLcjYRvM3V3Qus+8FhVJip3DbCylL7DbMbOqdg== X-Received: by 2002:a05:7022:eac4:b0:11e:163:be60 with SMTP id a92af1059eb24-11f354cc91fmr9914890c88.31.1765845818134; Mon, 15 Dec 2025 16:43:38 -0800 (PST) Received: from will-mint.dhcp.asu.edu (209-147-139-190.nat.asu.edu. [209.147.139.190]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-11f2e1bb2f4sm47184776c88.3.2025.12.15.16.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Dec 2025 16:43:37 -0800 (PST) From: Will Rosenberg To: Cc: Paul Moore , Will Rosenberg , syzbot+6aaf7f48ae034ab0ea97@syzkaller.appspotmail.com, Greg Kroah-Hartman , Tejun Heo , Oliver Rosenberg , linux-kernel@vger.kernel.org Subject: [PATCH v2] fs/kernfs: null-ptr deref in simple_xattrs_free() Date: Mon, 15 Dec 2025 17:35:52 -0700 Message-Id: <20251216003552.3912290-1-whrosenb@asu.edu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251215232612.3880995-1-whrosenb@asu.edu> References: <20251215232612.3880995-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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D6aaf7f48ae034ab0ea97 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 =20 This bug was introduced as part of a patch I made, fixing a memory leak in the error out case. =20 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 ke= rnfs_root *root, return kn; =20 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 --=20 2.34.1