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

From: Dan Carpenter
Date: Tue Jan 16 2024 - 02:03:38 EST


What happened to this patch? These sorts of patches go through Kees?

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

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)

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...

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