From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>, Hao Ge <hao.ge@linux.dev>,
Vlastimil Babka <vbabka@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
Usama Arif <usamaarif642@gmail.com>,
Shakeel Butt <shakeel.butt@linux.dev>,
Harry Yoo <harry@kernel.org>, Hao Li <hao.li@linux.dev>,
Christoph Lameter <cl@gentwo.org>,
David Rientjes <rientjes@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>
Cc: linux-mm@kvack.org, "David Hildenbrand (Arm)" <david@kernel.org>,
stable@vger.kernel.org, Chris Mason <mason@kernel.org>
Subject: [PATCH 1/3] alloc_tag: handle a NULL tag in alloc_tag_set_inaccurate()
Date: Thu, 19 Nov 2026 09:52:20 +0100 [thread overview]
Message-ID: <20261119-alloc_tag-v1-1-efcccfd3a9c9@kernel.org> (raw)
In-Reply-To: <20261119-alloc_tag-v1-0-efcccfd3a9c9@kernel.org>
With memory allocation profiling enabled after boot, a slab allocation
can dereference a NULL pointer if current->alloc_tag is not set and
allocating the slab object extensions fails:
__alloc_tagging_slab_alloc_hook() passes current->alloc_tag to
alloc_tag_set_inaccurate(), which does not handle a NULL tag currently.
One way to trigger it is through rhashtable: rhashtable_init() records
current->alloc_tag in ht->alloc_tag, which is NULL while profiling is
disabled. Once profiling gets enabled, alloc_hooks_tag() sets
current->alloc_tag to that NULL tag when allocating a bucket table.
Fix it by handling NULL tags in alloc_tag_set_inaccurate(), just
like alloc_tag_add() and alloc_tag_sub() already do, and drop the now
unnecessary check in __pgalloc_tag_add().
This has low urgency.
Fixes: b9e2f58ffb84 ("alloc_tag: mark inaccurate allocation counters in /proc/allocinfo output")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
include/linux/alloc_tag.h | 3 ++-
mm/page_alloc.c | 3 +--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h
index 7f2d80a597924..0f9909c6701a7 100644
--- a/include/linux/alloc_tag.h
+++ b/include/linux/alloc_tag.h
@@ -227,7 +227,8 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes)
static inline void alloc_tag_set_inaccurate(struct alloc_tag *tag)
{
- tag->ct.flags |= CODETAG_FLAG_INACCURATE;
+ if (tag)
+ tag->ct.flags |= CODETAG_FLAG_INACCURATE;
}
static inline bool alloc_tag_is_inaccurate(struct alloc_tag *tag)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2fef4092c913c..0b76923145456 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1262,8 +1262,7 @@ void __pgalloc_tag_add(struct page *page, struct task_struct *task,
* clear the tag ref later when page_ext is initialized.
*/
alloc_tag_add_early_pfn(page_to_pfn(page), alloc_flags);
- if (task->alloc_tag)
- alloc_tag_set_inaccurate(task->alloc_tag);
+ alloc_tag_set_inaccurate(task->alloc_tag);
}
}
--
2.56.1
prev parent reply other threads:[~2026-11-19 8:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:52 [PATCH 0/3] alloc_tag: two fixes and one cleanup David Hildenbrand (Arm)
2026-11-19 8:52 ` David Hildenbrand (Arm) [this message]
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=20261119-alloc_tag-v1-1-efcccfd3a9c9@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=cl@gentwo.org \
--cc=hannes@cmpxchg.org \
--cc=hao.ge@linux.dev \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=linux-mm@kvack.org \
--cc=mason@kernel.org \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--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