From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,surenb@google.com,stable+noautosel@kernel.org,
richardycc@google.com,minchan@kernel.org,bgeffon@google.com,
senozhatsky@chromium.org,akpm@linux-foundation.org
Subject: + zram-avoid-rollback-uaf-in-zcomp_cpu_up_prepare.patch added to mm-new branch
Date: Mon, 30 Nov 2026 17:31:34 -0800 [thread overview]
Message-ID: <20261201013134.E4D2F1F000C1@smtp.kernel.org> (raw)
In-Reply-To: <20261130045410.68479-2-senozhatsky@chromium.org>
The patch titled
Subject: zram: avoid rollback UAF in zcomp_cpu_up_prepare()
has been added to the -mm mm-new branch. Its filename is
zram-avoid-rollback-uaf-in-zcomp_cpu_up_prepare.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/zram-avoid-rollback-uaf-in-zcomp_cpu_up_prepare.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: zram: avoid rollback UAF in zcomp_cpu_up_prepare()
Date: Mon, 30 Nov 2026 13:43:38 +0900
Patch series "zram: fix pCPU stream access vs CPU-hotplug races".
Suren Baghdasaryan ran an internal model on zram and found a couple of
pre-existing issues with per-CPU stream access in zram. Both are very low
risk, related to preemption and CPU-hotplug races, and have existed since
v6.15. Because zcomp has been redesigned since v6.15 (split into separate
R/W streams), these patches do not apply to stable trees as-is, thus
stable+noautosel tag.
This patch (of 2):
A task on CPU1 can grab CPU1's per-CPU compression stream pointer via
raw_cpu_ptr() and get preempted before taking cstrm->lock. If CPU1 goes
offline, the task is migrated to another CPU while still holding its
pointer to CPU1's cstrm, and zcomp_cpu_dead() destroys that stream under
its lock. When CPU1 starts coming back online, the task can resume on
that other CPU and acquire CPU1's cstrm->lock while zcomp_cpu_up_prepare()
is still rebuilding CPU1's streams.
Currently zcomp_cpu_up_prepare() sets cstrm->buffer before calling
zcomp_dstrm_init(). If the resumed writer acquires cstrm->lock, sees
cstrm->buffer != NULL and starts compressing, and zcomp_dstrm_init() then
fails, the rollback calls zcomp_cstrm_free() without cstrm->lock, freeing
->ctx and ->buffer under the active writer.
Splitting zcomp into separate R/W streams widened this window: before
that, the rollback could only follow a failed ->local_copy allocation in
zcomp_strm_init().
Move the buffer vzalloc() calls out of zcomp_{c,d}strm_init() (renamed to
zcomp_{c,d}strm_ctx_init(), paired with zcomp_{c,d}strm_ctx_free()) into
zcomp_cpu_up_prepare() and zcomp_init(). Because ->buffer and
->local_copy remain NULL and untouched on the error paths, nothing reads
->ctx and rollback never races with a resumed writer.
Link: https://lore.kernel.org/20261130045410.68479-1-senozhatsky@chromium.org
Link: https://patch.msgid.link/20261130045410.68479-2-senozhatsky@chromium.org
Fixes: 2efa9e9eb4db ("zram: permit preemption with active compression stream")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Brian Geffon <bgeffon@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Richard Chang <richardycc@google.com>
Cc: <stable+noautosel@kernel.org> # depends on the zram R/W stream split, not in stable trees
drivers/block/zram/zcomp.c | 83 +++++++++++++++++++++++------------
1 file changed, 56 insertions(+), 27 deletions(-)
--- a/drivers/block/zram/zcomp.c~zram-avoid-rollback-uaf-in-zcomp_cpu_up_prepare
+++ a/drivers/block/zram/zcomp.c
@@ -45,16 +45,21 @@ static const struct zcomp_ops *backends[
NULL
};
-static void zcomp_cstrm_free(struct zcomp *comp, struct zcomp_cstrm *zstrm)
+static void zcomp_cstrm_ctx_free(struct zcomp *comp, struct zcomp_cstrm *zstrm)
{
if (comp->ops->destroy_cctx)
comp->ops->destroy_cctx(&zstrm->ctx);
+ zstrm->ctx.context = NULL;
+}
+
+static void zcomp_cstrm_free(struct zcomp *comp, struct zcomp_cstrm *zstrm)
+{
+ zcomp_cstrm_ctx_free(comp, zstrm);
vfree(zstrm->buffer);
zstrm->buffer = NULL;
- zstrm->ctx.context = NULL;
}
-static int zcomp_cstrm_init(struct zcomp *comp, struct zcomp_cstrm *zstrm)
+static int zcomp_cstrm_ctx_init(struct zcomp *comp, struct zcomp_cstrm *zstrm)
{
int ret;
@@ -67,28 +72,24 @@ static int zcomp_cstrm_init(struct zcomp
}
}
- /*
- * allocate 2 pages. 1 for compressed data, plus 1 extra for the
- * case when compressed size is larger than the original one
- */
- zstrm->buffer = vzalloc(2 * PAGE_SIZE);
- if (!zstrm->buffer) {
- zcomp_cstrm_free(comp, zstrm);
- return -ENOMEM;
- }
return 0;
}
-static void zcomp_dstrm_free(struct zcomp *comp, struct zcomp_dstrm *zstrm)
+static void zcomp_dstrm_ctx_free(struct zcomp *comp, struct zcomp_dstrm *zstrm)
{
if (comp->ops->destroy_dctx)
comp->ops->destroy_dctx(&zstrm->ctx);
+ zstrm->ctx.context = NULL;
+}
+
+static void zcomp_dstrm_free(struct zcomp *comp, struct zcomp_dstrm *zstrm)
+{
+ zcomp_dstrm_ctx_free(comp, zstrm);
vfree(zstrm->local_copy);
zstrm->local_copy = NULL;
- zstrm->ctx.context = NULL;
}
-static int zcomp_dstrm_init(struct zcomp *comp, struct zcomp_dstrm *zstrm)
+static int zcomp_dstrm_ctx_init(struct zcomp *comp, struct zcomp_dstrm *zstrm)
{
int ret;
@@ -101,11 +102,6 @@ static int zcomp_dstrm_init(struct zcomp
}
}
- zstrm->local_copy = vzalloc(PAGE_SIZE);
- if (!zstrm->local_copy) {
- zcomp_dstrm_free(comp, zstrm);
- return -ENOMEM;
- }
return 0;
}
@@ -333,27 +329,55 @@ int zcomp_cpu_up_prepare(unsigned int cp
struct zcomp *comp = hlist_entry(node, struct zcomp, node);
struct zcomp_cstrm *cstrm = NULL;
struct zcomp_dstrm *dstrm;
+ void *buffer = NULL, *local_copy;
int ret;
if (comp->cstream) {
cstrm = per_cpu_ptr(comp->cstream, cpu);
- ret = zcomp_cstrm_init(comp, cstrm);
+ ret = zcomp_cstrm_ctx_init(comp, cstrm);
if (ret) {
pr_err("Can't allocate a compression stream\n");
return ret;
}
+
+ /*
+ * allocate 2 pages. 1 for compressed data, plus 1 extra for
+ * the case when compressed size is larger than the original
+ * one
+ */
+ buffer = vzalloc(2 * PAGE_SIZE);
+ if (!buffer) {
+ zcomp_cstrm_ctx_free(comp, cstrm);
+ return -ENOMEM;
+ }
}
dstrm = per_cpu_ptr(comp->dstream, cpu);
- ret = zcomp_dstrm_init(comp, dstrm);
+ ret = zcomp_dstrm_ctx_init(comp, dstrm);
if (ret) {
pr_err("Can't allocate a decompression stream\n");
- if (cstrm)
- zcomp_cstrm_free(comp, cstrm);
- return ret;
+ goto err;
+ }
+
+ local_copy = vzalloc(PAGE_SIZE);
+ if (!local_copy) {
+ zcomp_dstrm_ctx_free(comp, dstrm);
+ ret = -ENOMEM;
+ goto err;
}
+ if (cstrm)
+ cstrm->buffer = buffer;
+ dstrm->local_copy = local_copy;
+
return 0;
+
+err:
+ if (cstrm) {
+ vfree(buffer);
+ zcomp_cstrm_ctx_free(comp, cstrm);
+ }
+ return ret;
}
int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node)
@@ -394,13 +418,18 @@ static int zcomp_init(struct zcomp *comp
goto cleanup;
}
mutex_init(&comp->recomp_cstream->lock);
- ret = zcomp_cstrm_init(comp, comp->recomp_cstream);
+ ret = zcomp_cstrm_ctx_init(comp, comp->recomp_cstream);
if (ret) {
- /* zcomp_cstrm_init() cleans up after itself */
+ /* zcomp_cstrm_ctx_init() cleans up after itself */
kfree(comp->recomp_cstream);
comp->recomp_cstream = NULL;
goto cleanup;
}
+ comp->recomp_cstream->buffer = vzalloc(2 * PAGE_SIZE);
+ if (!comp->recomp_cstream->buffer) {
+ ret = -ENOMEM;
+ goto cleanup;
+ }
} else {
comp->cstream = alloc_percpu(struct zcomp_cstrm);
if (!comp->cstream) {
_
Patches currently in -mm which might be from senozhatsky@chromium.org are
zram-prefix-backends-printk-s.patch
zram-remove-debugfs-entry-on-init-failure.patch
zram-reset-writeback-state-in-zram_reset_device.patch
zram-move-mark_slot_accessed-under-existing-slot-lock-sections.patch
zram-remove-stale-warn_on-from-zram_read_page.patch
zram-zstd-do-not-allocate-empty-c-d-dictionaries.patch
zram-lz4hc-pre-initialize-dictionary-stream-in-setup_params.patch
zram-lz4-use-lz4_decompress_safe_usingdict.patch
zram-lz4hc-use-lz4_decompress_safe_usingdict.patch
zram-zstd-do-not-use-kvzalloc-for-zstd-allocations.patch
zram-split-zcomp-into-separate-r-w-streams.patch
zram-introduce-shared-decompression-streams.patch
zram-allocate-bounce-buffer-for-spanning-objects.patch
zram-borrow-idle-decompression-streams-in-exclusive-mode.patch
zram-use-a-singleton-compression-context-for-recompression.patch
zram-drop-stale-comment-in-write_incompressible_page.patch
zram-drop-get_slot_handle-and-set_slot_handle.patch
zsmalloc-return-handle-from-obj_allocated.patch
zsmalloc-switch-handle-type-to-struct-zs_handle.patch
zram-check-mem_limit-before-allocating-zsmalloc-object.patch
zram-allocate-zsmalloc-object-under-slot-lock.patch
zswap-do-not-free-the-entry-if-its-pool-is-null.patch
zsmalloc-encode-1-based-obj_idx-so-valid-obj-is-never-0.patch
zsmalloc-embed-struct-zs_handle-into-zram-and-zswap-entries.patch
zsmalloc-fold-zs_obj_write-into-zs_store.patch
zsmalloc-populate-new-zspage-outside-class-lock-in-zs_store.patch
zram-fix-quadratic-writeback-bitmap-search.patch
zsmalloc-free-a-zspages-pages-in-one-batch.patch
zram-keep-the-hot-statistics-per-cpu.patch
zram-do-not-modify-cont-sysfs-store-buffers.patch
zram-avoid-rollback-uaf-in-zcomp_cpu_up_prepare.patch
zram-publish-streams-under-lock-in-zcomp_cpu_up_prepare.patch
zsmalloc-fix-spdx-license-identifier.patch
zram-use-spdx-license-identifier.patch
maintainers-add-mm-and-block-lists-to-zram-entry.patch
next prev parent reply other threads:[~2026-12-01 1:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 4:43 [PATCH 0/2] zram: fix pCPU stream access vs CPU-hotplug races Sergey Senozhatsky
2026-11-30 4:43 ` [PATCH 1/2] zram: avoid rollback UAF in zcomp_cpu_up_prepare() Sergey Senozhatsky
2026-12-01 1:31 ` Andrew Morton [this message]
2026-11-30 4:43 ` [PATCH 2/2] zram: publish streams under lock " Sergey Senozhatsky
2026-12-01 1:31 ` + zram-publish-streams-under-lock-in-zcomp_cpu_up_prepare.patch added to mm-new branch Andrew Morton
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=20261201013134.E4D2F1F000C1@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=bgeffon@google.com \
--cc=minchan@kernel.org \
--cc=mm-commits@vger.kernel.org \
--cc=richardycc@google.com \
--cc=senozhatsky@chromium.org \
--cc=stable+noautosel@kernel.org \
--cc=surenb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.