* [PATCH] smb: client: fix shift of SID authority[0] in sid_to_key_str()
@ 2026-12-02 16:01 ` Anh Nguyen Hoang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Anh Nguyen Hoang @ 2026-12-02 16:01 UTC (permalink / raw)
To: Paulo Alcantara, Namjae Jeon
Cc: Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Jeff Layton, Steve French, Pavel Shilovsky, linux-cifs,
samba-technical, Anh Nguyen Hoang
sid_to_key_str() builds the description of the cifs.idmap key from a
SID. The identifier authority is a 48-bit big-endian number held in six
bytes, and the function assembles it by shifting authority[5]..[1] by 0,
8, 16, 24 and 32 bits. authority[0] is then shifted by 48 instead of 40,
which leaves bits 40-47 empty and puts the top byte in bits 48-55.
A SID whose first authority byte is not zero is therefore converted to
the wrong string, and the idmap upcall is asked to map a SID other than
the one the server sent.
The value can also need 14 hex digits, while SID_STRING_BASE_SIZE
reserves room for "-0x" plus 12. With a revision of two or three digits
the string no longer fits and sprintf() writes one or two bytes past
the size requested from kmalloc().
Shift authority[0] by 40 so that the authority is the 48-bit value the
comment and the buffer size expect.
Found by a static analysis tool.
Fixes: 193cdd8a2930 ("cifs: fix SID binary to string conversion")
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
Runtime test: QEMU, x86_64 defconfig + CIFS + KASAN, on cifs-next
5449fa133d3a, mounting a loopback SMB2.1 server with cifsacl returning a
SID with revision 255, authority 12:34:56:78:9a:bc, and 0 subauthorities.
Before the patch: KASAN reports a slab-out-of-bounds write past the
24-byte allocation and request-key receives "os:S-255-0x12003456789abc".
After the patch: no KASAN error and request-key receives
"os:S-255-0x123456789abc".
Testing:
- Compile-tested on x86_64 (allmodconfig, W=1): fs/smb/client/cifsacl.o;
no new warnings.
- checkpatch.pl --strict: no errors or warnings.
This patch was drafted with AI assistance (Claude, claude-fable-5-2).
---
fs/smb/client/cifsacl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/smb/client/cifsacl.c b/fs/smb/client/cifsacl.c
index b23cb226c4d3..fd5a0b72f574 100644
--- a/fs/smb/client/cifsacl.c
+++ b/fs/smb/client/cifsacl.c
@@ -148,7 +148,7 @@ sid_to_key_str(struct smb_sid *sidptr, unsigned int type)
id_auth_val |= (unsigned long long)sidptr->authority[3] << 16;
id_auth_val |= (unsigned long long)sidptr->authority[2] << 24;
id_auth_val |= (unsigned long long)sidptr->authority[1] << 32;
- id_auth_val |= (unsigned long long)sidptr->authority[0] << 48;
+ id_auth_val |= (unsigned long long)sidptr->authority[0] << 40;
/*
* MS-DTYP states that if the authority is >= 2^32, then it should be
---
base-commit: 5449fa133d3aa0e0fe497b1fe793496b5c8f499f
change-id: 20261202-kbug-l990-73c0c4955bef
Best regards,
--
Anh Nguyen Hoang <anhnh.4work@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] smb: client: fix shift of SID authority[0] in sid_to_key_str()
@ 2026-12-02 16:01 ` Anh Nguyen Hoang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Anh Nguyen Hoang via B4 Relay @ 2026-12-02 16:01 UTC (permalink / raw)
To: Paulo Alcantara, Namjae Jeon
Cc: Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Jeff Layton, Steve French, Pavel Shilovsky, linux-cifs,
samba-technical, Anh Nguyen Hoang
From: Anh Nguyen Hoang <anhnh.4work@gmail.com>
sid_to_key_str() builds the description of the cifs.idmap key from a
SID. The identifier authority is a 48-bit big-endian number held in six
bytes, and the function assembles it by shifting authority[5]..[1] by 0,
8, 16, 24 and 32 bits. authority[0] is then shifted by 48 instead of 40,
which leaves bits 40-47 empty and puts the top byte in bits 48-55.
A SID whose first authority byte is not zero is therefore converted to
the wrong string, and the idmap upcall is asked to map a SID other than
the one the server sent.
The value can also need 14 hex digits, while SID_STRING_BASE_SIZE
reserves room for "-0x" plus 12. With a revision of two or three digits
the string no longer fits and sprintf() writes one or two bytes past
the size requested from kmalloc().
Shift authority[0] by 40 so that the authority is the 48-bit value the
comment and the buffer size expect.
Found by a static analysis tool.
Fixes: 193cdd8a2930 ("cifs: fix SID binary to string conversion")
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
Runtime test: QEMU, x86_64 defconfig + CIFS + KASAN, on cifs-next
5449fa133d3a, mounting a loopback SMB2.1 server with cifsacl returning a
SID with revision 255, authority 12:34:56:78:9a:bc, and 0 subauthorities.
Before the patch: KASAN reports a slab-out-of-bounds write past the
24-byte allocation and request-key receives "os:S-255-0x12003456789abc".
After the patch: no KASAN error and request-key receives
"os:S-255-0x123456789abc".
Testing:
- Compile-tested on x86_64 (allmodconfig, W=1): fs/smb/client/cifsacl.o;
no new warnings.
- checkpatch.pl --strict: no errors or warnings.
This patch was drafted with AI assistance (Claude, claude-fable-5-2).
---
fs/smb/client/cifsacl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/smb/client/cifsacl.c b/fs/smb/client/cifsacl.c
index b23cb226c4d3..fd5a0b72f574 100644
--- a/fs/smb/client/cifsacl.c
+++ b/fs/smb/client/cifsacl.c
@@ -148,7 +148,7 @@ sid_to_key_str(struct smb_sid *sidptr, unsigned int type)
id_auth_val |= (unsigned long long)sidptr->authority[3] << 16;
id_auth_val |= (unsigned long long)sidptr->authority[2] << 24;
id_auth_val |= (unsigned long long)sidptr->authority[1] << 32;
- id_auth_val |= (unsigned long long)sidptr->authority[0] << 48;
+ id_auth_val |= (unsigned long long)sidptr->authority[0] << 40;
/*
* MS-DTYP states that if the authority is >= 2^32, then it should be
---
base-commit: 5449fa133d3aa0e0fe497b1fe793496b5c8f499f
change-id: 20261202-kbug-l990-73c0c4955bef
Best regards,
--
Anh Nguyen Hoang <anhnh.4work@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] smb: client: fix shift of SID authority[0] in sid_to_key_str()
2026-12-02 16:01 ` Anh Nguyen Hoang via B4 Relay
(?)
@ 2026-12-02 23:52 ` Paulo Alcantara
-1 siblings, 0 replies; 3+ messages in thread
From: Paulo Alcantara @ 2026-12-02 23:52 UTC (permalink / raw)
To: Anh Nguyen Hoang via B4 Relay, Namjae Jeon
Cc: Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM,
Jeff Layton, Steve French, Pavel Shilovsky, linux-cifs,
samba-technical, Anh Nguyen Hoang
Anh Nguyen Hoang via B4 Relay <devnull+anhnh.4work.gmail.com@kernel.org>
writes:
> From: Anh Nguyen Hoang <anhnh.4work@gmail.com>
>
> sid_to_key_str() builds the description of the cifs.idmap key from a
> SID. The identifier authority is a 48-bit big-endian number held in six
> bytes, and the function assembles it by shifting authority[5]..[1] by 0,
> 8, 16, 24 and 32 bits. authority[0] is then shifted by 48 instead of 40,
> which leaves bits 40-47 empty and puts the top byte in bits 48-55.
>
> A SID whose first authority byte is not zero is therefore converted to
> the wrong string, and the idmap upcall is asked to map a SID other than
> the one the server sent.
>
> The value can also need 14 hex digits, while SID_STRING_BASE_SIZE
> reserves room for "-0x" plus 12. With a revision of two or three digits
> the string no longer fits and sprintf() writes one or two bytes past
> the size requested from kmalloc().
>
> Shift authority[0] by 40 so that the authority is the 48-bit value the
> comment and the buffer size expect.
> ...
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 23:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 16:01 [PATCH] smb: client: fix shift of SID authority[0] in sid_to_key_str() Anh Nguyen Hoang
2026-12-02 16:01 ` Anh Nguyen Hoang via B4 Relay
2026-12-02 23:52 ` Paulo Alcantara
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.