Skip to content

Commit d12fa1d

Browse files
tohojojfvogel
authored andcommitted
net: xdp: Disallow attaching device-bound programs in generic mode
[ Upstream commit 3595599 ] 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 <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Tested-by: Marcus Wichelmann <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 557707906dd3e34b8a8c265f664d19f95799937e) Signed-off-by: Jack Vogel <[email protected]>
1 parent 9e717b0 commit d12fa1d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/core/dev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9660,6 +9660,10 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
96609660
NL_SET_ERR_MSG(extack, "Program bound to different device");
96619661
return -EINVAL;
96629662
}
9663+
if (bpf_prog_is_dev_bound(new_prog->aux) && mode == XDP_MODE_SKB) {
9664+
NL_SET_ERR_MSG(extack, "Can't attach device-bound programs in generic mode");
9665+
return -EINVAL;
9666+
}
96639667
if (new_prog->expected_attach_type == BPF_XDP_DEVMAP) {
96649668
NL_SET_ERR_MSG(extack, "BPF_XDP_DEVMAP programs can not be attached to a device");
96659669
return -EINVAL;

0 commit comments

Comments
 (0)