From nobody Thu Dec 18 23:27:24 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 0C1DC3A1E93 for ; Wed, 17 Dec 2025 06:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765951274; cv=none; b=os1w6x5IVkg4734Mche44PmFQ7CpmaaE4q2HbeAZUQXQUpqsjRAjSsrDyHBw2g1Sda2byCRcukbnmRWzNPamYralLbML7N2OvyYeP9iyTsexw/sYWg9ZV13cHGNxg+GFwUZ4tApS8dJ5Hnq2DDA7sdNQASb3mC7y7c17atcsevs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765951274; c=relaxed/simple; bh=uJKEthvad56//QQXnTcJM+sA6uXIa/JWJsXjbxgsSkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TO+IeLrF6gMIh1MWXGhpWH5SH7m0vaG+xanOisHyUjAwdYwQmHU4ab0RHtLZnYenqbOI10oNeRO0xNCMqZ9xbz6DPt9QdJ2dU8+A5oYs5+gLBl/jdXeOHM4E9ISB8jaJR3rEmimt2WfAT52awhEi352eSI6Iz8/u37esAZq23K8= 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=R+ipNg1Z; arc=none smtp.client-ip=209.85.214.171 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="R+ipNg1Z" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2a12ebe4b74so26421535ad.0 for ; Tue, 16 Dec 2025 22:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1765951272; x=1766556072; 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=xgakhOh5sXI6AF8sz2NnJpekL42AonHY3n5DbiL1HAA=; b=R+ipNg1ZH0rk/DZFGWBVyJnPO1gLeGl6QJiztvzSiiign9mATPS46YUzbNlIec3Z8b DwiBFxUYA+ATALNs4dU7eS6WOU/jl27Lm2AtNvKTiXP3HfZ/zHerqpg94/5GkQT2DxNv 2unAf8sPaN1WEddzxqU7rDSHCr93BAMmbJNI3bz+NEX6X5BwyliJwQkwXS/hgQUXmf8v ZGA8AaBHWuXPhd/BPb8glpnPoctUioazmnCrRGED0LW6gAiFinYygGsw+mfO0EcHolku LEGhaNQ7dCfUZVGUZN2rVhvGV72+d7YuLIql9hKsHKQ4cKeWZkwKyhCp4eMPQUPnOCS3 NOzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765951272; x=1766556072; 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=xgakhOh5sXI6AF8sz2NnJpekL42AonHY3n5DbiL1HAA=; b=N4ViVc8TO2VGbftpslZEaAol02B2lwHhGE1ViybBi49NH/9ZskmdzwT7aeh6rmBjzI ktNGP/zgtPZooxKtp/ur08ciZG7TR6qSJXc/pCpDCOEhQne6/BsEITSRgAqBU/S6VLy1 yydYe7JYEvMa9vlQkoCcNnYGSHq5B89lr9sFggN3uJE/YvgLNV4mbWsgrWWEgNDLplJp ryppZ8AtZMMKy87nXqcNhn+yuyoDqyzXpSyyU6O5Z8jrS8hfnOte7AwfCvKDeeqz6fdt q0MX8DxlFEVrEYAiCRtE6L1N0H/cAtmyuk6bI5kO6pQtjd0H8Xj1WCAWe87IcIJbXtd6 xy2g== X-Gm-Message-State: AOJu0YyqLDKPo578/mIBzGl0u32xRtyMs8y7Ac9XWF7gSgskuEpJcBJ/ QEG/V/kQIT0OBsU38Jhl506WVDGDtquaIsWxm8kRY4KDeBLnhwQeSvVFMK5vxOFffw== X-Gm-Gg: AY/fxX4uEvbP2kYbVCjuL37Exl7i7dkpMBC5qx9OHkxYl8lslzUXvJO+/Xh4+yE3kHb BmGHcNSrozY0zzEjwq2QQ6zJBMFD5J2/LkL0+7pnMgm/MN8t5VLXa5xM0zkoTThP08CP2HeLWj9 4UFaeuS3sQ9I0MpxgoV02iapwEFQy83ezpuNbX6YCUNqJw747ChDvXzSB25UQd6sldV7IjU2sX7 2cxsS3qrvzxM5ypXdi0W/UIwBG2YiZsEfR0n/VAYh7KsA99hYRoRHVx0Dpt4/g3r32Tk8v9sBgZ 5+RLQcLRXZJxnHKOceyiVvtvAbshANWY9KBrC2WZ+Ovj2p99f6O5y/5EdatNV0o1gMqXNAcj0dF mxQeU3wsJiRKSyybAhQ03+M5mw3TZ5Z/SjolDwc+lp+ZmfPT62pgQorUmldNitKPyiD82Wz0m7U z/vhOawlisEl6VaWAlEQ2bRWk+xv0JMl20WRVST0ItGSIEuudftA== X-Google-Smtp-Source: AGHT+IGOph63owqQR9doJjkKuJkjqGB/QfUJB5a74RlESyh56GONb7jxsZZOUzDKJaURI1MOTmjYYQ== X-Received: by 2002:a05:7022:170d:b0:119:e56b:c758 with SMTP id a92af1059eb24-11f34c26239mr8249176c88.29.1765951272149; Tue, 16 Dec 2025 22:01:12 -0800 (PST) Received: from will-mint.dhcp.asu.edu (ip72-200-102-19.tc.ph.cox.net. [72.200.102.19]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-11f392500cdsm42405509c88.7.2025.12.16.22.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 22:01:11 -0800 (PST) From: Will Rosenberg To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, olrose55@gmail.com, paul@paul-moore.com, stable@vger.kernel.org, syzbot+6aaf7f48ae034ab0ea97@syzkaller.appspotmail.com, tj@kernel.org, whrosenb@asu.edu Subject: [PATCH v4] fs/kernfs: null-ptr deref in simple_xattrs_free() Date: Tue, 16 Dec 2025 23:01:07 -0700 Message-Id: <20251217060107.4171558-1-whrosenb@asu.edu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <2025121745-chatty-jogging-ac2d@gregkh> References: <2025121745-chatty-jogging-ac2d@gregkh> 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_xattrs_free() at all. As was previously discussed during the initial patch, simple_xattrs_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") Cc: stable@vger.kernel.org Signed-off-by: Will Rosenberg --- Notes: v1 -> v2: fix patch formatting issues v2 -> v3: add cc stable branch v3 -> v4: re-add the notes section. =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