Re: [PATCH] smb: client: check the cifs.spnego key lengths against its payload

From: Namjae Jeon

Date: Sat Dec 05 2026 - 08:04:44 EST


On Sat, Dec 5, 2026 at 7:16 PM Piyus Kedia <piyus@xxxxxxxxxxx> wrote:
>
> The payload of a cifs.spnego key is a struct cifs_spnego_msg followed by
> the session key and the security blob, whose lengths are in the header:
> sesskey_len and secblob_len. cifs_spnego_key_instantiate() stores the
> payload as the request-key helper sent it, and nothing keeps its length,
> so the session setup code has nothing to check the two against.
> SMB2_auth_kerberos() copies sesskey_len bytes from msg->data into the
> session key and sends secblob_len bytes from msg->data + sesskey_len to
> the server as the security buffer; sess_auth_kerberos() does the same
> for SMB1. A header that claims more than the payload holds makes both
> read past the end of it:
>
> BUG: KASAN: slab-out-of-bounds in SMB2_auth_kerberos+0x3a8/0x5b0
> Read of size 4096 at addr ffff888040f862b0 by task poc/9451
> __asan_memcpy+0x24/0x60 mm/kasan/shadow.c:105
> SMB2_auth_kerberos+0x3a8/0x5b0 fs/smb/client/smb2pdu.c:1809
> SMB2_sess_setup+0x1b4/0x470 fs/smb/client/smb2pdu.c:2087
> cifs_setup_session+0x49d/0xaf0 fs/smb/client/connect.c:4240
> cifs_get_smb_ses+0xf4a/0x14e0 fs/smb/client/connect.c:2535
> cifs_mount_get_session+0xc0/0x2e0 fs/smb/client/connect.c:3660
> Allocated by task 9458:
> kmemdup_noprof+0x2b/0x60 mm/util.c:138
> cifs_spnego_key_instantiate+0x3a/0x80 fs/smb/client/cifs_spnego.c:28
> key_instantiate_and_link+0x314/0x330 security/keys/key.c:544
> keyctl_instantiate_key_common+0x240/0x350 security/keys/keyctl.c:1228
> The buggy address is located 0 bytes to the right of
> allocated 16-byte region [ffff888040f862a0, ffff888040f862b0)
>
> Check the lengths once, where the payload comes in, so that its readers
> can rely on them: the header has to be there and the session key and
> the blob have to fit in what follows it. Only an overrun is refused; a
> payload with bytes to spare after the blob is accepted as before.
>
> Only the helper that the kernel runs for the key, holding the key's
> authorisation, can instantiate it, and the type's vet_description
> refuses cifs.spnego keys created from userspace, so this hardens the
> client against a buggy or compromised helper.
>
> We found this with a syzkaller-based fuzzing harness driven by an AI tool.
>
> Fixes: f1d662a7d5e5 ("[CIFS] Add upcall files for cifs to use spnego/kerberos")
> Closes: https://lore.kernel.org/r/cifs-spnego-key-lengths.20261205@xxxxxxxxxxx/
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
> Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
Looks good to me.
Reviewed-by: Namjae Jeon <linkinjeon@xxxxxxxxxx>
Thanks.