Re: [PATCH] Bluetooth: SMP: add missing skb len check in smp_cmd_keypress_notify
From: Luiz Augusto von Dentz
Date: Mon May 18 2026 - 16:40:51 EST
Hi Muhammad,
On Sun, May 17, 2026 at 10:55 AM Muhammad Bilal <meatuni001@xxxxxxxxx> wrote:
>
> smp_cmd_keypress_notify() accesses the received payload as
> struct smp_cmd_keypress_notify without verifying that skb->len
> contains enough data.
>
> smp_sig_channel() removes the opcode byte before dispatching to
> command handlers, so a SMP_CMD_KEYPRESS_NOTIFY packet without a
> payload leaves skb->len equal to zero on entry to the handler,
> causing a 1-byte out-of-bounds read from the heap.
>
> Add a length check before accessing the payload and return
> SMP_INVALID_PARAMS when the packet is too short, matching the
> pattern used by other SMP command handlers.
>
> Fixes: 1408bb6efb04 ("Bluetooth: Add dummy handler for LE SC keypress notification")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Muhammad Bilal <meatuni001@xxxxxxxxx>
> ---
> net/bluetooth/smp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
> index 98f1da4f5..4c98e2a3a 100644
> --- a/net/bluetooth/smp.c
> +++ b/net/bluetooth/smp.c
> @@ -2932,6 +2932,9 @@ static int smp_cmd_keypress_notify(struct l2cap_conn *conn,
> {
> struct smp_cmd_keypress_notify *kp = (void *) skb->data;
Perhaps we should stop assigning it directly and instead just use
`skb_pull_data`, which performs bounds checks on its own.
> + if (skb->len < sizeof(*kp))
> + return SMP_INVALID_PARAMS;
I suggested we add a bt_dev_warn_ratelimit with something like "Too
small packet: skb->len %u < %u" to make debugging easier.
> +
> bt_dev_dbg(conn->hcon->hdev, "value 0x%02x", kp->value);
>
> return 0;
> --
> 2.54.0
>
--
Luiz Augusto von Dentz