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:
>
next prev parent reply other threads:[~2017-07-21 14:30 UTC|newest]
Thread overview: 7+ 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 via iovisor-dev
2017-07-21 13:36 ` [PATCH net 1/2] selftests/bpf: subtraction bounds test Edward Cree
[not found] ` <a12c5a59-d2e0-5866-d225-501d19a3ec7b-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
2017-07-21 14:29 ` Daniel Borkmann via iovisor-dev
[not found] ` <2ebcb201-2f18-7276-f4f9-f2bbaffae179-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
2017-07-21 13:37 ` [PATCH net 2/2] bpf/verifier: fix min/max handling in BPF_SUB Edward Cree via iovisor-dev
[not found] ` <e3fa964f-54f2-7310-59d1-41a4b7ad9a5b-s/n/eUQHGBpZroRs9YW3xA@public.gmane.org>
2017-07-21 14:30 ` Daniel Borkmann via iovisor-dev [this message]
2017-07-21 15:54 ` [PATCH net 0/2] bpf: fix verifier " Nadav Amit via iovisor-dev
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=iovisor-dev-9jonkmmolfhee9la1f8ukti2o/jbrioy@public$(echo .)gmane.org \
--cc=alexei.starovoitov-Re5JQEeQqe8AvxtiuMwx3w@public$(echo .)gmane.org \
--cc=ast-b10kYP2dOMg@public$(echo .)gmane.org \
--cc=daniel-FeC+5ew28dpmcu3hnIyYJQ@public$(echo .)gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public$(echo .)gmane.org \
--cc=ecree-s/n/eUQHGBpZroRs9YW3xA@public$(echo .)gmane.org \
--cc=josef-DigfWCa+lFGyeJad7bwFQA@public$(echo .)gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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