Skip to contentSkip to conversation

lib/vsprintf: Make no_hash_pointers take effect early

PATCH In review Kaitao Cheng 2 participants 3 messages Jun 18 – Jun 25

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

PATCH v3 1/1 lib/vsprintf: Make no_hash_pointers take effect early

From: Kaitao Cheng <[email protected]>

The no_hash_pointers boot parameter is now handled as an alias for hash_pointers=never. However, hash_pointers=never only records the selected mode during early parameter parsing, and no_hash_pointers is not updated until hash_pointers_finalize() runs later from SLUB init.

This leaves a window during very early boot where %p output is still hashed even though the user explicitly requested unhashed pointers with no_hash_pointers or hash_pointers=never.

Set no_hash_pointers as soon as the "never" mode is parsed. The later hash_pointers_finalize() call still keeps the final policy decision in one place, but explicit requests to disable pointer hashing now take effect for early boot users too.

---
Changes in v3 (Petr Mladek):
- Avoid stale no_hash_pointers state when hash_pointers overrides it.

Changes in v2 (Andy Shevchenko):
- Add a description of the kernel documentation to the commit log.

Link to v2:
https://lore.kernel.org/all/[email protected]/

Link to v1:
https://lore.kernel.org/all/[email protected]/

---
 lib/vsprintf.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/vsprintf.c +4 -0
index 4221e95701f9..ca2f12144152 100644
@@ -2352,6 +2352,9 @@ void __init hash_pointers_finalize(bool slub_debug)
 
 static int __init hash_pointers_mode_parse(char *str)
 {
+	/* Avoid stale no_hash_pointers state when hash_pointers overrides it */
+	no_hash_pointers = false;
+
 	if (!str) {
 		pr_warn("Hash pointers mode empty; falling back to auto.\n");
 		hash_pointers_mode = HASH_PTR_AUTO;
@@ -2361,6 +2364,7 @@ static int __init hash_pointers_mode_parse(char *str)
 	} else if (strcmp(str, "never") == 0) {
 		pr_info("Hash pointers mode set to never.\n");
 		hash_pointers_mode = HASH_PTR_NEVER;
+		no_hash_pointers = true;
 	} else if (strcmp(str, "always") == 0) {
 		pr_info("Hash pointers mode set to always.\n");
 		hash_pointers_mode = HASH_PTR_ALWAYS;
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

The no_hash_pointers boot parameter is now handled as an alias for hash_pointers=never. However, hash_pointers=never only records the selected mode during early parameter parsing, and no_hash_pointers is not updated until hash_pointers_finalize() runs later from SLUB init.

This leaves a window during very early boot where %p output is still hashed even though the user explicitly requested unhashed pointers with no_hash_pointers or hash_pointers=never.

Quoted 6 lines

Set no_hash_pointers as soon as the "never" mode is parsed. The later hash_pointers_finalize() call still keeps the final policy decision in one place, but explicit requests to disable pointer hashing now take effect for early boot users too.

LGTM, feel free to use:

I am going to queue it via printk git tree for 7.3. I have already sent printk changes for 7.2 and this does not look serious enough to create yet another pull request. I could still add it to a pull request for 7.2 if a more serious fix appeared.

Best Regards,
Petr

maintainer
#2 lore raw
In reply to Kaitao Cheng
Quoted 11 lines · Kaitao Cheng

From: Kaitao Cheng <[email protected]>

The no_hash_pointers boot parameter is now handled as an alias for hash_pointers=never. However, hash_pointers=never only records the selected mode during early parameter parsing, and no_hash_pointers is not updated until hash_pointers_finalize() runs later from SLUB init.

This leaves a window during very early boot where %p output is still hashed even though the user explicitly requested unhashed pointers with no_hash_pointers or hash_pointers=never.

Quoted 6 lines

Set no_hash_pointers as soon as the "never" mode is parsed. The later hash_pointers_finalize() call still keeps the final policy decision in one place, but explicit requests to disable pointer hashing now take effect for early boot users too.

JFYI, the patch has been pushed into printk/linux.git, branch for-7.3-trivial.

As the branch name suggests, it is intended for 7.3. But as a trivial change, I could add it to a pull request for some 7.2-rcX when I need to create one because of a more important fix.

Best Regards,
Petr