Skip to contentSkip to conversation

platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning

RFC PATCH In review Kees Cook 3 participants 3 messages Aug 25, 2021 – Aug 26, 2021

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

RFC PATCH 1/1 platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields.

Since all the size checking has already happened, use input.pointer (void *) so memcpy() doesn't get confused about how much is being written.

Avoids this false-positive warning when run-time memcpy() strict bounds checking is enabled:

memcpy: detected field-spanning write (size 4096) of single field (size 36)

WARNING: CPU: 0 PID: 357 at drivers/platform/x86/dell/dell-smbios-wmi.c:74 run_smbios_call+0x110/0x1e0 [dell_smbios]

Note: is there a missed kfree() in the marked error path?

Cc Hans de Goede <[email protected]>
Cc Mark Gross <[email protected]>
Cc Mario Limonciello <[email protected]>
Cc "Pali Rohár" <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc "Uwe Kleine-König" <[email protected]>
---
 drivers/platform/x86/dell/dell-smbios-wmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/dell/dell-smbios-wmi.c +2 -1
index 33f823772733..c410d6d920b8 100644
@@ -69,9 +69,10 @@ static int run_smbios_call(struct wmi_device *wdev)
 		if (obj->type == ACPI_TYPE_INTEGER)
 			dev_dbg(&wdev->dev, "SMBIOS call failed: %llu\n",
 				obj->integer.value);
+		/* output.pointer memory allocation leak? */
 		return -EIO;
 	}
-	memcpy(&priv->buf->std, obj->buffer.pointer, obj->buffer.length);
+	memcpy(input.pointer, obj->buffer.pointer, obj->buffer.length);
 	dev_dbg(&wdev->dev, "result: [%08x,%08x,%08x,%08x]\n",
 		priv->buf->std.output[0], priv->buf->std.output[1],
 		priv->buf->std.output[2], priv->buf->std.output[3]);
Signature · 1 line
2.30.2
#1 lore raw
Quoted 8 lines · Kees Cook

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields.

Since all the size checking has already happened, use input.pointer (void *) so memcpy() doesn't get confused about how much is being written.

Quoted 7 lines

Avoids this false-positive warning when run-time memcpy() strict bounds checking is enabled:

memcpy: detected field-spanning write (size 4096) of single field (size 36)

WARNING: CPU: 0 PID: 357 at drivers/platform/x86/dell/dell-smbios-wmi.c:74 run_smbios_call+0x110/0x1e0 [dell_smbios]

Note: is there a missed kfree() in the marked error path?

Seems so.

* Note: The caller should use acpi_os_free to free this
* buffer created via ACPI_ALLOCATE_BUFFER.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Kees Cook

Hi,

Quoted 16 lines · Kees Cook

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields.

Since all the size checking has already happened, use input.pointer (void *) so memcpy() doesn't get confused about how much is being written.

Avoids this false-positive warning when run-time memcpy() strict bounds checking is enabled:

memcpy: detected field-spanning write (size 4096) of single field (size 36)

WARNING: CPU: 0 PID: 357 at drivers/platform/x86/dell/dell-smbios-wmi.c:74 run_smbios_call+0x110/0x1e0 [dell_smbios]

Note: is there a missed kfree() in the marked error path?

Quoted 10 lines
Cc Hans de Goede <[email protected]>
Cc Mark Gross <[email protected]>
Cc Mario Limonciello <[email protected]>
Cc "Pali Rohár" <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc "Uwe Kleine-König" <[email protected]>

Thank you, I've applied the patch, minus the:

/* output.pointer memory allocation leak? */

Comment, instead I'll submit (and also apply right-away) a patch to add the missing kfree()

Regards,

Hans

Quoted 21 lines
---
 drivers/platform/x86/dell/dell-smbios-wmi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/dell/dell-smbios-wmi.c +2 -1
index 33f823772733..c410d6d920b8 100644
@@ -69,9 +69,10 @@ static int run_smbios_call(struct wmi_device *wdev)
 		if (obj->type == ACPI_TYPE_INTEGER)
 			dev_dbg(&wdev->dev, "SMBIOS call failed: %llu\n",
 				obj->integer.value);
+		/* output.pointer memory allocation leak? */
 		return -EIO;
 	}
-	memcpy(&priv->buf->std, obj->buffer.pointer, obj->buffer.length);
+	memcpy(input.pointer, obj->buffer.pointer, obj->buffer.length);
 	dev_dbg(&wdev->dev, "result: [%08x,%08x,%08x,%08x]\n",
 		priv->buf->std.output[0], priv->buf->std.output[1],
 		priv->buf->std.output[2], priv->buf->std.output[3]);