Re: [PATCH 1/2] selftests/bpf: Fix read_iter buffer termination in test_bpffs

From: sun jian

Date: Wed Mar 11 2026 - 02:50:34 EST


On Tue, Mar 10, 2026 at 8:28 PM Viktor Malik <vmalik@xxxxxxxxxx> wrote:
>
> Does this fix any real issue with the test? I can see one very
> hypothetical false negative when the uninitialized memory would contain
> "iter" but that seems very unlikely to happen.
>

Hi Viktor,

Thanks for the feedback.

Even if the probability of a false positive is low, the current code
is still incorrect:
on short reads it NUL-terminates only at the end of the buffer, so strstr() can
scan uninitialized stack bytes. That makes the helper potentially
non-deterministic.

Terminating at len makes it deterministic and ensures we only inspect
data actually
returned by read().

Regards,
Sun Jian