Netdev Archive on
 help / color / Atom feed
* [PATCH bpf-next] net: Don't uninstall an XDP program when none is installed
@ 2019-06-12 16:14 Maxim Mikityanskiy
  2019-06-12 18:39 ` Björn Töpel
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Maxim Mikityanskiy @ 2019-06-12 16:14 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Björn Töpel
  Cc: bpf, netdev, David S. Miller, Saeed Mahameed, Jakub Kicinski,
	Jesper Dangaard Brouer, John Fastabend, Martin KaFai Lau,
	Song Liu, Yonghong Song, Maxim Mikityanskiy

dev_change_xdp_fd doesn't perform any checks in case it uninstalls an
XDP program. It means that the driver's ndo_bpf can be called with
XDP_SETUP_PROG asking to set it to NULL even if it's already NULL. This
case happens if the user runs `ip link set eth0 xdp off` when there is
no XDP program attached.

The drivers typically perform some heavy operations on XDP_SETUP_PROG,
so they all have to handle this case internally to return early if it
happens. This patch puts this check into the kernel code, so that all
drivers will benefit from it.

Signed-off-by: Maxim Mikityanskiy <>
Björn, please take a look at this, Saeed told me you were doing
something related, but I couldn't find it. If this fix is already
covered by your work, please tell about that.

 net/core/dev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 66f7508825bd..68b3e3320ceb 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8089,6 +8089,9 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 			return -EINVAL;
+	} else {
+		if (!__dev_xdp_query(dev, bpf_op, query))
+			return 0;
 	err = dev_xdp_install(dev, bpf_op, extack, flags, prog);

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

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 16:14 [PATCH bpf-next] net: Don't uninstall an XDP program when none is installed Maxim Mikityanskiy
2019-06-12 18:39 ` Björn Töpel
2019-06-12 21:15 ` Jakub Kicinski
2019-06-13  9:04   ` Björn Töpel
2019-06-13 17:26     ` Jakub Kicinski
2019-07-10 11:16 ` Maxim Mikityanskiy
2019-07-12 15:44   ` Daniel Borkmann
2019-08-14 14:34     ` [PATCH bpf-next v2] net: Don't call XDP_SETUP_PROG when nothing is changed Maxim Mikityanskiy
2019-08-14 17:57       ` Jonathan Lemon
2019-08-14 22:01       ` Jakub Kicinski
2019-08-17 21:29       ` Daniel Borkmann

Netdev Archive on

Archives are clonable:
	git clone --mirror netdev/git/0.git
	git clone --mirror netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ \
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone