Skip to contentSkip to conversation

ksmbd: fix partial normalized name responses

PATCH In review Namjae Jeon 2 participants 8 messages Sep 13 – Sep 14

Subsystems (2)
lore
Share & tools
lore

Namjae Jeon

author maintainer
#0 lore raw

PATCH 2/3 ksmbd: fix partial normalized name responses

Windows may request FILE_NORMALIZED_NAME_INFORMATION with an output buffer that only fits the fixed portion of the variable-length response. Treat the fixed portion as FILE_ALTERNATE_NAME_INFORMATION_SIZE so ksmbd returns STATUS_BUFFER_OVERFLOW instead of STATUS_INFO_LENGTH_MISMATCH.

This avoids rejecting valid partial normalized-name responses.

Fixes 6b8b79226bc3 ("ksmbd: fix partial file information responses")
---
 fs/smb/server/smb2pdu.c | 3 +++
 1 file changed, 3 insertions(+)
fs/smb/server/smb2pdu.c +3 -0
index f4d96799e1d2..38cddbf3e6ed 100644
@@ -7318,6 +7318,9 @@ static int smb2_get_info_file(struct ksmbd_work *work,
 		case FILE_ALTERNATE_NAME_INFORMATION:
 			fixed_len = FILE_ALTERNATE_NAME_INFORMATION_SIZE;
 			break;
+		case FILE_NORMALIZED_NAME_INFORMATION:
+			fixed_len = FILE_ALTERNATE_NAME_INFORMATION_SIZE;
+			break;
 		case FILE_STREAM_INFORMATION:
 			fixed_len = FILE_STREAM_INFORMATION_SIZE;
 			break;
Signature · 1 line
2.25.1
reviewer
#1 lore raw

Should we define a new macro FILE_NORMALIZED_NAME_INFORMATION_SIZE?

Quoted 2 lines · Namjae Jeon
fs/smb/server/smb2pdu.c +2 -0
+		case FILE_NORMALIZED_NAME_INFORMATION:
+			fixed_len = FILE_ALTERNATE_NAME_INFORMATION_SIZE;
Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
author maintainer
#2 lore raw
Quoted 2 lines · ChenXiaoSong

Should we define a new macro FILE_NORMALIZED_NAME_INFORMATION_SIZE?

Okay, I will add it in v2 patch.
Thanks for the review.

reviewer
#3 lore raw
In reply to Namjae Jeon

Hi Namjae,

According to MS-FSA 2.1.5.12.30: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/3d5c68f8-fbc5-4f94-a51d-3600a319fd45

Set AvailableNameLength to BlockAlignTruncate((OutputBufferSize -
FieldOffset(FILE_NAME_INFORMATION.FileName)), 2).

It seems that the following changes are also needed:

```
smb2_get_info_file()
{
        unsigned int req_output_len = le32_to_cpu(req->OutputBufferLength);
...
        case FILE_NORMALIZED_NAME_INFORMATION:
                fixed_len = FILE_NORMALIZED_NAME_INFORMATION_SIZE;
                req_output_len = round_down(req_output_len, 2);
                break;
...
        rc = buffer_check_err(req_output_len, fixed_len, rsp);
}
```

By the way, it seems that struct smb2_file_alt_name_info should be renamed to struct smb2_file_name_info, since both FILE_ALTERNATE_NAME_INFORMATION and FILE_NORMALIZED_NAME_INFORMATION use this structure. See:
- MS-FSA 2.1.5.12.4 FileAlternateNameInformation: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/5051d021-8d06-4b7e-94e3-55b118193427
- MS-FSA 2.1.5.12.30 FileNormalizedNameInformation: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/3d5c68f8-fbc5-4f94-a51d-3600a319fd45

Quoted 28 lines · Namjae Jeon

Windows may request FILE_NORMALIZED_NAME_INFORMATION with an output buffer that only fits the fixed portion of the variable-length response. Treat the fixed portion as FILE_ALTERNATE_NAME_INFORMATION_SIZE so ksmbd returns STATUS_BUFFER_OVERFLOW instead of STATUS_INFO_LENGTH_MISMATCH.

This avoids rejecting valid partial normalized-name responses.

Fixes 6b8b79226bc3 ("ksmbd: fix partial file information responses")
---
  fs/smb/server/smb2pdu.c | 3 +++
  1 file changed, 3 insertions(+)
fs/smb/server/smb2pdu.c +3 -0
index f4d96799e1d2..38cddbf3e6ed 100644
@@ -7318,6 +7318,9 @@ static int smb2_get_info_file(struct ksmbd_work *work,
  		case FILE_ALTERNATE_NAME_INFORMATION:
  			fixed_len = FILE_ALTERNATE_NAME_INFORMATION_SIZE;
  			break;
+		case FILE_NORMALIZED_NAME_INFORMATION:
+			fixed_len = FILE_ALTERNATE_NAME_INFORMATION_SIZE;
+			break;
  		case FILE_STREAM_INFORMATION:
  			fixed_len = FILE_STREAM_INFORMATION_SIZE;
  			break;
Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
reviewer
#4 lore raw

If needed, I would be happy to help send v2.

And it would be better to use FILE_NAME_INFORMATION_SIZE (should be changed to 8) instead of FILE_ALTERNATE_NAME_INFORMATION_SIZE.

```
smb2_get_info_file()
{
...
	case FILE_ALTERNATE_NAME_INFORMATION:
        case FILE_NORMALIZED_NAME_INFORMATION:
                fixed_len = FILE_NAME_INFORMATION_SIZE; // 8
...
}
```
Quoted 28 lines · ChenXiaoSong

Hi Namjae,

According to MS-FSA 2.1.5.12.30: https://learn.microsoft.com/en-us/ openspecs/windows_protocols/ms-fsa/3d5c68f8-fbc5-4f94-a51d-3600a319fd45

  Set AvailableNameLength to BlockAlignTruncate((OutputBufferSize -
FieldOffset(FILE_NAME_INFORMATION.FileName)), 2).

It seems that the following changes are also needed:

```
smb2_get_info_file()
{
         unsigned int req_output_len = le32_to_cpu(req- 
 >OutputBufferLength);
...
         case FILE_NORMALIZED_NAME_INFORMATION:
                 fixed_len = FILE_NORMALIZED_NAME_INFORMATION_SIZE;
                 req_output_len = round_down(req_output_len, 2);
                 break;
...
         rc = buffer_check_err(req_output_len, fixed_len, rsp);
}
```

By the way, it seems that struct smb2_file_alt_name_info should be renamed to struct smb2_file_name_info, since both FILE_ALTERNATE_NAME_INFORMATION and FILE_NORMALIZED_NAME_INFORMATION use this structure. See:
- MS-FSA 2.1.5.12.4 FileAlternateNameInformation: https://
learn.microsoft.com/en-us/openspecs/windows_protocols/ms- fsa/5051d021-8d06-4b7e-94e3-55b118193427
- MS-FSA 2.1.5.12.30 FileNormalizedNameInformation: https://
learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/3d5c68f8- fbc5-4f94-a51d-3600a319fd45

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
author maintainer
#5 lore raw
In reply to ChenXiaoSong
Quoted 24 lines · ChenXiaoSong

Hi Namjae,

According to MS-FSA 2.1.5.12.30:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/3d5c68f8-fbc5-4f94-a51d-3600a319fd45

Set AvailableNameLength to BlockAlignTruncate((OutputBufferSize -
FieldOffset(FILE_NAME_INFORMATION.FileName)), 2).

It seems that the following changes are also needed:

```
smb2_get_info_file()
{
         unsigned int req_output_len = le32_to_cpu(req->OutputBufferLength);
...
         case FILE_NORMALIZED_NAME_INFORMATION:
                 fixed_len = FILE_NORMALIZED_NAME_INFORMATION_SIZE;
                 req_output_len = round_down(req_output_len, 2);
                 break;
...
         rc = buffer_check_err(req_output_len, fixed_len, rsp);
}
```
Quoted 8 lines

By the way, it seems that struct smb2_file_alt_name_info should be renamed to struct smb2_file_name_info, since both FILE_ALTERNATE_NAME_INFORMATION and FILE_NORMALIZED_NAME_INFORMATION use this structure. See:
- MS-FSA 2.1.5.12.4 FileAlternateNameInformation:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/5051d021-8d06-4b7e-94e3-55b118193427
- MS-FSA 2.1.5.12.30 FileNormalizedNameInformation:
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/3d5c68f8-fbc5-4f94-a51d-3600a319fd45

I think that both of them are changed in another patches.

reviewer
#6 lore raw

It seems that ksmbd-for-next has not been updated yet. Have you not pushed it yet?

Quoted 1 line · Namjae Jeon

I think that both of them are changed in another patches.

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en
author maintainer
#7 lore raw
Quoted 3 lines · ChenXiaoSong

It seems that ksmbd-for-next has not been updated yet. Have you not pushed it yet?

Done it now.
Thanks!