Re: [PATCH bpf-next 2/2] selftests/bpf: Add test for resizing data map with struct_ops

From: David Vernet
Date: Wed Jul 24 2024 - 22:55:12 EST


On Wed, Jul 24, 2024 at 05:12:00PM -0700, Andrii Nakryiko wrote:
> On Wed, Jul 24, 2024 at 10:15 AM David Vernet <void@xxxxxxxxxxxxx> wrote:
> >
> > Tests that if you resize a map after opening a skel, that it doesn't
> > cause a UAF which causes a struct_ops map to fail to be able to load.
> >
> > Signed-off-by: David Vernet <void@xxxxxxxxxxxxx>
> > ---
> > .../bpf/prog_tests/struct_ops_resize.c | 30 +++++++++++++++++++
> > .../selftests/bpf/progs/struct_ops_resize.c | 24 +++++++++++++++
> > 2 files changed, 54 insertions(+)
> > create mode 100644 tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c
> > create mode 100644 tools/testing/selftests/bpf/progs/struct_ops_resize.c
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c b/tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c
> > new file mode 100644
> > index 000000000000..7584f91c2bd1
> > --- /dev/null
> > +++ b/tools/testing/selftests/bpf/prog_tests/struct_ops_resize.c
> > @@ -0,0 +1,30 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include <test_progs.h>
> > +#include "struct_ops_resize.skel.h"
> > +
> > +static void resize_datasec(void)
> > +{
> > + struct struct_ops_resize *skel;
> > + int err;
> > +
> > + skel = struct_ops_resize__open();
> > + if (!ASSERT_OK_PTR(skel, "struct_ops_resize__open"))
> > + return;
> > +
> > + err = bpf_map__set_value_size(skel->maps.data_resizable, 1 << 15);
> > + if (!ASSERT_OK(err, "bpf_map__set_value_size"))
> > + goto cleanup;
> > +
> > + err = struct_ops_resize__load(skel);
> > + ASSERT_OK(err, "struct_ops_resize__load");
> > +
> > +cleanup:
> > + struct_ops_resize__destroy(skel);
> > +}
> > +
> > +void test_struct_ops_resize(void)
> > +{
> > + if (test__start_subtest("resize_datasec"))
> > + resize_datasec();
>
> It seems a bit unnecessary to add an entire new test with a subtest
> just for this. Would you mind adding this testing logic into the
> already existing prog_tests/global_map_resize.c set of cases?

Sure thing, I'll send a subsequent patch that adds the testcase to
prog_tests/global_map_resize.c.

> I've applied patch #1, as it's obviously correct, so I didn't want to
> delay the fix. Thanks!

Thanks!

Attachment: signature.asc
Description: PGP signature