All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf 1/2] xdp: check prog type before updating BPF link
@ 2022-01-07 18:30 Toke Høiland-Jørgensen
  2022-01-07 18:30 ` [PATCH bpf 2/2] bpf/selftests: Add check for updating XDP bpf_link with wrong program type Toke Høiland-Jørgensen
  2022-01-07 21:17 ` [PATCH bpf 1/2] xdp: check prog type before updating BPF link Andrii Nakryiko
  0 siblings, 2 replies; 7+ messages in thread
From: Toke Høiland-Jørgensen @ 2022-01-07 18:30 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	KP Singh
  Cc: Toke Høiland-Jørgensen, syzbot+983941aa85af6ded1fd9,
	netdev, bpf

The bpf_xdp_link_update() function didn't check the program type before
updating the program, which made it possible to install any program type as
an XDP program, which is obviously not good. Syzbot managed to trigger this
by swapping in an LWT program on the XDP hook which would crash in a helper
call.

Fix this by adding a check and bailing out if the types don't match.

Fixes: 026a4c28e1db ("bpf, xdp: Implement LINK_UPDATE for BPF XDP link")
Reported-by: syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 net/core/dev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index c4708e2487fb..2078d04c6482 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9656,6 +9656,12 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,
 		goto out_unlock;
 	}
 	old_prog = link->prog;
+	if (old_prog->type != new_prog->type ||
+	    old_prog->expected_attach_type != new_prog->expected_attach_type) {
+		err = -EINVAL;
+		goto out_unlock;
+	}
+
 	if (old_prog == new_prog) {
 		/* no-op, don't disturb drivers */
 		bpf_prog_put(new_prog);
-- 
2.34.1


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

end of thread, other threads:[~2022-01-07 21:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07 18:30 [PATCH bpf 1/2] xdp: check prog type before updating BPF link Toke Høiland-Jørgensen
2022-01-07 18:30 ` [PATCH bpf 2/2] bpf/selftests: Add check for updating XDP bpf_link with wrong program type Toke Høiland-Jørgensen
2022-01-07 21:08   ` Andrii Nakryiko
2022-01-07 21:23     ` Toke Høiland-Jørgensen
2022-01-07 21:30       ` Andrii Nakryiko
2022-01-07 21:17 ` [PATCH bpf 1/2] xdp: check prog type before updating BPF link Andrii Nakryiko
2022-01-07 21:26   ` Toke Høiland-Jørgensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.