From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8E73223762; Thu, 18 Jan 2024 11:02:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705575738; cv=none; b=WkWrsHeMgTRPK8e1VlFfq4/fHXaBjgFcN9Fh1zVUyiecNPZOqeqaLbIMjcPtS0Pa96xR6qq1uk3+L6bf9wNc4LvAYzIVVGiMVJCe+TJICjY6DWjxOw6RTSxhNb7gp1NeOUa5kmIBKmAEpl8LDIc5oBOxWwfE6qwb2AeaHfRVQMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705575738; c=relaxed/simple; bh=OC0veZ/nrX4tj42CF5VTZbJnTuZ6K3g8CZec77mgoxs=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:User-Agent:X-stable: X-Patchwork-Hint:MIME-Version:Content-Transfer-Encoding; b=KjmNUbfMmz1gRyD4hLtyxQmwrAF/dMQBWyKeX1mh9/QSVKChRR5nbKBEdNEUGi1Ph2vcU1CM6etbrYN2ZWCVoS/VMHy5L2vNWJ1mgw6M3WvCXMUAJ2iBe50quyndE1XLPih2j5+Nl2l4KCQ6BaFkJ1WEzxuLuPWGy4SCANtisDo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IsGertn/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="IsGertn/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EF6EC433F1; Thu, 18 Jan 2024 11:02:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705575738; bh=OC0veZ/nrX4tj42CF5VTZbJnTuZ6K3g8CZec77mgoxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IsGertn/nNMWpazbPXWiGKpn9iLcz6jPpMIWzxS/pdmxl62r7l/mq87/6q1DIXXsp zVzjPrr1L8a7ze3Id/pU+k0U7gwENYXanH0FPIOp/UbUaILNYK1EsXplfr0prCr27W ZL2gMt7nfEEFQhGve8wTjlsvXDXjOEn4zoX+Go8k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Namjae Jeon , Steve French Subject: [PATCH 6.1 087/100] ksmbd: dont allow O_TRUNC open on read-only share Date: Thu, 18 Jan 2024 11:49:35 +0100 Message-ID: <20240118104314.682080769@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118104310.892180084@linuxfoundation.org> References: <20240118104310.892180084@linuxfoundation.org> User-Agent: quilt/0.67 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: Namjae Jeon commit d592a9158a112d419f341f035d18d02f8d232def upstream. When file is changed using notepad on read-only share(read_only = yes in ksmbd.conf), There is a problem where existing data is truncated. notepad in windows try to O_TRUNC open(FILE_OVERWRITE_IF) and all data in file is truncated. This patch don't allow O_TRUNC open on read-only share and add KSMBD_TREE_CONN_FLAG_WRITABLE check in smb2_set_info(). Cc: stable@vger.kernel.org Signed-off-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/smb/server/smb2pdu.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -2969,7 +2969,7 @@ int smb2_open(struct ksmbd_work *work) &may_flags); if (!test_tree_conn_flag(tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { - if (open_flags & O_CREAT) { + if (open_flags & (O_CREAT | O_TRUNC)) { ksmbd_debug(SMB, "User does not have write permission\n"); rc = -EACCES; @@ -5941,12 +5941,6 @@ static int smb2_set_info_file(struct ksm } case FILE_RENAME_INFORMATION: { - if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { - ksmbd_debug(SMB, - "User does not have write permission\n"); - return -EACCES; - } - if (buf_len < sizeof(struct smb2_file_rename_info)) return -EINVAL; @@ -5966,12 +5960,6 @@ static int smb2_set_info_file(struct ksm } case FILE_DISPOSITION_INFORMATION: { - if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { - ksmbd_debug(SMB, - "User does not have write permission\n"); - return -EACCES; - } - if (buf_len < sizeof(struct smb2_file_disposition_info)) return -EINVAL; @@ -6033,7 +6021,7 @@ int smb2_set_info(struct ksmbd_work *wor { struct smb2_set_info_req *req; struct smb2_set_info_rsp *rsp; - struct ksmbd_file *fp; + struct ksmbd_file *fp = NULL; int rc = 0; unsigned int id = KSMBD_NO_FID, pid = KSMBD_NO_FID; @@ -6053,6 +6041,13 @@ int smb2_set_info(struct ksmbd_work *wor rsp = smb2_get_msg(work->response_buf); } + if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { + ksmbd_debug(SMB, "User does not have write permission\n"); + pr_err("User does not have write permission\n"); + rc = -EACCES; + goto err_out; + } + if (!has_file_id(id)) { id = req->VolatileFileId; pid = req->PersistentFileId;