Commit d592a915 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French

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: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 8d99c113
...@@ -2972,7 +2972,7 @@ int smb2_open(struct ksmbd_work *work) ...@@ -2972,7 +2972,7 @@ int smb2_open(struct ksmbd_work *work)
&may_flags); &may_flags);
if (!test_tree_conn_flag(tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) { 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, ksmbd_debug(SMB,
"User does not have write permission\n"); "User does not have write permission\n");
rc = -EACCES; rc = -EACCES;
...@@ -5944,12 +5944,6 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp, ...@@ -5944,12 +5944,6 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
} }
case FILE_RENAME_INFORMATION: 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)) if (buf_len < sizeof(struct smb2_file_rename_info))
return -EINVAL; return -EINVAL;
...@@ -5969,12 +5963,6 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp, ...@@ -5969,12 +5963,6 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
} }
case FILE_DISPOSITION_INFORMATION: 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)) if (buf_len < sizeof(struct smb2_file_disposition_info))
return -EINVAL; return -EINVAL;
...@@ -6036,7 +6024,7 @@ int smb2_set_info(struct ksmbd_work *work) ...@@ -6036,7 +6024,7 @@ int smb2_set_info(struct ksmbd_work *work)
{ {
struct smb2_set_info_req *req; struct smb2_set_info_req *req;
struct smb2_set_info_rsp *rsp; struct smb2_set_info_rsp *rsp;
struct ksmbd_file *fp; struct ksmbd_file *fp = NULL;
int rc = 0; int rc = 0;
unsigned int id = KSMBD_NO_FID, pid = KSMBD_NO_FID; unsigned int id = KSMBD_NO_FID, pid = KSMBD_NO_FID;
...@@ -6056,6 +6044,13 @@ int smb2_set_info(struct ksmbd_work *work) ...@@ -6056,6 +6044,13 @@ int smb2_set_info(struct ksmbd_work *work)
rsp = smb2_get_msg(work->response_buf); 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)) { if (!has_file_id(id)) {
id = req->VolatileFileId; id = req->VolatileFileId;
pid = req->PersistentFileId; pid = req->PersistentFileId;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment