* [PATCH] apparmor: set xattr_count only after the xattrs array is allocated
@ 2026-11-27 8:04 Cong Nguyen
2026-11-27 8:07 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-11-27 8:04 UTC (permalink / raw)
To: John Johansen, Georgia Garcia
Cc: apparmor, linux-security-module, linux-kernel
unpack_xattrs() sets profile->attach.xattr_count before it allocates
profile->attach.xattrs with kcalloc(). If the allocation fails, the load
fails and free_attachment() runs on the profile. It loops over
xattr_count entries and reads attach->xattrs[i], which is NULL, so it
dereferences a NULL pointer.
Set xattr_count after the allocation has succeeded.
Fixes: 8e51f9087f40 ("apparmor: Add support for attaching profiles via xattr, presence and value")
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..83cfa981f7bd 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -598,10 +598,10 @@ static bool unpack_xattrs(struct aa_ext *e, struct aa_profile *profile)
if (!aa_unpack_array(e, NULL, &size))
goto fail;
- profile->attach.xattr_count = size;
profile->attach.xattrs = kcalloc(size, sizeof(char *), GFP_KERNEL);
if (!profile->attach.xattrs)
goto fail;
+ profile->attach.xattr_count = size;
for (i = 0; i < size; i++) {
if (!aa_unpack_strdup(e, &profile->attach.xattrs[i], NULL))
goto fail;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] apparmor: set xattr_count only after the xattrs array is allocated
2026-11-27 8:04 [PATCH] apparmor: set xattr_count only after the xattrs array is allocated Cong Nguyen
@ 2026-11-27 8:07 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27 8:07 UTC (permalink / raw)
Cc: linux-security-module
> unpack_xattrs() sets profile->attach.xattr_count before it allocates
> profile->attach.xattrs with kcalloc(). If the allocation fails, the load
> fails and free_attachment() runs on the profile. It loops over
> xattr_count entries and reads attach->xattrs[i], which is NULL, so it
> dereferences a NULL pointer.
>
> Set xattr_count after the allocation has succeeded.
>
> Fixes: 8e51f9087f40 ("apparmor: Add support for attaching profiles via xattr, presence and value")
> Signed-off-by: Cong Nguyen <congnt264@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127080400.275982-1-congnt264@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 8:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 8:04 [PATCH] apparmor: set xattr_count only after the xattrs array is allocated Cong Nguyen
2026-11-27 8:07 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox