All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] apparmor: return 0 from unpack_tag_headers() on success
@ 2026-11-27  8:01 Cong Nguyen
  2026-11-27  8:05 ` sashiko-bot
  2026-11-28  3:03 ` Guicai Ma
  0 siblings, 2 replies; 4+ messages in thread
From: Cong Nguyen @ 2026-11-27  8:01 UTC (permalink / raw)
  To: John Johansen, Georgia Garcia
  Cc: apparmor, linux-security-module, linux-kernel

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@gmail.com>
---
 security/apparmor/policy_unpack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index 24fbce2e4322..b6864757e6dd 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -841,7 +841,7 @@ static int unpack_tag_headers(struct aa_ext *e, struct aa_tags_struct *tags)
 	tags->hdrs.size = size;
 	tags->hdrs.table = hdrs;
 	AA_DEBUG(DEBUG_UNPACK, "headers %ld size %d", (long) hdrs, size);
-	return true;
+	return 0;
 
 fail:
 	kfree_sensitive(hdrs);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] apparmor: return 0 from unpack_tag_headers() on success
  2026-11-27  8:01 [PATCH] apparmor: return 0 from unpack_tag_headers() on success Cong Nguyen
@ 2026-11-27  8:05 ` sashiko-bot
  2026-11-28  3:03 ` Guicai Ma
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-27  8:05 UTC (permalink / raw)
  Cc: linux-security-module

> 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@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127080132.266236-1-congnt264@gmail.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] apparmor: return 0 from unpack_tag_headers() on success
  2026-11-27  8:01 [PATCH] apparmor: return 0 from unpack_tag_headers() on success Cong Nguyen
  2026-11-27  8:05 ` sashiko-bot
@ 2026-11-28  3:03 ` Guicai Ma
  2026-11-28 10:37   ` Nguyễn Công
  1 sibling, 1 reply; 4+ messages in thread
From: Guicai Ma @ 2026-11-28  3:03 UTC (permalink / raw)
  To: Cong Nguyen
  Cc: Guicai Ma, John Johansen, Georgia Garcia, apparmor,
	linux-security-module, linux-kernel

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@gmail.com>

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@vger.kernel.org.

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@kylinos.cn>
Tested-by: Guicai Ma <maguicai@kylinos.cn>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] apparmor: return 0 from unpack_tag_headers() on success
  2026-11-28  3:03 ` Guicai Ma
@ 2026-11-28 10:37   ` Nguyễn Công
  0 siblings, 0 replies; 4+ messages in thread
From: Nguyễn Công @ 2026-11-28 10:37 UTC (permalink / raw)
  To: Guicai Ma
  Cc: John Johansen, Georgia Garcia, apparmor, linux-security-module,
	linux-kernel, stable

On Sat, Nov 28, 2026 at 10:03 AM Guicai Ma <maguicai@kylinos.cn> 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@gmail.com>
>
> 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@vger.kernel.org.
Hi Guicai,

Thanks for the review and the test. Agreed, the profile fails to load
with -EPROTO,
and this wants stable@vger.kernel.org. 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@kylinos.cn>
> Tested-by: Guicai Ma <maguicai@kylinos.cn>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-28 10:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  8:01 [PATCH] apparmor: return 0 from unpack_tag_headers() on success Cong Nguyen
2026-11-27  8:05 ` sashiko-bot
2026-11-28  3:03 ` Guicai Ma
2026-11-28 10:37   ` Nguyễn Công

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.