Skip to content

Commit

Permalink
nfp: bpf: prevent integer overflow in nfp_bpf_event_output()
Browse files Browse the repository at this point in the history
The "sizeof(struct cmsg_bpf_event) + pkt_size + data_size" math could
potentially have an integer wrapping bug on 32bit systems.  Check for
this and return an error.

Fixes: 9816dd3 ("nfp: bpf: perf event output helpers support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://patch.msgid.link/6074805b-e78d-4b8a-bf05-e929b5377c28@stanley.mountain
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Dan Carpenter authored and Jakub Kicinski committed Jan 14, 2025
1 parent f62bb88 commit 16ebb6f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/ethernet/netronome/nfp/bpf/offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data,
map_id_full = be64_to_cpu(cbe->map_ptr);
map_id = map_id_full;

if (len < sizeof(struct cmsg_bpf_event) + pkt_size + data_size)
if (size_add(pkt_size, data_size) > INT_MAX ||
len < sizeof(struct cmsg_bpf_event) + pkt_size + data_size)
return -EINVAL;
if (cbe->hdr.ver != NFP_CCM_ABI_VERSION)
return -EINVAL;
Expand Down

0 comments on commit 16ebb6f

Please sign in to comment.