From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: david@kernel.org, hao.ge@linux.dev, liam@infradead.org,
vbabka@kernel.org, hannes@cmpxchg.org,
brendan.jackman@linux.dev, ziy@nvidia.com,
bigeasy@linutronix.de, clrkwllms@kernel.org,
rostedt@goodmis.org, pasha.tatashin@soleen.com,
pyyjason@gmail.com, usamaarif642@gmail.com, surenb@google.com,
linux-mm@kvack.org, linux-rt-devel@lists.linux.dev
Subject: [PATCH 2/3] alloc_tag: do not leak module tag areas when removing them fails
Date: Thu, 3 Dec 2026 17:56:29 -0800 [thread overview]
Message-ID: <20261204015630.4095988-3-surenb@google.com> (raw)
In-Reply-To: <20261204015630.4095988-1-surenb@google.com>
release_module_tags() removes the area of a module, and the padding in
front of it, from mod_area_mt with mas_store(&mas, NULL). Storing NULL can
merge the range with its neighbours and rebalance the tree, which needs
new maple tree node allocations (with GFP_NOWAIT) and therefore can fail.
If the allocation fails, the area stays in the tree and still points to
the module that is going away. The maple state is left in the error state,
so mas_prev_range() returns NULL and the padding is not removed either.
If the allocation fails when the padding is removed, the padding is
leaked.
Use mas_erase() to remove the entries. It retries the allocation with the
tree lock dropped and cannot fail. Dropping the lock is fine because all
the changes to mod_area_mt are serialized by codetag_lock. Marking the
area with unloaded_mod replaces the entry in place using mas_store()
which does not allocate and therefore can't fail.
Fixes: 0db6f8d7820a ("alloc_tag: load module tags into separate contiguous memory")
Closes: https://sashiko.dev/#/bug/linux-55c2bd22-02fc-49f6-9ee7-e43117224340
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
mm/alloc_tag.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c
index b4e55bbf57f6..7c12053445fe 100644
--- a/mm/alloc_tag.c
+++ b/mm/alloc_tag.c
@@ -1087,10 +1087,20 @@ static void release_module_tags(struct module *mod, bool used)
used = false;
}
release_area:
- mas_store(&mas, used ? &unloaded_mod : NULL);
+ /*
+ * Replacing the entry in place does not need new maple tree nodes and
+ * cannot fail. Removing it might, and mas_store() allocates them with
+ * GFP_NOWAIT. A failure would leave the area reserved forever, with a
+ * stale module pointer in it. Use mas_erase(), which does not fail.
+ */
+ if (used)
+ mas_store(&mas, &unloaded_mod);
+ else
+ mas_erase(&mas);
+
val = mas_prev_range(&mas, 0);
if (val == &prepend_mod)
- mas_store(&mas, NULL);
+ mas_erase(&mas);
out:
mas_unlock(&mas);
}
--
2.56.1.987.g2ec0ab4260-goog
next prev parent reply other threads:[~2026-12-04 1:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 1:56 [PATCH 0/3] alloc_tag: fixes for module tag area handling and the show_mem() report Suren Baghdasaryan
2026-12-04 1:56 ` [PATCH 1/3] alloc_tag: preserve the error when reserving a module tag area fails Suren Baghdasaryan
2026-12-04 2:06 ` Liam R. Howlett
2026-12-04 1:56 ` Suren Baghdasaryan [this message]
2026-12-04 2:29 ` [PATCH 2/3] alloc_tag: do not leak module tag areas when removing them fails Liam R. Howlett
2026-12-04 1:56 ` [PATCH 3/3] mm/show_mem: avoid unsafe locking when reporting allocation profiling Suren Baghdasaryan
2026-12-04 2:48 ` Liam R. Howlett
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=20261204015630.4095988-3-surenb@google.com \
--to=surenb@google.com \
--cc=akpm@linux-foundation.org \
--cc=bigeasy@linutronix.de \
--cc=brendan.jackman@linux.dev \
--cc=clrkwllms@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hao.ge@linux.dev \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=pasha.tatashin@soleen.com \
--cc=pyyjason@gmail.com \
--cc=rostedt@goodmis.org \
--cc=usamaarif642@gmail.com \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.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