Skip to content

Commit cb902b3

Browse files
atenartdavem330
authored andcommitted
sections: global data can be in .bss
When checking an address is located in a global data section also check for the .bss section as global variables initialized to 0 can be in there (-fzero-initialized-in-bss). This was found when looking at ensure_safe_net_sysctl which was failing to detect non-init sysctl pointing to a global data section when the data was in the .bss section. Signed-off-by: Antoine Tenart <[email protected]> Acked-by: Steven Rostedt (VMware) <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e968b1b commit cb902b3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

include/asm-generic/sections.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,24 @@ static inline bool init_section_intersects(void *virt, size_t size)
130130

131131
/**
132132
* is_kernel_core_data - checks if the pointer address is located in the
133-
* .data section
133+
* .data or .bss section
134134
*
135135
* @addr: address to check
136136
*
137-
* Returns: true if the address is located in .data, false otherwise.
137+
* Returns: true if the address is located in .data or .bss, false otherwise.
138138
* Note: On some archs it may return true for core RODATA, and false
139139
* for others. But will always be true for core RW data.
140140
*/
141141
static inline bool is_kernel_core_data(unsigned long addr)
142142
{
143-
return addr >= (unsigned long)_sdata &&
144-
addr < (unsigned long)_edata;
143+
if (addr >= (unsigned long)_sdata && addr < (unsigned long)_edata)
144+
return true;
145+
146+
if (addr >= (unsigned long)__bss_start &&
147+
addr < (unsigned long)__bss_stop)
148+
return true;
149+
150+
return false;
145151
}
146152

147153
/**

0 commit comments

Comments
 (0)