netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: davem@davemloft.net
Cc: alexei.starovoitov@gmail.com, daniel@iogearbox.net,
	bpf@vger.kernel.org, netdev@vger.kernel.org,
	oss-drivers@netronome.com,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Maxim Mikityanskiy <maximmi@mellanox.com>
Subject: [PATCH net 3/3] net: fix installing orphaned programs
Date: Thu, 31 Oct 2019 20:07:00 -0700	[thread overview]
Message-ID: <20191101030700.13080-4-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20191101030700.13080-1-jakub.kicinski@netronome.com>

When netdevice with offloaded BPF programs is destroyed
the programs are orphaned and removed from the program
IDA - their IDs get released (the programs may remain
accessible via existing open file descriptors and pinned
files). After IDs are released they are set to 0.

This confuses dev_change_xdp_fd() because it compares
the __dev_xdp_query() result where 0 means no program
with prog->aux->id where 0 means orphaned.

dev_change_xdp_fd() would have incorrectly returned success
even though it had not installed the program.

Since drivers already catch this case via bpf_offload_dev_match()
let them handle this case. The error message drivers produce in
this case ("program loaded for a different device") is in fact
correct as the orphaned program must had to be loaded for a
different device.

Fixes: c14a9f633d9e ("net: Don't call XDP_SETUP_PROG when nothing is changed")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
CC: Maxim Mikityanskiy <maximmi@mellanox.com>

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

diff --git a/net/core/dev.c b/net/core/dev.c
index 96afd464284a..99ac84ff398f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8421,7 +8421,8 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
 			return -EINVAL;
 		}
 
-		if (prog->aux->id == prog_id) {
+		/* prog->aux->id may be 0 for orphaned device-bound progs */
+		if (prog->aux->id && prog->aux->id == prog_id) {
 			bpf_prog_put(prog);
 			return 0;
 		}
-- 
2.23.0


  parent reply	other threads:[~2019-11-01  3:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01  3:06 [PATCH net 0/3] fix BPF offload related bugs Jakub Kicinski
2019-11-01  3:06 ` [PATCH net 1/3] selftests: bpf: Skip write only files in debugfs Jakub Kicinski
2019-11-01  3:06 ` [PATCH net 2/3] net: cls_bpf: fix NULL deref on offload filter removal Jakub Kicinski
2019-11-01  3:07 ` Jakub Kicinski [this message]
2019-11-01 12:10 ` [PATCH net 0/3] fix BPF offload related bugs Daniel Borkmann
2019-11-01 17:03   ` Jakub Kicinski
2019-11-01 22:16 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191101030700.13080-4-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=maximmi@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).