Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/20240601233840.617458-1-surenb@google.com
Fixes: cc92eba1c88b ("mm: fix non-compound multi-order memory accounting in __free_pages")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202405271029.6d2f9c4c-lkp@intel.com
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Kees Cook <keescook@chromium.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Suren Baghdasaryan and committed by
Andrew Morton
a273559e c944bf60

+8 -3
+8 -3
include/linux/pgalloc_tag.h
··· 37 37 38 38 static inline void put_page_tag_ref(union codetag_ref *ref) 39 39 { 40 + if (WARN_ON(!ref)) 41 + return; 42 + 40 43 page_ext_put(page_ext_from_codetag_ref(ref)); 41 44 } 42 45 ··· 105 102 union codetag_ref *ref = get_page_tag_ref(page); 106 103 107 104 alloc_tag_sub_check(ref); 108 - if (ref && ref->ct) 109 - tag = ct_to_alloc_tag(ref->ct); 110 - put_page_tag_ref(ref); 105 + if (ref) { 106 + if (ref->ct) 107 + tag = ct_to_alloc_tag(ref->ct); 108 + put_page_tag_ref(ref); 109 + } 111 110 } 112 111 113 112 return tag;