Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 68DE654A7F2 for ; Thu, 17 Sep 2026 15:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789657351; cv=none; b=cQ4koy75ShKLFBGxL0F3SVoF5ya+l+CFkuI9T0CPD47wxCfpo6sMtKUxVpu2HTpCGwiFjq9Gkw0ok6w7Pe4fzwb6vn7KurAaAmSDnHOddvFzPMoZUPSzphC2Dq6OcGSH54ItCI8VQGLhRxb04WSAHF297fW02Vb+A6zh2cHLHe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789657351; c=relaxed/simple; bh=K0Ki+cJFcEGB/k+06RfSg3Bjb4oAGeHaLyiirnBKtFI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nkIoKbjMj+ampR5Oe9gZ8UUqRYyrbo7zRg5wvp9zKS2pss1D7FjHmj1ttoIxcTdeH9cOLJlzTaEyT9fEvFei/GCLkAnaRW/yWxvGgMts0Q0t3+JFvhYuDwWGwmw4c+nvjwHwVSIMXq5fozq/x92/0d1aySi7itnCypvBGE+S0j4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=byV68j/B; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="byV68j/B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C5C41F008A5; Thu, 17 Sep 2026 15:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789657313; bh=DyihbsgPyA8EbVJJ9Po2IpJyh0Opi659RhslMTUWNNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=byV68j/BhNloxpeomyfLapwmrLiTi9TV7A2o1VcjWlfr1VFpGVyY8k1GqI7WOH7Rp 73ealAYMlhXGCYJdXRuJq2ICPzP9eezYygCNPVSYYE44DGZVcbO816pcuq/SvnrSiL BF43ZvWG2A4sOLLSvRvQaZD71YlngQiYUS9XbJ2pQAhoZJ/NVWGzhjJ9LjemWJYx9m qIwftpEISOXW+lSD1nu5DjkBrMP6T8CAIb3jUKW4yKAaRYWp7oE2a74DFtkOv8abBb LS+xn55eybcR95bdUzWgw8bmvjWdG7eJM1TJeehcCci/yCmZlb136qpiB51/FQcSMc oqMQeA1zLmzMg== From: Sasha Levin To: stable@vger.kernel.org Cc: Paulo Alcantara , Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , Sasha Levin Subject: [PATCH 6.12.y 2/2] smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr() Date: Thu, 17 Sep 2026 11:01:49 -0400 Message-ID: <20260917150149.671513-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260917150149.671513-1-sashal@kernel.org> References: <2026091628-armored-debtless-c6d4@gregkh> <20260917150149.671513-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Paulo Alcantara [ Upstream commit da6e25842431982d5a53cf00d925b98c690f4467 ] cifs_posix_to_fattr() ignores the return value of posix_info_parse(). When a malformed POSIX directory entry is encountered (e.g. invalid SID lengths from an untrusted server), posix_info_parse() returns -1 without populating the 'parsed' struct. The uninitialized stack memory in parsed.owner and parsed.group is then passed to sid_to_id(), which processes the garbage bytes and passes them to request_key() to construct a SID string, potentially leaking kernel stack contents to the userspace idmap daemon. Fix this by checking the return value and skipping the SID-to-id mapping when parsing fails. The remaining fattr fields (timestamps, mode, etc.) are populated directly from the 'info' pointer so they are unaffected. Closes: https://sashiko.dev/#/patchset/20260906172005.627163-1-pc%40manguebit.org Closes: https://sashiko.dev/#/patchset/20260906181540.647469-1-pc%40manguebit.org Reviewed-by: Namjae Jeon Signed-off-by: Paulo Alcantara Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin --- fs/smb/client/readdir.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c index 9888756fff888..0c8c8c64904b7 100644 --- a/fs/smb/client/readdir.c +++ b/fs/smb/client/readdir.c @@ -243,8 +243,9 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, { unsigned int sbflags = cifs_sb_flags(cifs_sb); struct smb2_posix_info_parsed parsed; + int rc; - posix_info_parse(info, NULL, &parsed); + rc = posix_info_parse(info, NULL, &parsed); memset(fattr, 0, sizeof(*fattr)); fattr->cf_uniqueid = le64_to_cpu(info->Inode); @@ -283,10 +284,15 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, fattr->cf_uid = cifs_sb->ctx->linux_uid; fattr->cf_gid = cifs_sb->ctx->linux_gid; - if (!(sbflags & CIFS_MOUNT_OVERR_UID)) - sid_to_id(cifs_sb, &parsed.owner, fattr, SIDOWNER); - if (!(sbflags & CIFS_MOUNT_OVERR_GID)) - sid_to_id(cifs_sb, &parsed.group, fattr, SIDGROUP); + if (rc < 0) { + cifs_dbg(VFS, "%s: failed to parse SIDs: %d\n", + __func__, rc); + } else { + if (!(sbflags & CIFS_MOUNT_OVERR_UID)) + sid_to_id(cifs_sb, &parsed.owner, fattr, SIDOWNER); + if (!(sbflags & CIFS_MOUNT_OVERR_GID)) + sid_to_id(cifs_sb, &parsed.group, fattr, SIDGROUP); + } } static void __dir_info_to_fattr(struct cifs_fattr *fattr, const void *info) -- 2.53.0