Skip to contentSkip to conversation

sections: global data can be in .bss

PATCH Applied Antoine Tenart 4 participants 5 messages Nov 22, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---

A few remarks:

- This still targets net-next but I added Arnd if he prefers to take it through the 'asm-generic' tree, now that is_kernel_core_data is in include/asm-generic/.

- I kept the Acked-by tag as the change is the same really, the difference is the core_kernel_data function was renamed to is_kernel_core_data and moved since then.

- @Jonathon: with your analysis and suggestion I think you should be listed as a co-developer. If that's fine please say so, and reply with both a Co-developed-by and a Signed-off-by tags.

Since v1:
- Grouped the .data and .bss checks in the same function.

v1 was https://lore.kernel.org/all/[email protected]/T/

Thanks!
Antoine

 include/asm-generic/sections.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
include/asm-generic/sections.h +10 -4
index 1dfadb2e878d..76a0f16e56cf 100644
@@ -130,18 +130,24 @@ static inline bool init_section_intersects(void *virt, size_t size)
 
 /**
  * is_kernel_core_data - checks if the pointer address is located in the
- *			 .data section
+ *			 .data or .bss section
  *
  * @addr: address to check
  *
- * Returns: true if the address is located in .data, false otherwise.
+ * Returns: true if the address is located in .data or .bss, false otherwise.
  * Note: On some archs it may return true for core RODATA, and false
  *       for others. But will always be true for core RW data.
  */
 static inline bool is_kernel_core_data(unsigned long addr)
 {
-	return addr >= (unsigned long)_sdata &&
-	       addr < (unsigned long)_edata;
+	if (addr >= (unsigned long)_sdata && addr < (unsigned long)_edata)
+		return true;
+
+	if (addr >= (unsigned long)__bss_start &&
+	    addr < (unsigned long)__bss_stop)
+		return true;
+
+	return false;
 }
 
 /**
Signature · 1 line
2.33.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 11 lines · Antoine Tenart

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.

Quoted 7 lines

---

A few remarks:

- This still targets net-next but I added Arnd if he prefers to take it through the 'asm-generic' tree, now that is_kernel_core_data is in include/asm-generic/.

I have nothing else for asm-generic at the moment, please take this through net-next.

#2 lore raw
In reply to Antoine Tenart
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Mon, 22 Nov 2021 15:24:56 +0100 you wrote:

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.

[...]

Here is the summary with links:
- [net-next,v2] sections: global data can be in .bss

    https://git.kernel.org/netdev/net-next/c/cb902b332f95

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Antoine Tenart
Quoted 11 lines · Antoine Tenart

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.

Quoted 8 lines

---

A few remarks:

- This still targets net-next but I added Arnd if he prefers to take it through the 'asm-generic' tree, now that is_kernel_core_data is in include/asm-generic/.

Quoted 7 lines

- I kept the Acked-by tag as the change is the same really, the difference is the core_kernel_data function was renamed to is_kernel_core_data and moved since then.

- @Jonathon: with your analysis and suggestion I think you should be listed as a co-developer. If that's fine please say so, and reply with both a Co-developed-by and a Signed-off-by tags.

Added, thanks. Although it appears I may have missed the boat.

#4 lore raw

Quoting Jonathon Reinhart (2021-11-22 17:56:55)

Quoted 7 lines · Antoine Tenart
Quoted 4 lines

- @Jonathon: with your analysis and suggestion I think you should be listed as a co-developer. If that's fine please say so, and reply with both a Co-developed-by and a Signed-off-by tags.

Added, thanks. Although it appears I may have missed the boat.

Yes, the patch was applied quickly. Anyway, thanks for the investigation!

Antoine