From nobody Thu Dec 18 23:29:18 2025 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 5FC2A1EA7CB for ; Tue, 16 Dec 2025 16:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765903420; cv=none; b=ZAMKEWe6ktjt+G9shpH/MWrRvs22vO2OdRmIOE9DrzTY4eRL3t8bryJvpTQ6Ke5e82OkMl67RmI230oqb1J81sXl2U6aTdlQqwee5rP2sLQLjHeCGZ0hPvbIzQnJfb98CxxonGtEhmMK3CTg8kpYRV5orrpHPDJnFvfEdIGoCUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765903420; c=relaxed/simple; bh=c/vy1OQJySxIp4gpz4dJ3CMCm6lvu5FSBlUmBdaeNbI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PiCfGAx8IB+XQm5WNI8z7cglPW9Pmre/alhuNzyZFrPd/HU7FF7iY2kYXSFwhumeQUx7V2kMJut6LYIEzr1zrwjSHF9qyuL7+vi30X/BTlBcwADxMNFBX4rK0BdqyVYSKYOgv6SvNd2V3FXbX8Fz4Tjyxd+8MLztNk7bUB3ZqW4= 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=qqaOUwsW; arc=none smtp.client-ip=209.85.215.182 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="qqaOUwsW" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-bd1ce1b35e7so3329609a12.0 for ; Tue, 16 Dec 2025 08:43:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1765903417; x=1766508217; 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=DuaSItuMnaOwvl8gzGHA0YebmR1TZFEIwXuhDX+7ZwM=; b=qqaOUwsWC4aXWvsXocjwRvgv3NhpMDxH5yxr7k2YLcFqQSjujMEee82qUPMSvasFRu XGSnqgh0pZ9kRx9b2+135hcvCZ8ybq2eZIvC9mzbhdULweKurwyszw8Jo9x2InAlNxXZ lOIjnQ4+vur6S3fTywwaJwzvxNAUx7Zzcr+JC5y8aRTQktcdovTVInA8R2uvLTs4lN6f cckizyMEUVknw+VV5cWrMivbL0nGGGQ8VMYcigqqkgb1I6W3l4Qba6iWgl7dZX3FdGmV Rs9KcOQzev8+463by3sJU/sUn82un9rNKwdZOkk4rlYWccE8OG79WW79+egjdyYmZyfz 6H2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765903417; x=1766508217; 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=DuaSItuMnaOwvl8gzGHA0YebmR1TZFEIwXuhDX+7ZwM=; b=Ws3oWdlX/AN/F/TKzbEijU56+v/tXGw0vdtk8rCoSL2ELmsySW94fNdvKL65tlwbIG lbFe2o+u+z3vTbFXOYnUn9PiW8n2FAEqqyCQBH8nvOB8pNEh5IGYEFfC+JugDaJ2l22J b+tQNPYXjxm5lD1i8iLv0uUlLVy1Ovc2u4+Fa9o3QslpLN4Q3WLCRZqdSbyUUGvlHVAU v9Ev/4Qnd+kSU3YhEp2sLQXPS200wucD9BH056TKtbVaYEIDY8Cu/5sLcjKyZrrdiqgx CCuDYhGOZCJ/jxuTSBHdjRnMlv1iGvD8tH8TOlhQEKQHVFAEHs3aBc7wNhuiH9r4J/uP K2wg== X-Forwarded-Encrypted: i=1; AJvYcCVHvMvsChbRML2PZ4jyrskJZgsc4FtDjFv2jNSyC53gtZR5flglKLa7eG7zZJ1Q5a7s7tQq2MCwABsriAg=@vger.kernel.org X-Gm-Message-State: AOJu0Yzt3WbbPO1QdMUjwRkANTXoECe57y/KhNiWqjiS5uVysiyodRis IHiOWHaQp9gODPRn81i5o/qXfh05V8Ax9AZfNDsaGgcv0IAZoGbuUI38QKfscODqLQ== X-Gm-Gg: AY/fxX7ggxXDPlVSQg/CC3o6vBxQyP2jAVKHI7IKVMuM/doNEN6yRs7OuE7jcsM1TEA nf+T4kq7h7PtI5T0CSlz9xlhc2rZrc91E7+WUOCb+rrrdG5d4YUFplXYkZya0TXmFYlaK/ktVCA 1KHy8zsowRd9Kx54bHiU+0o30sa/DKwKHsnfRD4qnoiEiU5U2HilAR9fQmnjPHlonqMO3Z4RfG3 w6jNczCbhMDRNJ85vD81QBxOieDY4vexEH/0S8XFYXfQCfJcS63qHdz+IrvIJFQ34UUv6m2g05M 4qXWGc1oqajQat2i2TfL3uPhSKD3311BDiZFNktIVAeVvcerq3Z9YinsRD2LEirUoRe/2ykP/k7 W4LwyXyEIpIqeuxryXf63aM4QzPtQnKfPii50ueVvOdHg1gNyo62WkrDEgyEWh60hLSP58KePMf N6K2g8ia63ShnZOctZt8TcFZevNwle7Sxjt7w/sF+4ukPnnBpOTTeFReIkMaCF X-Google-Smtp-Source: AGHT+IEgIM6Vd4gAY8sPNiHEJn4U8FXjlXYPWxVnBxYlbkpoUgcSNpZj4PdQPi6CBSdaTfv1RYmQDQ== X-Received: by 2002:a05:7022:628c:b0:11a:273c:dd98 with SMTP id a92af1059eb24-11f34bc70bamr10606777c88.20.1765903416936; Tue, 16 Dec 2025 08:43:36 -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-11f43288340sm20028181c88.6.2025.12.16.08.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 08:43:36 -0800 (PST) From: Will Rosenberg To: Cc: Paul Moore , Will Rosenberg , syzbot+6aaf7f48ae034ab0ea97@syzkaller.appspotmail.com, stable@vger.kernel.org, Greg Kroah-Hartman , Tejun Heo , Oliver Rosenberg , linux-kernel@vger.kernel.org Subject: [PATCH v3] fs/kernfs: null-ptr deref in simple_xattrs_free() Date: Tue, 16 Dec 2025 09:43:35 -0700 Message-Id: <20251216164335.4066425-1-whrosenb@asu.edu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <2025121653-overfeed-giblet-5bde@gregkh> References: <2025121653-overfeed-giblet-5bde@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_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") Cc: stable@vger.kernel.org Signed-off-by: Will Rosenberg --- 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