From mboxrd@z Thu Jan 1 00:00:00 1970 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 A7BD438B15B; Sat, 12 Sep 2026 18:34:28 +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=1789238069; cv=none; b=lHpTVbkRG+W+X+D9PI4vWHJwQ+p2dubnF4hU25lgadvIP5Ht9qA0NMCTSauZn6RGQeEsyPsjZ6IhcudyoqfwQDzmGrlPwv0Q0++FhqCNXhyoyOqGVuK1Sek+xbly2hbFPJVnCrZSqRoU+x8UuXDNLkuPnDDxOaYlevsPJBwvCVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789238069; c=relaxed/simple; bh=TTJ+S4UU76FsGb4JA8v65POHsFgX5XVArGEAZaUATKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Up/CiECMQRrMn4bnUUS/CbbW6t/YYHZtgx/NNrmjyCUSCNQ6M1apQPRa9Ka1K8OISPrhdHcE+gbhvn8TFsmjaDAv9GWygyUhbuH1NGzLGmJDRjTMCkvt3opppMzWgy6M8pxLNRBdVOe/OFTcH8a8tAVWxqlFJgSk9J0gaaWs21g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DlRn0HwZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DlRn0HwZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEC261F000FF; Sat, 12 Sep 2026 18:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789238068; bh=tPVr85ru6agZD1Ofrj8YUw4JEZ++w82f/Mo+0MSUb+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DlRn0HwZpnCr0UswHxPkvEzH4QVs4AWwCRjjAnBQm9Li28ukTGqXHAV+l//bd/5qC 8UNJQwXbSULnpi7BmfHKBxue111DDirYdGTNJqBtsftDiYujAzUhYIGc5c0L2ELF+w pjvpcrMKFrablDfamDfCcKH4s5okoyijzRsVe2yc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Namjae Jeon , Sergey Senozhatsky , Steve French , Sean Shen , Steve French , Sasha Levin Subject: [PATCH 5.15 386/935] ksmbd: fix FSCTL permission bypass by adding a permission check for FSCTL_SET_SPARSE Date: Sat, 12 Sep 2026 08:56:56 +0200 Message-ID: <20260912065535.673616095@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065526.833703348@linuxfoundation.org> References: <20260912065526.833703348@linuxfoundation.org> User-Agent: quilt/0.69 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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Shen [ Upstream commit cc57232cae23c0df91b4a59d0f519141ce9b5b02 ] FSCTL_SET_SPARSE in fsctl_set_sparse() modifies the file's sparse attribute and saves it through xattr without any permission checks. This exposes two issues: 1) A client on a read-only share can change the sparse attribute on files it opened, even though the share is read-only. Other FSCTL write operations already check test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE), but FSCTL_SET_SPARSE does not. 2) Even on writable shares, clients without FILE_WRITE_DATA or FILE_WRITE_ATTRIBUTES access should not modify the sparse attribute. Similar handle-level checks exist in other functions but are missing here. Add both share-level writable check and per-handle access check. Use goto out on error to avoid leaking file references. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Cc: Namjae Jeon Cc: Sergey Senozhatsky Cc: Steve French Signed-off-by: Sean Shen Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/ksmbd/smb2pdu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index cd3e475bfb309..2ffd78ef7da26 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -7667,9 +7667,19 @@ static inline int fsctl_set_sparse(struct ksmbd_work *work, u64 id, int ret = 0; __le32 old_fattr; + if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { + ksmbd_debug(SMB, "User does not have write permission\n"); + return -EACCES; + } + fp = ksmbd_lookup_fd_fast(work, id); if (!fp) return -ENOENT; + if (!(fp->daccess & (FILE_WRITE_DATA_LE | FILE_WRITE_ATTRIBUTES_LE))) { + ret = -EACCES; + goto out; + } + user_ns = file_mnt_user_ns(fp->filp); old_fattr = fp->f_ci->m_fattr; -- 2.53.0