netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf/xdp: Can't detach BPF XDP prog if not exist
@ 2022-05-04  3:52 Zhengchao Shao
  2022-05-04 11:19 ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 4+ messages in thread
From: Zhengchao Shao @ 2022-05-04  3:52 UTC (permalink / raw)
  To: netdev, linux-kernel, bpf, davem, edumazet, kuba, pabeni
  Cc: ast, daniel, hawk, john.fastabend, andrii, kafai, songliubraving,
	yhs, kpsingh, bigeasy, imagedong, petrm, memxor, arnd,
	weiyongjun1, shaozhengchao, yuehaibing

if user sets nonexistent xdp_flags to detach xdp prog, kernel should
return err and tell user that detach failed with detail info.

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 net/core/dev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 8ed0272bf32f..8ed05ef62c68 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9149,6 +9149,12 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
 		return -EBUSY;
 	}
 
+	/* no BPF XDP prog attached */
+	if (!new_prog && !(dev->xdp_state[mode].prog)) {
+		NL_SET_ERR_MSG(extack, "no BPF XDP prog attached");
+		return -ENOENT;
+	}
+
 	/* don't allow if an upper device already has a program */
 	netdev_for_each_upper_dev_rcu(dev, upper, iter) {
 		if (dev_xdp_prog_count(upper) > 0) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-05 14:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-04  3:52 [PATCH bpf-next] bpf/xdp: Can't detach BPF XDP prog if not exist Zhengchao Shao
2022-05-04 11:19 ` Toke Høiland-Jørgensen
2022-05-05  8:21   ` 答复: " shaozhengchao
2022-05-05 14:27     ` Toke Høiland-Jørgensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).