Re: [PATCH v4 6/6] binder: encapsulate individual alloc test cases

From: Kees Cook
Date: Thu Jul 17 2025 - 02:32:36 EST


On Wed, Jul 16, 2025 at 06:10:09PM -0700, Tiffany Yang wrote:
> Each case tested by the binder allocator test is defined by 3 parameters:
> the end alignment type of each requested buffer allocation, whether those
> buffers share the front or back pages of the allotted address space, and
> the order in which those buffers should be released. The alignment type
> represents how a binder buffer may be laid out within or across page
> boundaries and relative to other buffers, and it's used along with
> whether the buffers cover part (sharing the front pages) of or all
> (sharing the back pages) of the vma to calculate the sizes passed into
> each test.
>
> binder_alloc_test_alloc recursively generates each possible arrangement
> of alignment types and then tests that the binder_alloc code tracks pages
> correctly when those buffers are allocated and then freed in every
> possible order at both ends of the address space. While they provide
> comprehensive coverage, they are poor candidates to be represented as
> KUnit test cases, which must be statically enumerated. For 5 buffers and
> 5 end alignment types, the test case array would have 750,000 entries.
> This change structures the recursive calls into meaningful test cases so
> that failures are easier to interpret.
>
> Cc: Kees Cook <kees@xxxxxxxxxx>
> Acked-by: Carlos Llamas <cmllamas@xxxxxxxxxx>
> Signed-off-by: Tiffany Yang <ynaffit@xxxxxxxxxx>
> [...]
> +struct binder_alloc_test_case_info {
> + char alignments[ALIGNMENTS_BUFLEN];
> + struct seq_buf alignments_sb;

This really screams for a struct-based way to in-place declare a
seq_buf. The current macro only works on the stack. I think this
will work; I'll send a patch once I get it tested:

#define DECLARE_SEQ_BUF(NAME, SIZE) \
char NAME##_buffer[size]; \
struct seq_buf NAME = { \
.buffer = &NAME##_buffer, \
.size = SIZE, \
}

But yes, this and the seq_buf_init below is correct.

Reviewed-by: Kees Cook <kees@xxxxxxxxxx>

--
Kees Cook