bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Alexei Starovoitov <ast@kernel.org>,
	"davem@davemloft.net" <davem@davemloft.net>
Cc: "daniel@iogearbox.net" <daniel@iogearbox.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next] bpf: fix bpf_attr.attach_btf_id check
Date: Fri, 18 Oct 2019 17:59:53 +0000	[thread overview]
Message-ID: <8a75a0e4-2202-7a3f-dfd2-45b25f8c5147@fb.com> (raw)
In-Reply-To: <20191018060933.2950231-1-ast@kernel.org>



On 10/17/19 11:09 PM, Alexei Starovoitov wrote:
> Only raw_tracepoint program type can have bpf_attr.attach_btf_id >= 0.
> Make sure to reject other program types that accidentally set it to non-zero.
> 
> Fixes: ccfe29eb29c2 ("bpf: Add attach_btf_id attribute to program load")
> Reported-by: Andrii Nakryiko <andriin@fb.com>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Acked-by: Yonghong Song <yhs@fb.com>

> ---
>   kernel/bpf/syscall.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 523e3ac15a08..16ea3c0db4f6 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -1570,6 +1570,17 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
>   			   enum bpf_attach_type expected_attach_type,
>   			   u32 btf_id)
>   {
> +	switch (prog_type) {
> +	case BPF_PROG_TYPE_RAW_TRACEPOINT:
> +		if (btf_id > BTF_MAX_TYPE)
> +			return -EINVAL;
> +		break;
> +	default:
> +		if (btf_id)
> +			return -EINVAL;
> +		break;
> +	}
> +
>   	switch (prog_type) {
>   	case BPF_PROG_TYPE_CGROUP_SOCK:
>   		switch (expected_attach_type) {
> @@ -1610,13 +1621,7 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
>   		default:
>   			return -EINVAL;
>   		}
> -	case BPF_PROG_TYPE_RAW_TRACEPOINT:
> -		if (btf_id > BTF_MAX_TYPE)
> -			return -EINVAL;
> -		return 0;
>   	default:
> -		if (btf_id)
> -			return -EINVAL;
>   		return 0;
>   	}
>   }
> 

  reply	other threads:[~2019-10-18 18:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18  6:09 [PATCH bpf-next] bpf: fix bpf_attr.attach_btf_id check Alexei Starovoitov
2019-10-18 17:59 ` Yonghong Song [this message]
2019-10-18 19:10 ` Daniel Borkmann
2019-10-18 23:28 ` Andrii Nakryiko

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=8a75a0e4-2202-7a3f-dfd2-45b25f8c5147@fb.com \
    --to=yhs@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /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).