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 296E9313E27; Tue, 2 Sep 2025 13:45:00 +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=1756820700; cv=none; b=MUpUxehUvESdaWXMZnoi6zpVxJdSa963uxFMA5ryQ+EN/IcOWPiPUUnwTzD0i5Gp6qFnqWavf0AAcsZkafHXRt5qcvpPJo6cfNLUZgNdObpFZCNvnu0T3zL4Edo3lq6ytJgOdKbqqUMWzBV9gI7blgyQtpwzjQ2vJSR/JW5psnM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756820700; c=relaxed/simple; bh=avj+v9ZKGwNaNUj4x3sPFc7A98kPcK1phRiVJXwmxQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ig+Om/LjC5bJePq0m9PaWikS4D6ZAimEIy0+9NIO7NYMAxneLWwYmdh3dIE0zQ0eLAvb71xU7Pwa64a11zMXoicDSE7YARfmWQlGeoCCSv0n8+usqtp0TxnkHFQE4J5GX1+e5CE7wXtWn+3EmCv3sgbJPRJr1if0VusC4OxLqhg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QQHoz+RI; 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="QQHoz+RI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D557C4CEF9; Tue, 2 Sep 2025 13:44:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756820700; bh=avj+v9ZKGwNaNUj4x3sPFc7A98kPcK1phRiVJXwmxQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QQHoz+RIMXt7Sc7vTk9CIt8+l2PT+JfBC8q9xnvd4SGY8dwFde2N19V/kxWBeTRRw prWPK05Dseo8jPCuJHImE/zxLrxIB0BaG9H97Nr7lBF24M3fBdT0aq9Eo42fwdA9yf WAPkSq1RTR4ecOu5ekgbuoyOZrZHMZUX3V2BQeVQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Li Nan , Wu Guanghao , Ard Biesheuvel , Sasha Levin Subject: [PATCH 5.10 18/34] efivarfs: Fix slab-out-of-bounds in efivarfs_d_compare Date: Tue, 2 Sep 2025 15:21:44 +0200 Message-ID: <20250902131927.347031581@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250902131926.607219059@linuxfoundation.org> References: <20250902131926.607219059@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Li Nan [ Upstream commit a6358f8cf64850f3f27857b8ed8c1b08cfc4685c ] Observed on kernel 6.6 (present on master as well): BUG: KASAN: slab-out-of-bounds in memcmp+0x98/0xd0 Call trace: kasan_check_range+0xe8/0x190 __asan_loadN+0x1c/0x28 memcmp+0x98/0xd0 efivarfs_d_compare+0x68/0xd8 __d_lookup_rcu_op_compare+0x178/0x218 __d_lookup_rcu+0x1f8/0x228 d_alloc_parallel+0x150/0x648 lookup_open.isra.0+0x5f0/0x8d0 open_last_lookups+0x264/0x828 path_openat+0x130/0x3f8 do_filp_open+0x114/0x248 do_sys_openat2+0x340/0x3c0 __arm64_sys_openat+0x120/0x1a0 If dentry->d_name.len < EFI_VARIABLE_GUID_LEN , 'guid' can become negative, leadings to oob. The issue can be triggered by parallel lookups using invalid filename: T1 T2 lookup_open ->lookup simple_lookup d_add // invalid dentry is added to hash list lookup_open d_alloc_parallel __d_lookup_rcu __d_lookup_rcu_op_compare hlist_bl_for_each_entry_rcu // invalid dentry can be retrieved ->d_compare efivarfs_d_compare // oob Fix it by checking 'guid' before cmp. Fixes: da27a24383b2 ("efivarfs: guid part of filenames are case-insensitive") Signed-off-by: Li Nan Signed-off-by: Wu Guanghao Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- fs/efivarfs/super.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c index 99d002438008b..124db520b2bd6 100644 --- a/fs/efivarfs/super.c +++ b/fs/efivarfs/super.c @@ -47,6 +47,10 @@ static int efivarfs_d_compare(const struct dentry *dentry, { int guid = len - EFI_VARIABLE_GUID_LEN; + /* Parallel lookups may produce a temporary invalid filename */ + if (guid <= 0) + return 1; + if (name->len != len) return 1; -- 2.50.1