From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx1.manguebit.org (mx1.manguebit.org [143.255.12.172]) (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 5B17433ADAF; Sun, 6 Sep 2026 20:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=143.255.12.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788725121; cv=none; b=CUpbpW/+C+8oZ3Vn9s5/A8751PCLanvMkpeNURN9P+PCgqzLujhP1tstbktNaUUmR0ovrO0I2y1lO1XRmkyCn/Dg/TpaK5EAnSz4iIijxAflDCoLVWXvTlU81vLPLSznECMgWkfMBySdiNqfhi3Gg6iyIJU1Z2T9Chlv69aMieI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788725121; c=relaxed/simple; bh=PTsmbqRojGl6CSbqGrFEW+LREbHoHngSaDt9w4Z/zS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R7Z9w4DVn211SsN3I8pN1PSiHIob7311GGgELHEmbXknOeaNut0Fz2QKotJdA4IwadHLqDkm6RU8D5ZObXeRCZy/JxzAWJOzERKA/HHg2ZbMVKwxKAs9TAvmUXR+D2Jp2jUNqsdXSRBmGmKrDxwz2V6xv1942Ch3iuPFHycsWOY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.org; spf=pass smtp.mailfrom=manguebit.org; dkim=pass (2048-bit key) header.d=manguebit.org header.i=@manguebit.org header.b=U37dvdxn; arc=none smtp.client-ip=143.255.12.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manguebit.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manguebit.org header.i=@manguebit.org header.b="U37dvdxn" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=manguebit.org; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Content-Type:Reply-To: Content-ID:Content-Description; bh=sh15HAx4gwt+8QiRyWcpyRbQrydwA5wicvbq6DoZ7nA=; b=U37dvdxnWrVjSiPn233ghyfc7s jh38cY1ad2U29M8Es1GC+l2HSOT0nB0lzb/J5Nhiwsa5uu0LMLVKvzw93un4aNdJE0K72FeAGSk6j rcY6S6aogvnhPKet6BhclEkNtjhesMetsauapcMfX5ygGkkVZNaUgT0F1wJ/c8opJEraCWOI47hMt De9/9jKj1nvICw/W3Ay2z6w+TBiY63IFjuwFWX18F6dn9ZkBe87AGMz4kesKT58PQP3zxtg0grg5z 15eZth6gPJUSESxtQx7DmmAbnioZKeztby+wlomcVuiwPsMnazfIEbyjpIcTvhdbQd8d8t/VNrkjL VjPOIhWg==; Received: from pc by mx1.manguebit.org with local (Exim 4.99.5) id 1x3J78-00000000oEG-23gW; Sun, 06 Sep 2026 17:05:18 -0300 From: Paulo Alcantara To: linux-cifs@vger.kernel.org Cc: Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , stable@vger.kernel.org Subject: [PATCH v4 4/7] smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr() Date: Sun, 6 Sep 2026 17:05:14 -0300 Message-ID: <20260906200517.725015-4-pc@manguebit.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260906200517.725015-1-pc@manguebit.org> References: <20260906200517.725015-1-pc@manguebit.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Paulo Alcantara Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: stable@vger.kernel.org --- 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 1ea84f4ada39..9530e5b01564 100644 --- a/fs/smb/client/readdir.c +++ b/fs/smb/client/readdir.c @@ -244,8 +244,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); @@ -284,10 +285,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.55.0