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.

alloc_tag: add sequence number for module and iterator

Codetag iterator use <id,address> pair to guarantee the validness. But
both id and address can be reused, there is theoretical possibility when
module inserted right after another module removed, kmalloc returns an
address same as the address kfree by previous module and IDR key reuses
the key recently removed.

Add a sequence number to codetag_module and code_iterator, the sequence
number is strickly incremented whenever a module is loaded. An iterator
is valid if and only if its sequence number match codetag_module's.

Link: https://lkml.kernel.org/r/20250609064200.112639-1-00107082@163.com
Signed-off-by: David Wang <00107082@163.com>
Acked-by: Suren Baghdasaryan <surenb@google.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Wang and committed by
Andrew Morton
b0da7709 a03db236

+15 -3
+1
include/linux/codetag.h
··· 54 54 struct codetag_module *cmod; 55 55 unsigned long mod_id; 56 56 struct codetag *ct; 57 + unsigned long mod_seq; 57 58 }; 58 59 59 60 #ifdef MODULE
+14 -3
lib/codetag.c
··· 11 11 struct list_head link; 12 12 unsigned int count; 13 13 struct idr mod_idr; 14 - struct rw_semaphore mod_lock; /* protects mod_idr */ 14 + /* 15 + * protects mod_idr, next_mod_seq, 16 + * iter->mod_seq and cmod->mod_seq 17 + */ 18 + struct rw_semaphore mod_lock; 15 19 struct codetag_type_desc desc; 20 + /* generates unique sequence number for module load */ 21 + unsigned long next_mod_seq; 16 22 }; 17 23 18 24 struct codetag_range { ··· 29 23 struct codetag_module { 30 24 struct module *mod; 31 25 struct codetag_range range; 26 + unsigned long mod_seq; 32 27 }; 33 28 34 29 static DEFINE_MUTEX(codetag_lock); ··· 55 48 .cmod = NULL, 56 49 .mod_id = 0, 57 50 .ct = NULL, 51 + .mod_seq = 0, 58 52 }; 59 53 60 54 return iter; ··· 99 91 if (!cmod) 100 92 break; 101 93 102 - if (cmod != iter->cmod) { 94 + if (!iter->cmod || iter->mod_seq != cmod->mod_seq) { 103 95 iter->cmod = cmod; 96 + iter->mod_seq = cmod->mod_seq; 104 97 ct = get_first_module_ct(cmod); 105 - } else 98 + } else { 106 99 ct = get_next_module_ct(iter); 100 + } 107 101 108 102 if (ct) 109 103 break; ··· 201 191 cmod->range = range; 202 192 203 193 down_write(&cttype->mod_lock); 194 + cmod->mod_seq = ++cttype->next_mod_seq; 204 195 mod_id = idr_alloc(&cttype->mod_idr, cmod, 0, 0, GFP_KERNEL); 205 196 if (mod_id >= 0) { 206 197 if (cttype->desc.module_load) {