Skip to contentSkip to conversation

xdp: Reset prog in dev_change_xdp_fd when fd is negative

PATCH Applied David Ahern 5 participants 5 messages Apr 12, 2020 – Apr 14, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xdp: Reset prog in dev_change_xdp_fd when fd is negative

From: David Ahern <[email protected]>

The commit mentioned in the Fixes tag reuses the local prog variable when looking up an expected_fd. The variable is not reset when fd < 0 causing a detach with the expected_fd set to actually call dev_xdp_install for the existing program. The end result is that the detach does not happen.

Fixes 92234c8f15c8 ("xdp: Support specifying expected existing program when attaching XDP")
Cc Toke Høiland-Jørgensen <[email protected]>
---
 net/core/dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/dev.c +2 -1
index df8097b8e286..522288177bbd 100644
@@ -8667,8 +8667,8 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 	const struct net_device_ops *ops = dev->netdev_ops;
 	enum bpf_netdev_command query;
 	u32 prog_id, expected_id = 0;
-	struct bpf_prog *prog = NULL;
 	bpf_op_t bpf_op, bpf_chk;
+	struct bpf_prog *prog;
 	bool offload;
 	int err;
 
@@ -8734,6 +8734,7 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 	} else {
 		if (!prog_id)
 			return 0;
+		prog = NULL;
 	}
 
 	err = dev_xdp_install(dev, bpf_op, extack, flags, prog);
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Sun, 12 Apr 2020 07:32:04 -0600 David Ahern wrote:

From: David Ahern <[email protected]>

The commit mentioned in the Fixes tag reuses the local prog variable when looking up an expected_fd. The variable is not reset when fd < 0 causing a detach with the expected_fd set to actually call dev_xdp_install for the existing program. The end result is that the detach does not happen.

Fixes 92234c8f15c8 ("xdp: Support specifying expected existing program when attaching XDP")
Cc Toke Høiland-Jørgensen <[email protected]>
#2 lore raw
In reply to David Ahern
Quoted 11 lines · David Ahern

From: David Ahern <[email protected]>

The commit mentioned in the Fixes tag reuses the local prog variable when looking up an expected_fd. The variable is not reset when fd < 0 causing a detach with the expected_fd set to actually call dev_xdp_install for the existing program. The end result is that the detach does not happen.

Fixes 92234c8f15c8 ("xdp: Support specifying expected existing program when attaching XDP")
Cc Toke Høiland-Jørgensen <[email protected]>

Argh. Thanks for the fix.

Toke, please review.

Reviewed-by on v1 1/1
#3 lore raw
In reply to David Ahern
Quoted 11 lines · David Ahern

From: David Ahern <[email protected]>

The commit mentioned in the Fixes tag reuses the local prog variable when looking up an expected_fd. The variable is not reset when fd < 0 causing a detach with the expected_fd set to actually call dev_xdp_install for the existing program. The end result is that the detach does not happen.

Fixes 92234c8f15c8 ("xdp: Support specifying expected existing program when attaching XDP")
Cc Toke Høiland-Jørgensen <[email protected]>

Ugh, my bad (obviously!). Thanks for the fix! I'll send an update to the selftest to catch errors like this...

#4 lore raw
Quoted 10 lines · Toke Høiland-Jørgensen
Quoted 8 lines · David Ahern

From: David Ahern <[email protected]>

The commit mentioned in the Fixes tag reuses the local prog variable when looking up an expected_fd. The variable is not reset when fd < 0 causing a detach with the expected_fd set to actually call dev_xdp_install for the existing program. The end result is that the detach does not happen.

Quoted 6 lines
Quoted 3 lines
Fixes 92234c8f15c8 ("xdp: Support specifying expected existing program when attaching XDP")
Cc Toke Høiland-Jørgensen <[email protected]>

Ugh, my bad (obviously!). Thanks for the fix! I'll send an update to the selftest to catch errors like this...

+1

Quoted 1 line

Applied, thanks!