* [PATCH] mm: zswap: fix objcg use-after-free in entry destruction
@ 2024-01-30 1:34 Johannes Weiner
2024-01-30 1:44 ` Yosry Ahmed
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Johannes Weiner @ 2024-01-30 1:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Nhat Pham, Yosry Ahmed, Chengming Zhou, linux-mm, linux-kernel
In the per-memcg LRU universe, LRU removal uses entry->objcg to
determine which list count needs to be decreased. Drop the objcg
reference after updating the LRU, to fix a possible use-after-free.
Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware")
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
mm/zswap.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index de68a5928527..7f88b3a77e4a 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -522,10 +522,6 @@ static struct zpool *zswap_find_zpool(struct zswap_entry *entry)
*/
static void zswap_free_entry(struct zswap_entry *entry)
{
- if (entry->objcg) {
- obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
- obj_cgroup_put(entry->objcg);
- }
if (!entry->length)
atomic_dec(&zswap_same_filled_pages);
else {
@@ -534,6 +530,10 @@ static void zswap_free_entry(struct zswap_entry *entry)
atomic_dec(&entry->pool->nr_stored);
zswap_pool_put(entry->pool);
}
+ if (entry->objcg) {
+ obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
+ obj_cgroup_put(entry->objcg);
+ }
zswap_entry_cache_free(entry);
atomic_dec(&zswap_stored_pages);
zswap_update_total_size();
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm: zswap: fix objcg use-after-free in entry destruction
2024-01-30 1:34 [PATCH] mm: zswap: fix objcg use-after-free in entry destruction Johannes Weiner
@ 2024-01-30 1:44 ` Yosry Ahmed
2024-01-30 2:41 ` Chengming Zhou
2024-01-30 7:26 ` Nhat Pham
2 siblings, 0 replies; 4+ messages in thread
From: Yosry Ahmed @ 2024-01-30 1:44 UTC (permalink / raw)
To: Johannes Weiner
Cc: Andrew Morton, Nhat Pham, Chengming Zhou, linux-mm, linux-kernel
On Mon, Jan 29, 2024 at 08:34:38PM -0500, Johannes Weiner wrote:
> In the per-memcg LRU universe, LRU removal uses entry->objcg to
> determine which list count needs to be decreased. Drop the objcg
> reference after updating the LRU, to fix a possible use-after-free.
>
> Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware")
Lots of hotfixes for zswap in v6.8 these couple of days :)
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Yosry Ahmed <yosryahmed@google.com>
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm: zswap: fix objcg use-after-free in entry destruction
2024-01-30 1:34 [PATCH] mm: zswap: fix objcg use-after-free in entry destruction Johannes Weiner
2024-01-30 1:44 ` Yosry Ahmed
@ 2024-01-30 2:41 ` Chengming Zhou
2024-01-30 7:26 ` Nhat Pham
2 siblings, 0 replies; 4+ messages in thread
From: Chengming Zhou @ 2024-01-30 2:41 UTC (permalink / raw)
To: Johannes Weiner, Andrew Morton
Cc: Nhat Pham, Yosry Ahmed, linux-mm, linux-kernel
On 2024/1/30 09:34, Johannes Weiner wrote:
> In the per-memcg LRU universe, LRU removal uses entry->objcg to
> determine which list count needs to be decreased. Drop the objcg
> reference after updating the LRU, to fix a possible use-after-free.
>
> Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware")
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
LGTM, thanks!
Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
> ---
> mm/zswap.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index de68a5928527..7f88b3a77e4a 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -522,10 +522,6 @@ static struct zpool *zswap_find_zpool(struct zswap_entry *entry)
> */
> static void zswap_free_entry(struct zswap_entry *entry)
> {
> - if (entry->objcg) {
> - obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> - obj_cgroup_put(entry->objcg);
> - }
> if (!entry->length)
> atomic_dec(&zswap_same_filled_pages);
> else {
> @@ -534,6 +530,10 @@ static void zswap_free_entry(struct zswap_entry *entry)
> atomic_dec(&entry->pool->nr_stored);
> zswap_pool_put(entry->pool);
> }
> + if (entry->objcg) {
> + obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> + obj_cgroup_put(entry->objcg);
> + }
> zswap_entry_cache_free(entry);
> atomic_dec(&zswap_stored_pages);
> zswap_update_total_size();
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm: zswap: fix objcg use-after-free in entry destruction
2024-01-30 1:34 [PATCH] mm: zswap: fix objcg use-after-free in entry destruction Johannes Weiner
2024-01-30 1:44 ` Yosry Ahmed
2024-01-30 2:41 ` Chengming Zhou
@ 2024-01-30 7:26 ` Nhat Pham
2 siblings, 0 replies; 4+ messages in thread
From: Nhat Pham @ 2024-01-30 7:26 UTC (permalink / raw)
To: Johannes Weiner
Cc: Andrew Morton, Yosry Ahmed, Chengming Zhou, linux-mm, linux-kernel
On Mon, Jan 29, 2024 at 5:34 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> In the per-memcg LRU universe, LRU removal uses entry->objcg to
> determine which list count needs to be decreased. Drop the objcg
> reference after updating the LRU, to fix a possible use-after-free.
>
> Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware")
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
> mm/zswap.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index de68a5928527..7f88b3a77e4a 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -522,10 +522,6 @@ static struct zpool *zswap_find_zpool(struct zswap_entry *entry)
> */
> static void zswap_free_entry(struct zswap_entry *entry)
> {
> - if (entry->objcg) {
> - obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> - obj_cgroup_put(entry->objcg);
> - }
> if (!entry->length)
> atomic_dec(&zswap_same_filled_pages);
> else {
> @@ -534,6 +530,10 @@ static void zswap_free_entry(struct zswap_entry *entry)
> atomic_dec(&entry->pool->nr_stored);
> zswap_pool_put(entry->pool);
> }
> + if (entry->objcg) {
> + obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> + obj_cgroup_put(entry->objcg);
> + }
Nice catch!
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
> zswap_entry_cache_free(entry);
> atomic_dec(&zswap_stored_pages);
> zswap_update_total_size();
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-30 7:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 1:34 [PATCH] mm: zswap: fix objcg use-after-free in entry destruction Johannes Weiner
2024-01-30 1:44 ` Yosry Ahmed
2024-01-30 2:41 ` Chengming Zhou
2024-01-30 7:26 ` Nhat Pham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox