Skip to content

Commit a273559

Browse files
surenbaghdasaryanakpm00
authored andcommitted
lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get()
put_page_tag_ref() should be called only when get_page_tag_ref() returns a valid reference because only in that case get_page_tag_ref() enters RCU read section while put_page_tag_ref() will call rcu_read_unlock() even if the provided reference is NULL. Fix pgalloc_tag_get() which does not follow this rule causing RCU imbalance. Add a warning in put_page_tag_ref() to catch any future mistakes. Link: https://lkml.kernel.org/r/[email protected] Fixes: cc92eba ("mm: fix non-compound multi-order memory accounting in __free_pages") Signed-off-by: Suren Baghdasaryan <[email protected]> Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Acked-by: Vlastimil Babka <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Pasha Tatashin <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c944bf6 commit a273559

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

include/linux/pgalloc_tag.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static inline union codetag_ref *get_page_tag_ref(struct page *page)
3737

3838
static inline void put_page_tag_ref(union codetag_ref *ref)
3939
{
40+
if (WARN_ON(!ref))
41+
return;
42+
4043
page_ext_put(page_ext_from_codetag_ref(ref));
4144
}
4245

@@ -102,9 +105,11 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page)
102105
union codetag_ref *ref = get_page_tag_ref(page);
103106

104107
alloc_tag_sub_check(ref);
105-
if (ref && ref->ct)
106-
tag = ct_to_alloc_tag(ref->ct);
107-
put_page_tag_ref(ref);
108+
if (ref) {
109+
if (ref->ct)
110+
tag = ct_to_alloc_tag(ref->ct);
111+
put_page_tag_ref(ref);
112+
}
108113
}
109114

110115
return tag;

0 commit comments

Comments
 (0)