Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 1/3] alloc_tag: preserve the error when reserving a module tag area fails
Date: Thu,  3 Dec 2026 17:56:28 -0800	[thread overview]
Message-ID: <20261204015630.4095988-2-surenb@google.com> (raw)
In-Reply-To: <20261204015630.4095988-1-surenb@google.com>

When storing the module area fails after the padding in front of it was
stored, reserve_module_tags() removes the padding with mas_erase() and
only then reads the error from the maple state. mas_erase() walks the
tree and overrides the error stored in mas.node, therefore the correct
error code gets cleared and later treated as area reservation success.
This leaves the same memory area available for allocation to subsequent
modules, causing silent memory corruption of allocation tags.

Store the error before removing the padding.

Fixes: 0db6f8d7820a ("alloc_tag: load module tags into separate contiguous memory")
Closes: https://sashiko.dev/#/bug/linux-64e7eab3-9791-43b6-a55e-fc05f931983c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
 mm/alloc_tag.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/alloc_tag.c b/mm/alloc_tag.c
index 18bec85b6220..b4e55bbf57f6 100644
--- a/mm/alloc_tag.c
+++ b/mm/alloc_tag.c
@@ -1010,9 +1010,10 @@ static void *reserve_module_tags(struct module *mod, unsigned long size,
 		mas.last = offset + size - 1;
 		mas_store(&mas, mod);
 		if (mas_is_err(&mas)) {
+			/* mas_erase() resets the error in the maple state */
+			ret = ERR_PTR(xa_err(mas.node));
 			mas.index = pad_start;
 			mas_erase(&mas);
-			ret = ERR_PTR(xa_err(mas.node));
 		}
 	} else {
 		mas.last = offset + size - 1;
-- 
2.56.1.987.g2ec0ab4260-goog



  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 ` Suren Baghdasaryan [this message]
2026-12-04  2:06   ` [PATCH 1/3] alloc_tag: preserve the error when reserving a module tag area fails Liam R. Howlett
2026-12-04  1:56 ` [PATCH 2/3] alloc_tag: do not leak module tag areas when removing them fails Suren Baghdasaryan
2026-12-04  2:29   ` 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-2-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