RE: [PATCH] coccinelle: semantic patch to check for potential struct_size calls

From: Keller, Jacob E
Date: Wed Jan 17 2024 - 16:54:36 EST




> -----Original Message-----
> From: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> Sent: Monday, January 15, 2024 11:03 PM
> To: Keller, Jacob E <jacob.e.keller@xxxxxxxxx>
> Cc: Julia Lawall <Julia.Lawall@xxxxxxx>; Kees Cook <keescook@xxxxxxxxxxxx>;
> Gustavo A . R . Silva <gustavoars@xxxxxxxxxx>; cocci@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxx>
> Subject: Re: [PATCH] coccinelle: semantic patch to check for potential struct_size
> calls
>
> What happened to this patch? These sorts of patches go through Kees?
>

No one replied and I got side tracked by other projects.

> Also it would be nice if it could handle char arrays. It doesn't warn
> for the kmalloc in dg_dispatch_as_host():
>
Yea it would be nice to handle this too.

> drivers/misc/vmw_vmci/vmci_datagram.c
> 227 dg_info = kmalloc(sizeof(*dg_info) +
> 228 (size_t) dg->payload_size, GFP_ATOMIC);
>
> The Cocci check is looking specifically for:
>
> sizeof(*dg_info) + (sizeof(*dg_info->msg_payload) * dg->payload_size)
>

I think that's a slightly different formulation.

> But since this flex array is u8 there is no multiply. I don't know how
> are it is to add support for char arrays...
>

A separate rule would work.

> Also another common way to write the multiply is:
>
> sizeof(*dg_info) + (sizeof(dg_info->msg_payload[0]) * dg->payload_size)
>
> That should be pretty straight forward to add.
>
> regards,
> dan carpenter
>

Mostly I just lost track of this because I struggled to get traction in the right lists and trees.

Thanks,
Jake