Skip to content

Commit d592a91

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: don't allow O_TRUNC open on read-only share
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 <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 8d99c11 commit d592a91

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ int smb2_open(struct ksmbd_work *work)
29722972
&may_flags);
29732973

29742974
if (!test_tree_conn_flag(tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
2975-
if (open_flags & O_CREAT) {
2975+
if (open_flags & (O_CREAT | O_TRUNC)) {
29762976
ksmbd_debug(SMB,
29772977
"User does not have write permission\n");
29782978
rc = -EACCES;
@@ -5944,12 +5944,6 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
59445944
}
59455945
case FILE_RENAME_INFORMATION:
59465946
{
5947-
if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
5948-
ksmbd_debug(SMB,
5949-
"User does not have write permission\n");
5950-
return -EACCES;
5951-
}
5952-
59535947
if (buf_len < sizeof(struct smb2_file_rename_info))
59545948
return -EINVAL;
59555949

@@ -5969,12 +5963,6 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
59695963
}
59705964
case FILE_DISPOSITION_INFORMATION:
59715965
{
5972-
if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
5973-
ksmbd_debug(SMB,
5974-
"User does not have write permission\n");
5975-
return -EACCES;
5976-
}
5977-
59785966
if (buf_len < sizeof(struct smb2_file_disposition_info))
59795967
return -EINVAL;
59805968

@@ -6036,7 +6024,7 @@ int smb2_set_info(struct ksmbd_work *work)
60366024
{
60376025
struct smb2_set_info_req *req;
60386026
struct smb2_set_info_rsp *rsp;
6039-
struct ksmbd_file *fp;
6027+
struct ksmbd_file *fp = NULL;
60406028
int rc = 0;
60416029
unsigned int id = KSMBD_NO_FID, pid = KSMBD_NO_FID;
60426030

@@ -6056,6 +6044,13 @@ int smb2_set_info(struct ksmbd_work *work)
60566044
rsp = smb2_get_msg(work->response_buf);
60576045
}
60586046

6047+
if (!test_tree_conn_flag(work->tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
6048+
ksmbd_debug(SMB, "User does not have write permission\n");
6049+
pr_err("User does not have write permission\n");
6050+
rc = -EACCES;
6051+
goto err_out;
6052+
}
6053+
60596054
if (!has_file_id(id)) {
60606055
id = req->VolatileFileId;
60616056
pid = req->PersistentFileId;

0 commit comments

Comments
 (0)