All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, KP Singh <kpsingh@kernel.org>,
	syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf 1/2] xdp: check prog type before updating BPF link
Date: Fri, 7 Jan 2022 13:17:39 -0800	[thread overview]
Message-ID: <CAEf4BzbRxwbJQFZHvB-hBj1A+364Jua4KJgkL+D_9PKsj7jKSg@mail.gmail.com> (raw)
In-Reply-To: <20220107183049.311134-1-toke@redhat.com>

On Fri, Jan 7, 2022 at 10:31 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> 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>
> ---

The fix looks good to me, thanks. I'd love it if this was done
generically in link_update, but each link type has its own locking
schema for link->prog, so I didn't figure out a way to do this in a
centralized way.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  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
>

  parent reply	other threads:[~2022-01-07 21:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Andrii Nakryiko [this message]
2022-01-07 21:26   ` [PATCH bpf 1/2] xdp: check prog type before updating BPF link Toke Høiland-Jørgensen

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=CAEf4BzbRxwbJQFZHvB-hBj1A+364Jua4KJgkL+D_9PKsj7jKSg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=syzbot+983941aa85af6ded1fd9@syzkaller.appspotmail.com \
    --cc=toke@redhat.com \
    --cc=yhs@fb.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 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.