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 0F9F938837C; Sat, 12 Sep 2026 16:00:04 +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=1789228806; cv=none; b=AXva5tZ+SdlugcjxBiWWglcB081JdPOnZryedtnrCow52iY06yPMten9NHeG5nTnp/ELMdsReX/g9Ny430821BqIL7XT7qbwFkMXCIDa8EriRDNmPqw72gmE0gEA7o1lkyLGDRsb6I59WOP7bbgeCexy8q4W2WJN82mCwFBQWVM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789228806; c=relaxed/simple; bh=iBr+GMr4i/TvYz3CG+fQo6ey5d51QkRy6mErQIuZpB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OJVhgV6hNemjztkKK4XuS7KWuY9tFQwmy9DIc87H49FryoK/+/uLqoPrBkkSzFYGgTZqlcXFqVwdGIsQMcNpZ+vX9+M+xtMrmUcchbZhPYFNW4e6du7C1tPzjZjY+imBTaHmVpJysAd5AXWoM+UtZwrNl9QvHtDnVoTbOZYdQZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=s/5UBjG7; 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="s/5UBjG7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3ABB1F000FF; Sat, 12 Sep 2026 16:00:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789228804; bh=GGeg+31GYo1bZl2xwJ/nJ7iCaGrs4YxIFLa+6EWuAE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=s/5UBjG7q47dXE3N2i9etTJ0kAJE2/trtX1h4JZgIuvqnfip0IcLTtk2lz5oLKxU6 hlX91+IBKySxgpLwEmv4R3JG4wyaT9OR/2OvPpNWlHzahCYqvX4OvCXAcoHY7YCeGz hfd3jNgU2t79xQlE2RYqunn66Ztxrm/+dgQ7Fu5w= 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 6.1 0458/1191] ksmbd: fix FSCTL permission bypass by adding a permission check for FSCTL_SET_SPARSE Date: Sat, 12 Sep 2026 08:53:06 +0200 Message-ID: <20260912065558.522035225@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@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 6.1-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/smb/server/smb2pdu.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index cefdac6e8cedc..bddf03ec337ee 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -7726,9 +7726,20 @@ 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