All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Edward Cree <ecree@solarflare.com>,
	davem@davemloft.net,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Alexei Starovoitov <ast@fb.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	iovisor-dev <iovisor-dev@lists.iovisor.org>,
	josef@toxicpanda.com
Subject: Re: [PATCH net 2/2] bpf/verifier: fix min/max handling in BPF_SUB
Date: Fri, 21 Jul 2017 16:30:17 +0200	[thread overview]
Message-ID: <59720FF9.10901@iogearbox.net> (raw)
In-Reply-To: <e3fa964f-54f2-7310-59d1-41a4b7ad9a5b@solarflare.com>

On 07/21/2017 03:37 PM, Edward Cree wrote:
> We have to subtract the src max from the dst min, and vice-versa, since
>   (e.g.) the smallest result comes from the largest subtrahend.
>
> Fixes: 484611357c19 ("bpf: allow access into map value arrays")
> Signed-off-by: Edward Cree <ecree@solarflare.com>

LGTM, thanks for the fix!

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

> ---
>   kernel/bpf/verifier.c | 21 +++++++++++++++------
>   1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index af9e84a..664d939 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -1865,10 +1865,12 @@ static void adjust_reg_min_max_vals(struct bpf_verifier_env *env,
>   	 * do our normal operations to the register, we need to set the values
>   	 * to the min/max since they are undefined.
>   	 */
> -	if (min_val == BPF_REGISTER_MIN_RANGE)
> -		dst_reg->min_value = BPF_REGISTER_MIN_RANGE;
> -	if (max_val == BPF_REGISTER_MAX_RANGE)
> -		dst_reg->max_value = BPF_REGISTER_MAX_RANGE;
> +	if (opcode != BPF_SUB) {
> +		if (min_val == BPF_REGISTER_MIN_RANGE)
> +			dst_reg->min_value = BPF_REGISTER_MIN_RANGE;
> +		if (max_val == BPF_REGISTER_MAX_RANGE)
> +			dst_reg->max_value = BPF_REGISTER_MAX_RANGE;
> +	}
>
>   	switch (opcode) {
>   	case BPF_ADD:
> @@ -1879,10 +1881,17 @@ static void adjust_reg_min_max_vals(struct bpf_verifier_env *env,
>   		dst_reg->min_align = min(src_align, dst_align);
>   		break;
>   	case BPF_SUB:
> +		/* If one of our values was at the end of our ranges, then the
> +		 * _opposite_ value in the dst_reg goes to the end of our range.
> +		 */
> +		if (min_val == BPF_REGISTER_MIN_RANGE)
> +			dst_reg->max_value = BPF_REGISTER_MAX_RANGE;
> +		if (max_val == BPF_REGISTER_MAX_RANGE)
> +			dst_reg->min_value = BPF_REGISTER_MIN_RANGE;
>   		if (dst_reg->min_value != BPF_REGISTER_MIN_RANGE)
> -			dst_reg->min_value -= min_val;
> +			dst_reg->min_value -= max_val;
>   		if (dst_reg->max_value != BPF_REGISTER_MAX_RANGE)
> -			dst_reg->max_value -= max_val;
> +			dst_reg->max_value -= min_val;
>   		dst_reg->min_align = min(src_align, dst_align);
>   		break;
>   	case BPF_MUL:
>

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Borkmann via iovisor-dev <iovisor-dev-9jONkmmOlFHEE9lA1F8Ukti2O/JbrIOy@public.gmane.org>
To: Edward Cree <ecree-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
	Alexei Starovoitov
	<alexei.starovoitov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Alexei Starovoitov <ast-b10kYP2dOMg@public.gmane.org>
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	iovisor-dev
	<iovisor-dev-9jONkmmOlFHEE9lA1F8Ukti2O/JbrIOy@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	josef-DigfWCa+lFGyeJad7bwFQA@public.gmane.org
Subject: Re: [PATCH net 2/2] bpf/verifier: fix min/max handling in BPF_SUB
Date: Fri, 21 Jul 2017 16:30:17 +0200	[thread overview]
Message-ID: <59720FF9.10901@iogearbox.net> (raw)
In-Reply-To: <e3fa964f-54f2-7310-59d1-41a4b7ad9a5b-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>

On 07/21/2017 03:37 PM, Edward Cree wrote:
> We have to subtract the src max from the dst min, and vice-versa, since
>   (e.g.) the smallest result comes from the largest subtrahend.
>
> Fixes: 484611357c19 ("bpf: allow access into map value arrays")
> Signed-off-by: Edward Cree <ecree-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>

LGTM, thanks for the fix!

Acked-by: Daniel Borkmann <daniel-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>

> ---
>   kernel/bpf/verifier.c | 21 +++++++++++++++------
>   1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index af9e84a..664d939 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -1865,10 +1865,12 @@ static void adjust_reg_min_max_vals(struct bpf_verifier_env *env,
>   	 * do our normal operations to the register, we need to set the values
>   	 * to the min/max since they are undefined.
>   	 */
> -	if (min_val == BPF_REGISTER_MIN_RANGE)
> -		dst_reg->min_value = BPF_REGISTER_MIN_RANGE;
> -	if (max_val == BPF_REGISTER_MAX_RANGE)
> -		dst_reg->max_value = BPF_REGISTER_MAX_RANGE;
> +	if (opcode != BPF_SUB) {
> +		if (min_val == BPF_REGISTER_MIN_RANGE)
> +			dst_reg->min_value = BPF_REGISTER_MIN_RANGE;
> +		if (max_val == BPF_REGISTER_MAX_RANGE)
> +			dst_reg->max_value = BPF_REGISTER_MAX_RANGE;
> +	}
>
>   	switch (opcode) {
>   	case BPF_ADD:
> @@ -1879,10 +1881,17 @@ static void adjust_reg_min_max_vals(struct bpf_verifier_env *env,
>   		dst_reg->min_align = min(src_align, dst_align);
>   		break;
>   	case BPF_SUB:
> +		/* If one of our values was at the end of our ranges, then the
> +		 * _opposite_ value in the dst_reg goes to the end of our range.
> +		 */
> +		if (min_val == BPF_REGISTER_MIN_RANGE)
> +			dst_reg->max_value = BPF_REGISTER_MAX_RANGE;
> +		if (max_val == BPF_REGISTER_MAX_RANGE)
> +			dst_reg->min_value = BPF_REGISTER_MIN_RANGE;
>   		if (dst_reg->min_value != BPF_REGISTER_MIN_RANGE)
> -			dst_reg->min_value -= min_val;
> +			dst_reg->min_value -= max_val;
>   		if (dst_reg->max_value != BPF_REGISTER_MAX_RANGE)
> -			dst_reg->max_value -= max_val;
> +			dst_reg->max_value -= min_val;
>   		dst_reg->min_align = min(src_align, dst_align);
>   		break;
>   	case BPF_MUL:
>

  reply	other threads:[~2017-07-21 14:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 13:35 [PATCH net 0/2] bpf: fix verifier min/max handling in BPF_SUB Edward Cree
2017-07-21 13:35 ` Edward Cree via iovisor-dev
2017-07-21 13:36 ` [PATCH net 1/2] selftests/bpf: subtraction bounds test Edward Cree
2017-07-21 14:29   ` Daniel Borkmann
2017-07-21 14:29     ` Daniel Borkmann via iovisor-dev
2017-07-21 13:37 ` [PATCH net 2/2] bpf/verifier: fix min/max handling in BPF_SUB Edward Cree
2017-07-21 13:37   ` Edward Cree via iovisor-dev
2017-07-21 14:30   ` Daniel Borkmann [this message]
2017-07-21 14:30     ` Daniel Borkmann via iovisor-dev
2017-07-21 15:54 ` [iovisor-dev] [PATCH net 0/2] bpf: fix verifier " Nadav Amit
2017-07-21 15:54   ` Nadav Amit via iovisor-dev
2017-07-24 21:03 ` David Miller
2017-07-24 21:03   ` David Miller via iovisor-dev

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=59720FF9.10901@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@fb.com \
    --cc=davem@davemloft.net \
    --cc=ecree@solarflare.com \
    --cc=iovisor-dev@lists.iovisor.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.