Skip to contentSkip to conversation

ksmbd: Replace one-element arrays with flexible-array members

PATCH In review Thorsten Blum 3 participants 5 messages Aug 18, 2024 – Aug 20, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: Replace one-element arrays with flexible-array members

Replace the deprecated one-element arrays with flexible-array members in the structs copychunk_ioctl_req and smb2_ea_info_req.

There are no binary differences after this conversion.

---
 fs/smb/server/smb2pdu.c | 4 ++--
 fs/smb/server/smb2pdu.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +2 -2
index 2df1354288e6..83667cb78fa6 100644
@@ -4580,7 +4580,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
 	/* single EA entry is requested with given user.* name */
 	if (req->InputBufferLength) {
 		if (le32_to_cpu(req->InputBufferLength) <
-		    sizeof(struct smb2_ea_info_req))
+		    sizeof(struct smb2_ea_info_req) + 1)
 			return -EINVAL;
 
 		ea_req = (struct smb2_ea_info_req *)((char *)req +
@@ -8083,7 +8083,7 @@ int smb2_ioctl(struct ksmbd_work *work)
 			goto out;
 		}
 
-		if (in_buf_len < sizeof(struct copychunk_ioctl_req)) {
+		if (in_buf_len < sizeof(struct copychunk_ioctl_req) + 1) {
 			ret = -EINVAL;
 			goto out;
 		}
fs/smb/server/smb2pdu.h +2 -2
index 3be7d5ae65a8..73aff20e22d0 100644
@@ -194,7 +194,7 @@ struct copychunk_ioctl_req {
 	__le64 ResumeKey[3];
 	__le32 ChunkCount;
 	__le32 Reserved;
-	__u8 Chunks[1]; /* array of srv_copychunk */
+	__u8 Chunks[]; /* array of srv_copychunk */
 } __packed;
 
 struct srv_copychunk {
@@ -370,7 +370,7 @@ struct smb2_file_attr_tag_info {
 struct smb2_ea_info_req {
 	__le32 NextEntryOffset;
 	__u8   EaNameLength;
-	char name[1];
+	char name[];
 } __packed; /* level 15 Query */
 
 struct smb2_ea_info {
Signature · 1 line
2.46.0
maintainer
#1 lore raw
Quoted 18 lines · Thorsten Blum

Replace the deprecated one-element arrays with flexible-array members in the structs copychunk_ioctl_req and smb2_ea_info_req.

There are no binary differences after this conversion.

---
 fs/smb/server/smb2pdu.c | 4 ++--
 fs/smb/server/smb2pdu.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +0 -0
index 2df1354288e6..83667cb78fa6 100644

fs/smb/server/smb2pdu.c static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp, · line 4583

Quoted 5 lines
fs/smb/server/smb2pdu.c +1 -1
@@ -4580,7 +4580,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
        /* single EA entry is requested with given user.* name */
        if (req->InputBufferLength) {
                if (le32_to_cpu(req->InputBufferLength) <
-                   sizeof(struct smb2_ea_info_req))
+                   sizeof(struct smb2_ea_info_req) + 1)

We can use <= instead of +1.

fs/smb/server/smb2pdu.c int smb2_ioctl(struct ksmbd_work *work) · line 8086

Quoted 9 lines
fs/smb/server/smb2pdu.c +1 -1
                        return -EINVAL;
 
                ea_req = (struct smb2_ea_info_req *)((char *)req +
@@ -8083,7 +8083,7 @@ int smb2_ioctl(struct ksmbd_work *work)
                        goto out;
                }
 
-               if (in_buf_len < sizeof(struct copychunk_ioctl_req)) {
+               if (in_buf_len < sizeof(struct copychunk_ioctl_req) + 1) {

Ditto.

Quoted 28 lines
fs/smb/server/smb2pdu.c +0 -0
                        ret = -EINVAL;
                        goto out;
                }
fs/smb/server/smb2pdu.h +2 -3
index 3be7d5ae65a8..73aff20e22d0 100644
@@ -194,7 +194,7 @@ struct copychunk_ioctl_req {
        __le64 ResumeKey[3];
        __le32 ChunkCount;
        __le32 Reserved;
-       __u8 Chunks[1]; /* array of srv_copychunk */
+       __u8 Chunks[]; /* array of srv_copychunk */
 } __packed;
 
 struct srv_copychunk {
@@ -370,7 +370,7 @@ struct smb2_file_attr_tag_info {
 struct smb2_ea_info_req {
        __le32 NextEntryOffset;
        __u8   EaNameLength;
-       char name[1];
+       char name[];
 } __packed; /* level 15 Query */
 
 struct smb2_ea_info {
--

2.46.0

reviewer
#2 lore raw
Quoted 14 lines · Namjae Jeon
Quoted 13 lines · Thorsten Blum

Replace the deprecated one-element arrays with flexible-array members in the structs copychunk_ioctl_req and smb2_ea_info_req.

There are no binary differences after this conversion.

---
  fs/smb/server/smb2pdu.c | 4 ++--
  fs/smb/server/smb2pdu.h | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines

fs/smb/server/smb2pdu.c static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp, · line 4583

Quoted 10 lines
fs/smb/server/smb2pdu.c +1 -1
index 2df1354288e6..83667cb78fa6 100644
@@ -4580,7 +4580,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
         /* single EA entry is requested with given user.* name */
         if (req->InputBufferLength) {
                 if (le32_to_cpu(req->InputBufferLength) <
-                   sizeof(struct smb2_ea_info_req))
+                   sizeof(struct smb2_ea_info_req) + 1)

We can use <= instead of +1.

This is better, but maybe this test was actually not right in the first place.

I think a strict "<" is correct here, because the ea name field is a counted array of length EaNameLength. So, it's a layering issue to fail with EINVAL this early in the processing. All that should be checked up front is that a complete smb2_ea_info_req header is present.

Quoted 10 lines

fs/smb/server/smb2pdu.c int smb2_ioctl(struct ksmbd_work *work) · line 8086

Quoted 9 lines
fs/smb/server/smb2pdu.c +1 -1
                         return -EINVAL;
 
                 ea_req = (struct smb2_ea_info_req *)((char *)req +
@@ -8083,7 +8083,7 @@ int smb2_ioctl(struct ksmbd_work *work)
                         goto out;
                 }
 
-               if (in_buf_len < sizeof(struct copychunk_ioctl_req)) {
+               if (in_buf_len < sizeof(struct copychunk_ioctl_req) + 1) {

Ditto.

And ditto.

Tom.

Quoted 29 lines
Quoted 28 lines
fs/smb/server/smb2pdu.c +0 -0
                         ret = -EINVAL;
                         goto out;
                 }
fs/smb/server/smb2pdu.h +2 -3
index 3be7d5ae65a8..73aff20e22d0 100644
@@ -194,7 +194,7 @@ struct copychunk_ioctl_req {
         __le64 ResumeKey[3];
         __le32 ChunkCount;
         __le32 Reserved;
-       __u8 Chunks[1]; /* array of srv_copychunk */
+       __u8 Chunks[]; /* array of srv_copychunk */
  } __packed;
 
  struct srv_copychunk {
@@ -370,7 +370,7 @@ struct smb2_file_attr_tag_info {
  struct smb2_ea_info_req {
         __le32 NextEntryOffset;
         __u8   EaNameLength;
-       char name[1];
+       char name[];
  } __packed; /* level 15 Query */
 
  struct smb2_ea_info {
--

2.46.0

#3 lore raw
Quoted 27 lines · Tom Talpey
Quoted 14 lines · Namjae Jeon
Quoted 13 lines · Thorsten Blum

Replace the deprecated one-element arrays with flexible-array members in the structs copychunk_ioctl_req and smb2_ea_info_req.

There are no binary differences after this conversion.

---
 fs/smb/server/smb2pdu.c | 4 ++--
 fs/smb/server/smb2pdu.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines

fs/smb/server/smb2pdu.c static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp, · line 4583

Quoted 10 lines
fs/smb/server/smb2pdu.c +1 -1
index 2df1354288e6..83667cb78fa6 100644
@@ -4580,7 +4580,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
        /* single EA entry is requested with given user.* name */
        if (req->InputBufferLength) {
                if (le32_to_cpu(req->InputBufferLength) <
-                   sizeof(struct smb2_ea_info_req))
+                   sizeof(struct smb2_ea_info_req) + 1)

We can use <= instead of +1.

Quoted 8 lines

This is better, but maybe this test was actually not right in the first place.

I think a strict "<" is correct here, because the ea name field is a counted array of length EaNameLength. So, it's a layering issue to fail with EINVAL this early in the processing. All that should be checked up front is that a complete smb2_ea_info_req header is present.

Just to clarify before I submit a v2: Is a strict "<" and without "+1" correct?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
fs/smb/server/smb2pdu.c +0 -0
                        return -EINVAL;
 
                ea_req = (struct smb2_ea_info_req *)((char *)req +
@@ -8083,7 +8083,7 @@ int smb2_ioctl(struct ksmbd_work *work)
                        goto out;
                }
 
Quoted 5 lines
Quoted 3 lines

fs/smb/server/smb2pdu.c int smb2_ioctl(struct ksmbd_work *work) · line 8086

Quoted 2 lines
fs/smb/server/smb2pdu.c +1 -1
-               if (in_buf_len < sizeof(struct copychunk_ioctl_req)) {
+               if (in_buf_len < sizeof(struct copychunk_ioctl_req) + 1) {

Ditto.

And ditto.

Same here, strict "<" and without "+ 1"? Or just a refactor to "<=" without changing the condition?

Thanks,
Thorsten

reviewer
#4 lore raw
Quoted 31 lines · Thorsten Blum
Quoted 30 lines · Tom Talpey
Quoted 14 lines · Namjae Jeon
Quoted 13 lines · Thorsten Blum

Replace the deprecated one-element arrays with flexible-array members in the structs copychunk_ioctl_req and smb2_ea_info_req.

There are no binary differences after this conversion.

---
  fs/smb/server/smb2pdu.c | 4 ++--
  fs/smb/server/smb2pdu.h | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 11 lines

fs/smb/server/smb2pdu.c static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp, · line 4583

Quoted 10 lines
fs/smb/server/smb2pdu.c +1 -1
index 2df1354288e6..83667cb78fa6 100644
@@ -4580,7 +4580,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
         /* single EA entry is requested with given user.* name */
         if (req->InputBufferLength) {
                 if (le32_to_cpu(req->InputBufferLength) <
-                   sizeof(struct smb2_ea_info_req))
+                   sizeof(struct smb2_ea_info_req) + 1)

We can use <= instead of +1.

This is better, but maybe this test was actually not right in the first place.

Quoted 8 lines
Quoted 5 lines

I think a strict "<" is correct here, because the ea name field is a counted array of length EaNameLength. So, it's a layering issue to fail with EINVAL this early in the processing. All that should be checked up front is that a complete smb2_ea_info_req header is present.

Just to clarify before I submit a v2: Is a strict "<" and without "+1" correct?

Maybe safest with "<=", because it changes no behavior.

I do think there is an issue with the test, because it is just checking for one byte of the EaName and not even checking EaNameLength, and similar for copychunk.

But these are pre-existing protocol parsing matters, not flex array ones. We can discuss those later.

Tom.

Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
fs/smb/server/smb2pdu.c +0 -0
                         return -EINVAL;
 
                 ea_req = (struct smb2_ea_info_req *)((char *)req +
@@ -8083,7 +8083,7 @@ int smb2_ioctl(struct ksmbd_work *work)
                         goto out;
                 }
 
Quoted 5 lines
Quoted 3 lines

fs/smb/server/smb2pdu.c int smb2_ioctl(struct ksmbd_work *work) · line 8086

Quoted 2 lines
fs/smb/server/smb2pdu.c +1 -1
-               if (in_buf_len < sizeof(struct copychunk_ioctl_req)) {
+               if (in_buf_len < sizeof(struct copychunk_ioctl_req) + 1) {

Ditto.

And ditto.

Same here, strict "<" and without "+ 1"? Or just a refactor to "<=" without changing the condition?

Thanks,
Thorsten