lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACkBjsauj7G31uAUB7137+ij5Pf4m-CB=woN35HBbZR5L3E6jg@mail.gmail.com>
Date: Tue, 9 Jan 2024 17:59:49 +0100
From: Hao Sun <sunhao.th@...il.com>
To: Eduard Zingerman <eddyz87@...il.com>
Cc: bpf@...r.kernel.org, willemb@...gle.com, ast@...nel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] bpf: Reject variable offset alu on PTR_TO_FLOW_KEYS

On Tue, Jan 9, 2024 at 5:21 PM Eduard Zingerman <eddyz87@...il.com> wrote:
>
> On Tue, 2024-01-09 at 16:36 +0100, Hao Sun wrote:
> > For PTR_TO_FLOW_KEYS, check_flow_keys_access() only uses fixed off
> > for validation. However, variable offset ptr alu is not prohibited
> > for this ptr kind. So the variable offset is not checked.
> >
> [...]
> >
> > Fixes: d58e468b1112 ("flow_dissector: implements flow dissector BPF hook")
> > Signed-off-by: Hao Sun <sunhao.th@...il.com>
> > ---
> >  kernel/bpf/verifier.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index adbf330d364b..65f598694d55 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -12826,6 +12826,10 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
> >       }
> >
> >       switch (base_type(ptr_reg->type)) {
> > +     case PTR_TO_FLOW_KEYS:
> > +             if (known)
> > +                     break;
> > +             fallthrough;
> >       case CONST_PTR_TO_MAP:
> >               /* smin_val represents the known value */
> >               if (known && smin_val == 0 && opcode == BPF_ADD)
>
> This change makes sense, could you please add a testcase?
>

OK, will do it in the next version tomorrow.

> Also, this switch is written to explicitly disallow and implicitly allow
> pointer arithmetics, which might be a bit unsafe when new ptr types are added.
> Would it make more sense to instead rewrite it to explicitly allow?

Yes, this sounds more safe and clear to me, should be done in another patch.

> E.g. here is what it currently allows / disallows:
>
> | Pointer type        | Arithmetics allowed |
> |---------------------+---------------------|
> | PTR_TO_CTX          | yes                 |
> | CONST_PTR_TO_MAP    | conditionally       |
> | PTR_TO_MAP_VALUE    | yes                 |
> | PTR_TO_MAP_KEY      | yes                 |
> | PTR_TO_STACK        | yes                 |
> | PTR_TO_PACKET_META  | yes                 |
> | PTR_TO_PACKET       | yes                 |
> | PTR_TO_PACKET_END   | no                  |
> | PTR_TO_FLOW_KEYS    | yes                 |

This one should be `conditionally`, variable offset disallowed, fixed allowed.

> | PTR_TO_SOCKET       | no                  |
> | PTR_TO_SOCK_COMMON  | no                  |
> | PTR_TO_TCP_SOCK     | no                  |
> | PTR_TO_TP_BUFFER    | yes                 |
> | PTR_TO_XDP_SOCK     | no                  |
> | PTR_TO_BTF_ID       | yes                 |
> | PTR_TO_MEM          | yes                 |
> | PTR_TO_BUF          | yes                 |
> | PTR_TO_FUNC         | yes                 |
> | CONST_PTR_TO_DYNPTR | yes                 |
>
> Of these PTR_TO_FUNC and CONST_PTR_TO_DYNPTR (?) should not be allowed
> as well, probably (not sure if that could be exploited).

I think both should be disallowed.

If alu sanitation is triggered, alu op on func and dynptr would be
rejected by retrieve_ptr_limit();
otherwise, it could be dangerous.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ