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 B33B23C0A14; Sun, 6 Sep 2026 19:08:06 +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=1788721688; cv=none; b=mD2PqHkvxa/QumqgvwQ/4BJ+wuKjJOYhwmYb+QcZrtLA4k9mHARZXKH3ufeG5GaDioXwYvtjmDyuXuw4dYhUW55z8xAZU4cEXxVD2mtgwW2oEoQ07kyfc9ztCyGNRXbSa1zXEz/czv0BBxvM9efyEla6fK7HzXjVRFLHin3uOs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788721688; c=relaxed/simple; bh=PTsmbqRojGl6CSbqGrFEW+LREbHoHngSaDt9w4Z/zS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L1hzCFQA1rNyxErPg4CdxbC45g0SpabSI12Wi5qHv+Eml2r246AXHdJL8fR/vhWVLefWv0Ws64PerVgCJ1GCIFNW8gR0caAmYYmT0TGiwLlR9fya27TFYv/q7zfkBiWONN+dRsugjzTLENhP5NDU6WR6680F5A0x87tTH2rr4Ik= 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=RVz+tZv1; 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="RVz+tZv1" 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=RVz+tZv1wH5SLAczf4R0B4YshV zTlBSdiZz9NYd5MkpGZOmuf9UPqPspLV6Hv2i7Vl4gCM0mbK7HGMgzdw5EdxSAf8WiPq4i+hC5inp xse4zKJG9QW8q53leVL251sPKPermyfWQSnfxewDEGMQ9rM97YNk9GxT1j0fGRFp8VmAVjheFFfe3 4lQLXzK6gaZwz8vzBN/6RXuI8Y3pvjUcknqBxWuxr+q+Y2brx0nrZrA9+cFTg3K3LyUNoREBzz2V5 VkKhIAGAYA61m2Ex6hOAVLt6SsePJ17SK6JJL20tUugqRxj4hV8TwgkCCbR2Uc5udGjPRj6ZGK4TJ TGnqG6QQ==; Received: from pc by mx1.manguebit.org with local (Exim 4.99.5) id 1x3IDk-00000000o69-4Afx; Sun, 06 Sep 2026 16:08:04 -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 v3 4/7] smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr() Date: Sun, 6 Sep 2026 16:08:00 -0300 Message-ID: <20260906190803.667489-4-pc@manguebit.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260906190803.667489-1-pc@manguebit.org> References: <20260906190803.667489-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