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

From: Guicai Ma

Date: Fri Nov 27 2026 - 22:03:40 EST


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.

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>