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: <uaf4x2aczwt3fphtnxly4vvvnzcuq6wyhtawcoh6j3sjsf2f2w@6mmc3d5cwqev>
Date: Tue, 30 Apr 2024 11:20:19 +0200
From: Benjamin Tissoires <bentiss@...nel.org>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>, 
	Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>, 
	Martin KaFai Lau <martin.lau@...ux.dev>, Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>, 
	Yonghong Song <yonghong.song@...ux.dev>, John Fastabend <john.fastabend@...il.com>, 
	KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...gle.com>, Hao Luo <haoluo@...gle.com>, 
	Jiri Olsa <jolsa@...nel.org>, Mykola Lysenko <mykolal@...com>, Shuah Khan <shuah@...nel.org>, 
	bpf <bpf@...r.kernel.org>, LKML <linux-kernel@...r.kernel.org>, 
	"open list:KERNEL SELFTEST FRAMEWORK" <linux-kselftest@...r.kernel.org>
Subject: Re: [PATCH 2/3] bpf: do not walk twice the hash map on free

On Apr 25 2024, Alexei Starovoitov wrote:
> On Thu, Apr 25, 2024 at 6:59 AM Benjamin Tissoires <bentiss@...nel.org> wrote:
> >
> > If someone stores both a timer and a workqueue in a hash map, on free, we
> > would walk it twice.
> > Add a check in htab_free_malloced_timers_or_wq and free the timers
> > and workqueues if they are present.
> >
> > Fixes: 246331e3f1ea ("bpf: allow struct bpf_wq to be embedded in arraymaps and hashmaps")
> > Signed-off-by: Benjamin Tissoires <bentiss@...nel.org>
> > ---
> >  kernel/bpf/hashtab.c | 16 +++++-----------
> >  1 file changed, 5 insertions(+), 11 deletions(-)
> >
> > diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> > index 0179183c543a..20162ae741e9 100644
> > --- a/kernel/bpf/hashtab.c
> > +++ b/kernel/bpf/hashtab.c
> > @@ -1515,7 +1515,7 @@ static void delete_all_elements(struct bpf_htab *htab)
> >         migrate_enable();
> >  }
> >
> > -static void htab_free_malloced_timers_or_wq(struct bpf_htab *htab, bool is_timer)
> > +static void htab_free_malloced_timers_or_wq(struct bpf_htab *htab)
> >  {
> >         int i;
> >
> > @@ -1527,10 +1527,10 @@ static void htab_free_malloced_timers_or_wq(struct bpf_htab *htab, bool is_timer
> >
> >                 hlist_nulls_for_each_entry(l, n, head, hash_node) {
> >                         /* We only free timer on uref dropping to zero */
> > -                       if (is_timer)
> > +                       if (btf_record_has_field(htab->map.record, BPF_TIMER))
> >                                 bpf_obj_free_timer(htab->map.record,
> >                                                    l->key + round_up(htab->map.key_size, 8));
> > -                       else
> > +                       if (btf_record_has_field(htab->map.record, BPF_WORKQUEUE))
> >                                 bpf_obj_free_workqueue(htab->map.record,
> >                                                        l->key + round_up(htab->map.key_size, 8));
> >                 }
> > @@ -1544,18 +1544,12 @@ static void htab_map_free_timers_and_wq(struct bpf_map *map)
> >         struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
> >
> >         /* We only free timer and workqueue on uref dropping to zero */
> > -       if (btf_record_has_field(htab->map.record, BPF_TIMER)) {
> > +       if (btf_record_has_field(htab->map.record, BPF_TIMER | BPF_WORKQUEUE)) {
> >                 if (!htab_is_prealloc(htab))
> > -                       htab_free_malloced_timers_or_wq(htab, true);
> > +                       htab_free_malloced_timers_or_wq(htab);
> >                 else
> >                         htab_free_prealloced_timers(htab);
> >         }
> > -       if (btf_record_has_field(htab->map.record, BPF_WORKQUEUE)) {
> > -               if (!htab_is_prealloc(htab))
> > -                       htab_free_malloced_timers_or_wq(htab, false);
> > -               else
> > -                       htab_free_prealloced_wq(htab);
> 
> This looks wrong.
> htab_free_prealloced_wq() is now unused as compiler says:
> ../kernel/bpf/hashtab.c:243:13: warning: ‘htab_free_prealloced_wq’
> defined but not used [-Wunused-function]
>   243 | static void htab_free_prealloced_wq(struct bpf_htab *htab)
>       |             ^~~~~~~~~~~~~~~~~~~~~~~
> 
> and prealloced maps with wq leak wq-s.

oops, you are right. Sending a v2 right away (sorry for the delay).

Cheers,
Benjamin

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ