Skip to content

Commit 71703ac

Browse files
mrpreKernel Patches Daemon
authored andcommitted
bpf, xdp: move offload check into dev_xdp_install()
bpf_xdp_link_update() calls dev_xdp_install() directly and bypasses dev_xdp_attach(), so the offload check that lived in dev_xdp_attach() does not apply. A user can create an XDP link in SKB or native mode with a regular program and then replace it via BPF_LINK_UPDATE with an offloaded program, whose bpf_func is bpf_prog_warn_on_exec(), tripping the WARN on the first packet. Move the check from dev_xdp_attach() into dev_xdp_install() so both the attach path and the link update path are covered by a single check at the actual install site. Fixes: 026a4c2 ("bpf, xdp: Implement LINK_UPDATE for BPF XDP link") Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
1 parent f3c1ada commit 71703ac

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

net/core/dev.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10359,6 +10359,11 @@ static int dev_xdp_install(struct net_device *dev, enum bpf_xdp_mode mode,
1035910359

1036010360
netdev_ops_assert_locked(dev);
1036110361

10362+
if (prog && mode != XDP_MODE_HW && bpf_prog_is_offloaded(prog->aux)) {
10363+
NL_SET_ERR_MSG(extack, "Using offloaded program without HW_MODE flag is not supported");
10364+
return -EINVAL;
10365+
}
10366+
1036210367
if (dev->cfg->hds_config == ETHTOOL_TCP_DATA_SPLIT_ENABLED &&
1036310368
prog && !prog->aux->xdp_has_frags) {
1036410369
NL_SET_ERR_MSG(extack, "unable to install XDP to device using tcp-data-split");
@@ -10510,10 +10515,6 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
1051010515
NL_SET_ERR_MSG(extack, "Native and generic XDP can't be active at the same time");
1051110516
return -EEXIST;
1051210517
}
10513-
if (!offload && bpf_prog_is_offloaded(new_prog->aux)) {
10514-
NL_SET_ERR_MSG(extack, "Using offloaded program without HW_MODE flag is not supported");
10515-
return -EINVAL;
10516-
}
1051710518
if (bpf_prog_is_dev_bound(new_prog->aux) && !bpf_offload_dev_match(new_prog, dev)) {
1051810519
NL_SET_ERR_MSG(extack, "Program bound to different device");
1051910520
return -EINVAL;

0 commit comments

Comments
 (0)