* [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control
@ 2025-09-04 18:12 Stanislav Fort
2025-09-04 18:33 ` Roman Gushchin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Stanislav Fort @ 2025-09-04 18:12 UTC (permalink / raw)
To: linux-mm, cgroups, linux-kernel
Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, akpm,
stable, Stanislav Fort
In cgroup v1, the legacy cgroup.event_control file is world-writable and allows unprivileged users to register unbounded events and thresholds. Each registration allocates kernel memory without capping or memcg charging, which can be abused to exhaust kernel memory in affected configurations.
Make the following minimal changes:
- Account allocations with __GFP_ACCOUNT in event and threshold registration.
- Remove CFTYPE_WORLD_WRITABLE from cgroup.event_control to make it owner-writable.
This does not affect cgroup v2. Allocations are still subject to kmem accounting being enabled, but this reduces unbounded global growth.
Reported-by: Stanislav Fort <disclosure@aisle.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: stable@vger.kernel.org
Signed-off-by: Stanislav Fort <disclosure@aisle.com>
---
mm/memcontrol-v1.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 4b94731305b9..9374785319ab 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -761,7 +761,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
size = thresholds->primary ? thresholds->primary->size + 1 : 1;
/* Allocate memory for new array of thresholds */
- new = kmalloc(struct_size(new, entries, size), GFP_KERNEL);
+ new = kmalloc(struct_size(new, entries, size), GFP_KERNEL | __GFP_ACCOUNT);
if (!new) {
ret = -ENOMEM;
goto unlock;
@@ -924,7 +924,7 @@ static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg,
{
struct mem_cgroup_eventfd_list *event;
- event = kmalloc(sizeof(*event), GFP_KERNEL);
+ event = kmalloc(sizeof(*event), GFP_KERNEL | __GFP_ACCOUNT);
if (!event)
return -ENOMEM;
@@ -1087,7 +1087,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
CLASS(fd, cfile)(cfd);
- event = kzalloc(sizeof(*event), GFP_KERNEL);
+ event = kzalloc(sizeof(*event), GFP_KERNEL | __GFP_ACCOUNT);
if (!event)
return -ENOMEM;
@@ -2053,7 +2053,7 @@ struct cftype mem_cgroup_legacy_files[] = {
{
.name = "cgroup.event_control", /* XXX: for compat */
.write = memcg_write_event_control,
- .flags = CFTYPE_NO_PREFIX | CFTYPE_WORLD_WRITABLE,
+ .flags = CFTYPE_NO_PREFIX,
},
{
.name = "swappiness",
--
2.39.3 (Apple Git-146)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control
2025-09-04 18:12 [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control Stanislav Fort
@ 2025-09-04 18:33 ` Roman Gushchin
2025-09-04 23:46 ` Shakeel Butt
2025-09-05 9:38 ` Stanislav Fort
2 siblings, 0 replies; 5+ messages in thread
From: Roman Gushchin @ 2025-09-04 18:33 UTC (permalink / raw)
To: Stanislav Fort
Cc: linux-mm, cgroups, linux-kernel, hannes, mhocko, shakeel.butt,
muchun.song, akpm, stable, Stanislav Fort
On Thu, Sep 04, 2025 at 09:12:48PM +0300, Stanislav Fort wrote:
> In cgroup v1, the legacy cgroup.event_control file is world-writable and allows unprivileged users to register unbounded events and thresholds. Each registration allocates kernel memory without capping or memcg charging, which can be abused to exhaust kernel memory in affected configurations.
>
> Make the following minimal changes:
> - Account allocations with __GFP_ACCOUNT in event and threshold registration.
> - Remove CFTYPE_WORLD_WRITABLE from cgroup.event_control to make it owner-writable.
>
> This does not affect cgroup v2. Allocations are still subject to kmem accounting being enabled, but this reduces unbounded global growth.
>
> Reported-by: Stanislav Fort <disclosure@aisle.com>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Stanislav Fort <disclosure@aisle.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Small nit: please, use GFP_KERNEL_ACCOUNT instead of
GFP_KERNEL | __GFP_ACCOUNT.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control
2025-09-04 18:12 [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control Stanislav Fort
2025-09-04 18:33 ` Roman Gushchin
@ 2025-09-04 23:46 ` Shakeel Butt
2025-09-05 9:44 ` Stanislav Fort
2025-09-05 9:38 ` Stanislav Fort
2 siblings, 1 reply; 5+ messages in thread
From: Shakeel Butt @ 2025-09-04 23:46 UTC (permalink / raw)
To: Stanislav Fort
Cc: linux-mm, cgroups, linux-kernel, hannes, mhocko, roman.gushchin,
muchun.song, akpm, stable, Stanislav Fort
On Thu, Sep 04, 2025 at 09:12:48PM +0300, Stanislav Fort wrote:
> In cgroup v1, the legacy cgroup.event_control file is world-writable and allows unprivileged users to register unbounded events and thresholds. Each registration allocates kernel memory without capping or memcg charging, which can be abused to exhaust kernel memory in affected configurations.
>
> Make the following minimal changes:
> - Account allocations with __GFP_ACCOUNT in event and threshold registration.
> - Remove CFTYPE_WORLD_WRITABLE from cgroup.event_control to make it owner-writable.
>
> This does not affect cgroup v2. Allocations are still subject to kmem accounting being enabled, but this reduces unbounded global growth.
>
> Reported-by: Stanislav Fort <disclosure@aisle.com>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Stanislav Fort <disclosure@aisle.com>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control
2025-09-04 18:12 [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control Stanislav Fort
2025-09-04 18:33 ` Roman Gushchin
2025-09-04 23:46 ` Shakeel Butt
@ 2025-09-05 9:38 ` Stanislav Fort
2 siblings, 0 replies; 5+ messages in thread
From: Stanislav Fort @ 2025-09-05 9:38 UTC (permalink / raw)
To: linux-mm, cgroups, linux-kernel
Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, akpm,
stable, Stanislav Fort
Switch __GFP_ACCOUNT to GFP_KERNEL_ACCOUNT as suggested by Roman.
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Stanislav Fort <disclosure@aisle.com>
---
mm/memcontrol-v1.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 4b94731305b9..6eed14bff742 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -761,7 +761,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg,
size = thresholds->primary ? thresholds->primary->size + 1 : 1;
/* Allocate memory for new array of thresholds */
- new = kmalloc(struct_size(new, entries, size), GFP_KERNEL);
+ new = kmalloc(struct_size(new, entries, size), GFP_KERNEL_ACCOUNT);
if (!new) {
ret = -ENOMEM;
goto unlock;
@@ -924,7 +924,7 @@ static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg,
{
struct mem_cgroup_eventfd_list *event;
- event = kmalloc(sizeof(*event), GFP_KERNEL);
+ event = kmalloc(sizeof(*event), GFP_KERNEL_ACCOUNT);
if (!event)
return -ENOMEM;
@@ -1087,7 +1087,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
CLASS(fd, cfile)(cfd);
- event = kzalloc(sizeof(*event), GFP_KERNEL);
+ event = kzalloc(sizeof(*event), GFP_KERNEL_ACCOUNT);
if (!event)
return -ENOMEM;
@@ -2053,7 +2053,7 @@ struct cftype mem_cgroup_legacy_files[] = {
{
.name = "cgroup.event_control", /* XXX: for compat */
.write = memcg_write_event_control,
- .flags = CFTYPE_NO_PREFIX | CFTYPE_WORLD_WRITABLE,
+ .flags = CFTYPE_NO_PREFIX,
},
{
.name = "swappiness",
--
2.39.3 (Apple Git-146)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control
2025-09-04 23:46 ` Shakeel Butt
@ 2025-09-05 9:44 ` Stanislav Fort
0 siblings, 0 replies; 5+ messages in thread
From: Stanislav Fort @ 2025-09-05 9:44 UTC (permalink / raw)
To: Shakeel Butt
Cc: linux-mm, cgroups, linux-kernel, hannes, mhocko, roman.gushchin,
muchun.song, akpm, stable, Stanislav Fort
[-- Attachment #1: Type: text/plain, Size: 1628 bytes --]
Hi Roman, Shakeel, Johannes, and all,
Thanks for the quick reviews and acks.
I’ve sent v2 switching to GFP_KERNEL_ACCOUNT in all three allocations.
Otherwise unchanged.
Link: https://lore.kernel.org/all/aLqvzCiPCGzA5eYo@b7823f61de85/T/#t
If you’d like me to respin to restore any tags into the commit message
(e.g., Acked-by: Johannes, Reported-by, Cc: stable) instead of adding them
while applying, I’m happy to send a trivial v3.
Let me know if this looks good.
Best wishes,
Stanislav Fort
Aisle Research
On Fri, Sep 5, 2025 at 2:46 AM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> On Thu, Sep 04, 2025 at 09:12:48PM +0300, Stanislav Fort wrote:
> > In cgroup v1, the legacy cgroup.event_control file is world-writable and
> allows unprivileged users to register unbounded events and thresholds. Each
> registration allocates kernel memory without capping or memcg charging,
> which can be abused to exhaust kernel memory in affected configurations.
> >
> > Make the following minimal changes:
> > - Account allocations with __GFP_ACCOUNT in event and threshold
> registration.
> > - Remove CFTYPE_WORLD_WRITABLE from cgroup.event_control to make it
> owner-writable.
> >
> > This does not affect cgroup v2. Allocations are still subject to kmem
> accounting being enabled, but this reduces unbounded global growth.
> >
> > Reported-by: Stanislav Fort <disclosure@aisle.com>
> > Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Stanislav Fort <disclosure@aisle.com>
>
> Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
>
[-- Attachment #2: Type: text/html, Size: 2432 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-05 9:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-04 18:12 [PATCH] mm/memcg: v1: account event registrations and drop world-writable cgroup.event_control Stanislav Fort
2025-09-04 18:33 ` Roman Gushchin
2025-09-04 23:46 ` Shakeel Butt
2025-09-05 9:44 ` Stanislav Fort
2025-09-05 9:38 ` Stanislav Fort
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox