Re: [PATCH] net/ncsi: Silence runtime memcpy() false positive warning

From: Joel Stanley
Date: Tue Jan 17 2023 - 21:38:44 EST


On Fri, 2 Dec 2022 at 21:24, Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> The memcpy() in ncsi_cmd_handler_oem deserializes nca->data into a
> flexible array structure that overlapping with non-flex-array members
> (mfr_id) intentionally. Since the mem_to_flex() API is not finished,
> temporarily silence this warning, since it is a false positive, using
> unsafe_memcpy().

Thanks for sending the fix Kees. I got a bit busy towards the end of the year.

I spent some time looking at how the netlink api was used, and tried
to convince myself that a user couldn't send an OEM command that
triggered the overflow. It all got a bit tangled up so I didn't come
to a conclusion.

Cheers,

Joel

>
> Reported-by: Joel Stanley <joel@xxxxxxxxx>
> Link: https://lore.kernel.org/netdev/CACPK8Xdfi=OJKP0x0D1w87fQeFZ4A2DP2qzGCRcuVbpU-9=4sQ@xxxxxxxxxxxxxx/
> Cc: Samuel Mendoza-Jonas <sam@xxxxxxxxxxxxxxxx>
> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
> Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
> Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
> Cc: netdev@xxxxxxxxxxxxxxx
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
> ---
> net/ncsi/ncsi-cmd.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
> index dda8b76b7798..fd2236ee9a79 100644
> --- a/net/ncsi/ncsi-cmd.c
> +++ b/net/ncsi/ncsi-cmd.c
> @@ -228,7 +228,8 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
> len += max(payload, padding_bytes);
>
> cmd = skb_put_zero(skb, len);
> - memcpy(&cmd->mfr_id, nca->data, nca->payload);
> + unsafe_memcpy(&cmd->mfr_id, nca->data, nca->payload,
> + /* skb allocated with enough to load the payload */);
> ncsi_cmd_build_header(&cmd->cmd.common, nca);
>
> return 0;
> --
> 2.34.1
>