LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH][RFC] platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning
@ 2021-08-25 16:07 Kees Cook
2021-08-25 16:32 ` Andy Shevchenko
2021-08-26 13:57 ` Hans de Goede
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2021-08-25 16:07 UTC (permalink / raw)
To: Hans de Goede
Cc: Kees Cook, Mark Gross, Mario Limonciello, Pali Rohár,
Andy Shevchenko, Uwe Kleine-König, Dell.Client.Kernel,
platform-driver-x86, Andy Lavr, linux-kernel, linux-hardening
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 <hdegoede@redhat.com>
Cc: Mark Gross <mgross@linux.intel.com>
Cc: Mario Limonciello <mario.limonciello@dell.com>
Cc: "Pali Rohár" <pali@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Dell.Client.Kernel@dell.com
Cc: platform-driver-x86@vger.kernel.org
Reported-by: Andy Lavr <andy.lavr@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/platform/x86/dell/dell-smbios-wmi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/dell/dell-smbios-wmi.c b/drivers/platform/x86/dell/dell-smbios-wmi.c
index 33f823772733..c410d6d920b8 100644
--- a/drivers/platform/x86/dell/dell-smbios-wmi.c
+++ b/drivers/platform/x86/dell/dell-smbios-wmi.c
@@ -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]);
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][RFC] platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning
2021-08-25 16:07 [PATCH][RFC] platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning Kees Cook
@ 2021-08-25 16:32 ` Andy Shevchenko
2021-08-26 13:57 ` Hans de Goede
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-08-25 16:32 UTC (permalink / raw)
To: Kees Cook
Cc: Hans de Goede, Mark Gross, Mario Limonciello, Pali Rohár,
Uwe Kleine-König, Dell.Client.Kernel, platform-driver-x86,
Andy Lavr, linux-kernel, linux-hardening
On Wed, Aug 25, 2021 at 09:07:49AM -0700, Kees Cook wrote:
> 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?
Seems so.
* Note: The caller should use acpi_os_free to free this
* buffer created via ACPI_ALLOCATE_BUFFER.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][RFC] platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning
2021-08-25 16:07 [PATCH][RFC] platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning Kees Cook
2021-08-25 16:32 ` Andy Shevchenko
@ 2021-08-26 13:57 ` Hans de Goede
1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2021-08-26 13:57 UTC (permalink / raw)
To: Kees Cook
Cc: Mark Gross, Mario Limonciello, Pali Rohár, Andy Shevchenko,
Uwe Kleine-König, Dell.Client.Kernel, platform-driver-x86,
Andy Lavr, linux-kernel, linux-hardening
Hi,
On 8/25/21 6:07 PM, Kees Cook wrote:
> 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 <hdegoede@redhat.com>
> Cc: Mark Gross <mgross@linux.intel.com>
> Cc: Mario Limonciello <mario.limonciello@dell.com>
> Cc: "Pali Rohár" <pali@kernel.org>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
> Cc: Dell.Client.Kernel@dell.com
> Cc: platform-driver-x86@vger.kernel.org
> Reported-by: Andy Lavr <andy.lavr@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
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
> ---
> drivers/platform/x86/dell/dell-smbios-wmi.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/dell/dell-smbios-wmi.c b/drivers/platform/x86/dell/dell-smbios-wmi.c
> index 33f823772733..c410d6d920b8 100644
> --- a/drivers/platform/x86/dell/dell-smbios-wmi.c
> +++ b/drivers/platform/x86/dell/dell-smbios-wmi.c
> @@ -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]);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-26 13:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 16:07 [PATCH][RFC] platform/x86: dell-smbios-wmi: Avoid false-positive memcpy() warning Kees Cook
2021-08-25 16:32 ` Andy Shevchenko
2021-08-26 13:57 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).