Commit 84029fd0 authored by Shakeel Butt's avatar Shakeel Butt Committed by Linus Torvalds

memcg: account security cred as well to kmemcg

The cred_jar kmem_cache is already memcg accounted in the current kernel
but cred->security is not.  Account cred->security to kmemcg.

Recently we saw high root slab usage on our production and on further
inspection, we found a buggy application leaking processes.  Though that
buggy application was contained within its memcg but we observe much
more system memory overhead, couple of GiBs, during that period.  This
overhead can adversely impact the isolation on the system.

One source of high overhead we found was cred->security objects, which
have a lifetime of at least the life of the process which allocated
them.

Link: http://lkml.kernel.org/r/20191205223721.40034-1-shakeelb@google.comSigned-off-by: default avatarShakeel Butt <shakeelb@google.com>
Acked-by: default avatarChris Down <chris@chrisdown.name>
Reviewed-by: default avatarRoman Gushchin <guro@fb.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a69b83e1
...@@ -223,7 +223,7 @@ struct cred *cred_alloc_blank(void) ...@@ -223,7 +223,7 @@ struct cred *cred_alloc_blank(void)
new->magic = CRED_MAGIC; new->magic = CRED_MAGIC;
#endif #endif
if (security_cred_alloc_blank(new, GFP_KERNEL) < 0) if (security_cred_alloc_blank(new, GFP_KERNEL_ACCOUNT) < 0)
goto error; goto error;
return new; return new;
...@@ -282,7 +282,7 @@ struct cred *prepare_creds(void) ...@@ -282,7 +282,7 @@ struct cred *prepare_creds(void)
new->security = NULL; new->security = NULL;
#endif #endif
if (security_prepare_creds(new, old, GFP_KERNEL) < 0) if (security_prepare_creds(new, old, GFP_KERNEL_ACCOUNT) < 0)
goto error; goto error;
validate_creds(new); validate_creds(new);
return new; return new;
...@@ -715,7 +715,7 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon) ...@@ -715,7 +715,7 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
#ifdef CONFIG_SECURITY #ifdef CONFIG_SECURITY
new->security = NULL; new->security = NULL;
#endif #endif
if (security_prepare_creds(new, old, GFP_KERNEL) < 0) if (security_prepare_creds(new, old, GFP_KERNEL_ACCOUNT) < 0)
goto error; goto error;
put_cred(old); put_cred(old);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment