Re: [PATCH] apparmor: return 0 from unpack_tag_headers() on success

From: Nguyễn Công

Date: Sat Nov 28 2026 - 05:38:12 EST


On Sat, Nov 28, 2026 at 10:03 AM Guicai Ma <maguicai@xxxxxxxxxx> wrote:
>
> On Fri, Nov 27, 2026 at 03:01:32PM +0700, Cong Nguyen wrote:
> > unpack_tag_headers() returns int, where 0 means success and a negative
> > errno means failure, like unpack_strs_table() and unpack_tagsets() which
> > unpack_tags() calls next to it. On success it returns true, which is 1.
> >
> > unpack_tags() tests the result with "if (error)", so a successfully
> > unpacked "hdrs" array is treated as a failure: unpack_tags() destroys the
> > tags, rewinds e->pos and returns 1. Its caller, unpack_pdb(), only checks
> > for "< 0", so it continues without the tags.
> >
> > Return 0 on success.
> >
> > Fixes: 3d28e2397af7 ("apparmor: add support loading per permission tagging")
> > Signed-off-by: Cong Nguyen <congnt264@xxxxxxxxx>
>
> Looks good. Because unpack_tags() rewinds e->pos to the start of "tags"
> before returning 1, unpack_pdb() leaves that section unconsumed and the
> profile fails to unpack (-EPROTO) rather than continuing without tags.
> Since tagged profiles cannot be loaded at all since 3d28e2397af7, this
> probably wants Cc: stable@xxxxxxxxxxxxxxx.
Hi Guicai,

Thanks for the review and the test. Agreed, the profile fails to load
with -EPROTO,
and this wants stable@xxxxxxxxxxxxxxx. Adding stable to Cc.

Thanks, Cong
>
> Tested on mainline (f4585067150b) on arm64/KVM with KASAN and
> CONFIG_SECURITY_APPARMOR_KUNIT_TEST=y: the existing 30
> apparmor_policy_unpack tests pass, and a local KUnit test passing a
> minimal profile with a "tags" section to aa_unpack() fails with -EPROTO
> ("failed to unpack end of profile") before this patch and passes after.
>
> Reviewed-by: Guicai Ma <maguicai@xxxxxxxxxx>
> Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>