Skip to content

Commit 3595599

Browse files
tohojokuba-moo
authored andcommitted
net: xdp: Disallow attaching device-bound programs in generic mode
Device-bound programs are used to support RX metadata kfuncs. These kfuncs are driver-specific and rely on the driver context to read the metadata. This means they can't work in generic XDP mode. However, there is no check to disallow such programs from being attached in generic mode, in which case the metadata kfuncs will be called in an invalid context, leading to crashes. Fix this by adding a check to disallow attaching device-bound programs in generic mode. Fixes: 2b3486b ("bpf: Introduce device-bound XDP programs") Reported-by: Marcus Wichelmann <marcus.wichelmann@hetzner-cloud.de> Closes: https://lore.kernel.org/r/dae862ec-43b5-41a0-8edf-46c59071cdda@hetzner-cloud.de Tested-by: Marcus Wichelmann <marcus.wichelmann@hetzner-cloud.de> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://patch.msgid.link/20250127131344.238147-1-toke@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8c670bd commit 3595599

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

net/core/dev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9924,6 +9924,10 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
99249924
NL_SET_ERR_MSG(extack, "Program bound to different device");
99259925
return -EINVAL;
99269926
}
9927+
if (bpf_prog_is_dev_bound(new_prog->aux) && mode == XDP_MODE_SKB) {
9928+
NL_SET_ERR_MSG(extack, "Can't attach device-bound programs in generic mode");
9929+
return -EINVAL;
9930+
}
99279931
if (new_prog->expected_attach_type == BPF_XDP_DEVMAP) {
99289932
NL_SET_ERR_MSG(extack, "BPF_XDP_DEVMAP programs can not be attached to a device");
99299933
return -EINVAL;

0 commit comments

Comments
 (0)