[PATCH slab/for-next 11/14] smack: specify SLAB_MAY_ACCOUNT for smack_rule cache

From: Harry Yoo (Meta)

Date: Wed Oct 21 2026 - 07:56:46 EST


smk_copy_rules() allocates rules with the gfp passed from
security_prepare_creds(), which is GFP_KERNEL_ACCOUNT. Specify
SLAB_MAY_ACCOUNT when the object may be charged to a memcg.
__GFP_ACCOUNT without SLAB_MAY_ACCOUNT will not be allowed.

Path: fork() -> copy_creds() -> prepare_creds()
-> security_prepare_creds(GFP_KERNEL_ACCOUNT) -> smack_cred_prepare()
-> smk_copy_rules() -> kmem_cache_zalloc(smack_rule_cache)

Assisted-by: LLM
Cc: Casey Schaufler <casey@xxxxxxxxxxxxxxxx>
Cc: Paul Moore <paul@xxxxxxxxxxxxxx>
Cc: James Morris <jmorris@xxxxxxxxx>
Cc: "Serge E. Hallyn" <serge@xxxxxxxxxx>
Cc: linux-security-module@xxxxxxxxxxxxxxx
Signed-off-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>
---
security/smack/smack_lsm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 8e88ac65fd7f..8a802578ac29 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -5352,7 +5352,7 @@ static __init int smack_init(void)
struct cred *cred = (struct cred *) current->cred;
struct task_smack *tsp;

- smack_rule_cache = KMEM_CACHE(smack_rule, 0);
+ smack_rule_cache = KMEM_CACHE(smack_rule, SLAB_MAY_ACCOUNT);
if (!smack_rule_cache)
return -ENOMEM;


--
2.54.0