Skip to contentSkip to conversation

of: module: harden a call to request_module

PATCH In review Dmitriy Okunev 2 participants 2 messages Sep 14 – Sep 16 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: module: harden a call to request_module

In of_request_module(), the string 'str' is built from Device Tree data and passed directly to request_module() as a format string. While the Device Tree is generally considered trusted, using externally provided data as a format string is fragile and can lead to unintended format specifier interpretation.

Fix this by using request_module("%s", str) to treat 'str' as a plain string argument, not a format string.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 9c829c097f2f1 ("of: device: Support loading a module with OF based modalias")
---
 drivers/of/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/module.c +1 -1
index 1e735fc130ad..592377603c24 100644
@@ -73,7 +73,7 @@ int of_request_module(const struct device_node *np)
 
 	of_modalias(np, str, size);
 	str[size - 1] = '\0';
-	ret = request_module(str);
+	ret = request_module("%s", str);
 	kfree(str);
 
 	return ret;
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 8 lines · Dmitriy Okunev

In of_request_module(), the string 'str' is built from Device Tree data and passed directly to request_module() as a format string. While the Device Tree is generally considered trusted, using externally provided data as a format string is fragile and can lead to unintended format specifier interpretation.

Fix this by using request_module("%s", str) to treat 'str' as a plain string argument, not a format string.

'%' is not a legal character in DT node names. Even if someone modified a DT to have one, would we even get to this point. Probably unflattening or creating sysfs files would fail first.

Rob