Skip to contentSkip to conversation

ksmbd: add low bound validation to FSCTL_SET_ZERO_DATA

PATCH Superseded Namjae Jeon 2 participants 5 messages Mar 5, 2023 – Mar 7, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Namjae Jeon

author maintainer
#0 lore raw

PATCH 1/2 ksmbd: add low bound validation to FSCTL_SET_ZERO_DATA

Smatch static checker warning:
fs/ksmbd/smb2pdu.c:7759 smb2_ioctl()
warn: no lower bound on 'off'

Fix unexpected result that could caused from negative off and bfz.

Fixes b5e5f9dfc915 ("ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA")
---
 fs/ksmbd/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +1 -1
index 81e987114206..b7a420e0fcc4 100644
@@ -7757,7 +7757,7 @@ int smb2_ioctl(struct ksmbd_work *work)
 
 		off = le64_to_cpu(zero_data->FileOffset);
 		bfz = le64_to_cpu(zero_data->BeyondFinalZero);
-		if (off > bfz) {
+		if (off < 0 || bfz < 0 || off > bfz) {
 			ret = -EINVAL;
 			goto out;
 		}
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 2/2 ksmbd: add low bound validation to FSCTL_QUERY_ALLOCATED_RANGES

Smatch static checker warning:
fs/ksmbd/vfs.c:1040 ksmbd_vfs_fqar_lseek() warn: no lower bound on 'length' fs/ksmbd/vfs.c:1041 ksmbd_vfs_fqar_lseek() warn: no lower bound on 'start'

Fix unexpected result that could caused from negative start and length.

Fixes f44158485826 ("cifsd: add file operations")
---
 fs/ksmbd/smb2pdu.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/ksmbd/smb2pdu.c +5 -0
index b7a420e0fcc4..4af4230ab50b 100644
@@ -7457,6 +7457,11 @@ static int fsctl_query_allocated_ranges(struct ksmbd_work *work, u64 id,
 	start = le64_to_cpu(qar_req->file_offset);
 	length = le64_to_cpu(qar_req->length);
 
+	if (start < 0 || length < 0) {
+		ksmbd_fd_put(work, fp);
+		return -EINVAL;
+	}
+
 	ret = ksmbd_vfs_fqar_lseek(fp, start, length,
 				   qar_rsp, in_count, out_count);
 	if (ret && ret != -E2BIG)
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 2/2] ksmbd: add low bound validation to FSCTL_QUERY_ALLOCATED_RANGES

fs/ksmbd/smb2pdu.c static int fsctl_query_allocated_ranges(struct ksmbd_work *work, u64 id, · line 7463

Quoted 9 lines · Namjae Jeon

+++ b/fs/ksmbd/smb2pdu.c

fs/ksmbd/smb2pdu.c +4 -0
@@ -7457,6 +7457,11 @@ static int fsctl_query_allocated_ranges(struct ksmbd_work *work, u64 id,
 	start = le64_to_cpu(qar_req->file_offset);
 	length = le64_to_cpu(qar_req->length);
 
+	if (start < 0 || length < 0) {
+		ksmbd_fd_put(work, fp);
+		return -EINVAL;
+	}

Can we do sanity checking before we ksmbd_lookup_fd_fast()?

author maintainer
#3 lore raw

Re: [PATCH 2/2] ksmbd: add low bound validation to FSCTL_QUERY_ALLOCATED_RANGES

2023-03-07 13:09 GMT+09:00, Sergey Senozhatsky <[email protected]>:

Quoted 7 lines · Namjae Jeon
Quoted 6 lines

+++ b/fs/ksmbd/smb2pdu.c

fs/ksmbd/smb2pdu.c +0 -0
@@ -7457,6 +7457,11 @@ static int fsctl_query_allocated_ranges(struct
 ksmbd_work *work, u64 id,
 	start = le64_to_cpu(qar_req->file_offset);
 	length = le64_to_cpu(qar_req->length);
 
Quoted 6 lines

fs/ksmbd/smb2pdu.c static int fsctl_query_allocated_ranges(struct ksmbd_work *work, u64 id, · line 7463

Quoted 4 lines
fs/ksmbd/smb2pdu.c +4 -0
+	if (start < 0 || length < 0) {
+		ksmbd_fd_put(work, fp);
+		return -EINVAL;
+	}

Can we do sanity checking before we ksmbd_lookup_fd_fast()?

We can:), will update it on v2.

Thanks!

Quoted 1 line
reviewer Reviewed-by on v1 1/2
#4 lore raw
In reply to Namjae Jeon
Quoted 9 lines · Namjae Jeon

Smatch static checker warning:
fs/ksmbd/smb2pdu.c:7759 smb2_ioctl()
warn: no lower bound on 'off'

Fix unexpected result that could caused from negative off and bfz.

Fixes b5e5f9dfc915 ("ksmbd: check invalid FileOffset and BeyondFinalZero in FSCTL_ZERO_DATA")