Re: [PATCH 2/2] libselinux: fix infinite loop and missing errno in partial <<none>> lookup

Stephen Smalley <[email protected]> Wed, 29 Jul 2026 11:55:21 -0400
Newsgroups org.kernel.vger.selinux
Message-ID <CAEjxPJ5HrRc1k7U9dRBLb4mHbipxigrAsySxov=UncHndpmKpQ@mail.gmail.com>
On Wed, Jul 29, 2026 at 9:40 AM Petr Matyas <[email protected]> wrote:
>
> lookup_check_node() has a do-while loop that iterates over matching
> literal specs. When partial=true and a matching spec has <<none>>
> context the loop body used `continue` to skip to the next entry.
> In a do-while, `continue` jumps to the condition rather than the
> loop increment, so `literal_idx` was never advanced and the loop
> spun forever.
>
> Fix by explicitly incrementing literal_idx before the continue so
> the loop moves to the next literal spec as intended.
>
> Additionally, set errno = ENOENT before continuing so that callers
> which test errno after a NULL return (such as the selabel_file_text
> fuzzer) see a valid error code. Without this, lookup_all() returned
> NULL with errno still 0, violating the expected contract that a NULL
> result is always accompanied by a non-zero errno.
>
> Signed-off-by: Petr Matyas <[email protected]>

Acked-by: Stephen Smalley <[email protected]>