Re: [PATCH] Bluetooth: Fix a buffer overflow in mgmt_mesh_add()

From: Gix, Brian
Date: Tue Dec 13 2022 - 20:00:50 EST


Signed-off: brian.gix@xxxxxxxxx

On Mon, 2022-12-12 at 05:08 -0800, Harshit Mogalapalli wrote:
> Smatch Warning:
> net/bluetooth/mgmt_util.c:375 mgmt_mesh_add() error: __memcpy()
> 'mesh_tx->param' too small (48 vs 50)
>
> Analysis:
>
> 'mesh_tx->param' is array of size 48. This is the destination.
> u8 param[sizeof(struct mgmt_cp_mesh_send) + 29]; // 19 + 29 = 48.
>
> But in the caller 'mesh_send' we reject only when len > 50.
> len > (MGMT_MESH_SEND_SIZE + 31) // 19 + 31 = 50.
>
> Fixes: b338d91703fa ("Bluetooth: Implement support for Mesh")
> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxxx>
> ---
> This is based on static analysis, I am unsure if we should put
> an upper bound to len(48) instead.
>
> This limit on length changed between v4 and v5 patches of Commit:
> ("Bluetooth: Implement support for Mesh") in function mesh_send()
>
> v4:
> https://lore.kernel.org/all/20220511155412.740249-2-brian.gix@xxxxxxxxx/
> v5:
> https://lore.kernel.org/all/20220720194511.320773-2-brian.gix@xxxxxxxxx/
> ---
>  net/bluetooth/mgmt_util.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/mgmt_util.h b/net/bluetooth/mgmt_util.h
> index 6a8b7e84293d..bdf978605d5a 100644
> --- a/net/bluetooth/mgmt_util.h
> +++ b/net/bluetooth/mgmt_util.h
> @@ -27,7 +27,7 @@ struct mgmt_mesh_tx {
>         struct sock *sk;
>         u8 handle;
>         u8 instance;
> -       u8 param[sizeof(struct mgmt_cp_mesh_send) + 29];
> +       u8 param[sizeof(struct mgmt_cp_mesh_send) + 31];
>  };
>  
>  struct mgmt_pending_cmd {