From: Link Lin <linkl@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@kernel.org>,
"Michael S . Tsirkin" <mst@redhat.com>,
David Hildenbrand <david@kernel.org>
Cc: virtualization@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, prasin@google.com,
rientjes@google.com, duenwen@google.com, jasowang@redhat.com,
xuanzhuo@linux.alibaba.com,
Ammar Faizi <ammarfaizi2@openresty.com>,
jiaqiyan@google.com, ahwilkins@google.com,
Greg Thelen <gthelen@google.com>,
Alexander Duyck <alexander.duyck@gmail.com>,
jthoughton@google.com, stable@vger.kernel.org,
Link Lin <linkl@google.com>
Subject: [PATCH v2 0/2] virtio_balloon: fix Use-After-Free bugs during PM freeze
Date: Fri, 17 Jul 2026 00:22:19 +0000 [thread overview]
Message-ID: <20260717002311.681748-1-linkl@google.com> (raw)
This patch series addresses a class of Use-After-Free vulnerabilities
in the virtio_balloon driver that can occur during system power management
freeze (e.g., suspend or hibernation).
The core issue is a lifecycle mismatch: when the system enters freeze,
virtballoon_freeze() resets the virtio device and deletes its virtqueues.
However, several asynchronous or event-driven components of the driver and
related subsystems (Free Page Reporting and Shrinker) remain registered
and active. If they trigger during the freeze/suspend process, they
attempt to access the now-deleted virtqueues, causing kernel crashes
(General Protection Faults or UAF).
To fix this:
1. Migrate Free Page Reporting to use the system_freezable_wq, ensuring
its worker is frozen before driver freeze callbacks run. (Suggested
by David Hildenbrand).
2. Avoid shrinker execution while the device is suspended by adding a
suspended flag to struct virtio_balloon. Wrap lockless reads of this
flag in READ_ONCE() and writes in WRITE_ONCE() to prevent data races and
KCSAN warnings.
Note: The OOM notifier (virtio_balloon_oom_notify) is also registered, but
since the PM core disables the OOM killer (via oom_killer_disable()) during
freeze_processes() before device drivers are frozen, it cannot trigger
while the device is frozen. Thus, it does not require a fix.
Testing:
I have verified these fixes using Google’s virtualization infrastructure by
running continuous suspend/resume iterations (40+ cycles) while
churning memory using stress-ng (stress-ng --vm 4 --vm-bytes 60% --timeout 1)
to constantly create free pages for the buddy allocator. We also set the
page_reporting_order parameter to 0 to make the page reporting worker
highly sensitive, forcing it to pick up any 4K free pages. This
confirmed that the UAF crashes are no longer reproducible.
RFC: https://lore.kernel.org/r/20260709224330.946683-1-linkl@google.com
---
RFC -> v2:
- Switched page reporting fix from unregister/re-register in driver to
using system_freezable_wq in mm/page_reporting.c, which avoids complex
restore rollback logic for that component.
- Switched shrinker fix from unregister/re-register to using a simple
suspended boolean flag to avoid complex rollback logic. Wrap its reads
and writes with READ_ONCE()/WRITE_ONCE() to prevent KCSAN data race
warnings.
- Dropped OOM notifier fix since it's already protected by the PM core's
oom_killer_disable().
Link Lin (2):
mm/page_reporting: use system_freezable_wq to fix UAF during suspend
virtio_balloon: avoid shrinker execution during PM suspend
drivers/virtio/virtio_balloon.c | 49 +++++++++++++++++++++++++++------
mm/page_reporting.c | 6 ++--
2 files changed, 45 insertions(+), 10 deletions(-)
--
2.55.0.229.g6434b31f56-goog
next reply other threads:[~2026-07-17 0:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 0:22 Link Lin [this message]
2026-07-17 0:22 ` [PATCH v2 1/2] mm/page_reporting: use system_freezable_wq to fix UAF during suspend Link Lin
2026-07-17 0:22 ` [PATCH v2 2/2] virtio_balloon: avoid shrinker execution during PM suspend Link Lin
2026-07-17 3:08 ` Link Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260717002311.681748-1-linkl@google.com \
--to=linkl@google.com \
--cc=ahwilkins@google.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.duyck@gmail.com \
--cc=ammarfaizi2@openresty.com \
--cc=david@kernel.org \
--cc=duenwen@google.com \
--cc=gthelen@google.com \
--cc=jasowang@redhat.com \
--cc=jiaqiyan@google.com \
--cc=jthoughton@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=prasin@google.com \
--cc=rientjes@google.com \
--cc=stable@vger.kernel.org \
--cc=vbabka@kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox