diff options
| author | Christian Brauner <brauner@kernel.org> | 2025-06-12 16:25:19 +0300 | 
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2025-06-16 18:01:22 +0300 | 
| commit | 0da3e3822cfabf062945e449f91ea3ca529eeaa4 (patch) | |
| tree | c9c72d541b60f9b9a84b354af39371aa85daa2a9 /drivers/base/firmware_loader/main.c | |
| parent | 3a2c977c463c68bf6fcd0138d15efa5f3adc743c (diff) | |
| download | linux-0da3e3822cfabf062945e449f91ea3ca529eeaa4.tar.xz | |
fs: move name_contains_dotdot() to header
Move the helper from the firmware specific code to a header so we can
reuse it for coredump sockets.
Link: https://lore.kernel.org/20250612-work-coredump-massage-v1-5-315c0c34ba94@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'drivers/base/firmware_loader/main.c')
| -rw-r--r-- | drivers/base/firmware_loader/main.c | 31 | 
1 files changed, 11 insertions, 20 deletions
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index 44486b2c7172..6942c62fa59d 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -822,26 +822,6 @@ static void fw_log_firmware_info(const struct firmware *fw, const char *name,  {}  #endif -/* - * Reject firmware file names with ".." path components. - * There are drivers that construct firmware file names from device-supplied - * strings, and we don't want some device to be able to tell us "I would like to - * be sent my firmware from ../../../etc/shadow, please". - * - * Search for ".." surrounded by either '/' or start/end of string. - * - * This intentionally only looks at the firmware name, not at the firmware base - * directory or at symlink contents. - */ -static bool name_contains_dotdot(const char *name) -{ -	size_t name_len = strlen(name); - -	return strcmp(name, "..") == 0 || strncmp(name, "../", 3) == 0 || -	       strstr(name, "/../") != NULL || -	       (name_len >= 3 && strcmp(name+name_len-3, "/..") == 0); -} -  /* called from request_firmware() and request_firmware_work_func() */  static int  _request_firmware(const struct firmware **firmware_p, const char *name, @@ -862,6 +842,17 @@ _request_firmware(const struct firmware **firmware_p, const char *name,  		goto out;  	} + +	/* +	 * Reject firmware file names with ".." path components. +	 * There are drivers that construct firmware file names from +	 * device-supplied strings, and we don't want some device to be +	 * able to tell us "I would like to be sent my firmware from +	 * ../../../etc/shadow, please". +	 * +	 * This intentionally only looks at the firmware name, not at +	 * the firmware base directory or at symlink contents. +	 */  	if (name_contains_dotdot(name)) {  		dev_warn(device,  			 "Firmware load for '%s' refused, path contains '..' component\n",  | 
