linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence
@ 2021-09-20  9:55 Arnd Bergmann
  2021-09-20 17:45 ` Mark Gross
  2021-09-21 10:12 ` Hans de Goede
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-09-20  9:55 UTC (permalink / raw)
  To: Matan Ziv-Av, Hans de Goede, Mark Gross
  Cc: Arnd Bergmann, Rafael J. Wysocki, platform-driver-x86, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

When CONFIG_DMI is disabled, dmi_get_system_info() returns a NULL
pointer, which is now caught by a warning:

In function 'strlen',
    inlined from 'acpi_add.part.0' at drivers/platform/x86/lg-laptop.c:658:6:
include/linux/fortify-string.h:25:33: error: argument 1 null where non-null expected [-Werror=nonnull]
   25 | #define __underlying_strlen     __builtin_strlen
      |                                 ^
include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
   60 |                 return __underlying_strlen(p);
      |                        ^~~~~~~~~~~~~~~~~~~
drivers/platform/x86/lg-laptop.c: In function 'acpi_add.part.0':
include/linux/fortify-string.h:25:33: note: in a call to built-in function '__builtin_strlen'
   25 | #define __underlying_strlen     __builtin_strlen
      |                                 ^
include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
   60 |                 return __underlying_strlen(p);
      |                        ^~~~~~~~~~~~~~~~~~~

The code in there does not appear essential, so an explicit
NULL check should be sufficient. The string is also printed
to the console, but printk() is able to handle NULL pointer
arguments gracefully.

Fixes: 8983bfd58d61 ("platform/x86: lg-laptop: Support for battery charge limit on newer models")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/platform/x86/lg-laptop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index 3e520d5bca07..88b551caeaaf 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -655,7 +655,7 @@ static int acpi_add(struct acpi_device *device)
 		goto out_platform_registered;
 	}
 	product = dmi_get_system_info(DMI_PRODUCT_NAME);
-	if (strlen(product) > 4)
+	if (product && strlen(product) > 4)
 		switch (product[4]) {
 		case '5':
 		case '6':
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence
  2021-09-20  9:55 [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence Arnd Bergmann
@ 2021-09-20 17:45 ` Mark Gross
  2021-09-21 10:12 ` Hans de Goede
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Gross @ 2021-09-20 17:45 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Matan Ziv-Av, Hans de Goede, Mark Gross, Arnd Bergmann,
	Rafael J. Wysocki, platform-driver-x86, linux-kernel

On Mon, Sep 20, 2021 at 11:55:50AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> When CONFIG_DMI is disabled, dmi_get_system_info() returns a NULL
> pointer, which is now caught by a warning:
> 
> In function 'strlen',
>     inlined from 'acpi_add.part.0' at drivers/platform/x86/lg-laptop.c:658:6:
> include/linux/fortify-string.h:25:33: error: argument 1 null where non-null expected [-Werror=nonnull]
>    25 | #define __underlying_strlen     __builtin_strlen
>       |                                 ^
> include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
>    60 |                 return __underlying_strlen(p);
>       |                        ^~~~~~~~~~~~~~~~~~~
> drivers/platform/x86/lg-laptop.c: In function 'acpi_add.part.0':
> include/linux/fortify-string.h:25:33: note: in a call to built-in function '__builtin_strlen'
>    25 | #define __underlying_strlen     __builtin_strlen
>       |                                 ^
> include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
>    60 |                 return __underlying_strlen(p);
>       |                        ^~~~~~~~~~~~~~~~~~~
> 
> The code in there does not appear essential, so an explicit
> NULL check should be sufficient. The string is also printed
> to the console, but printk() is able to handle NULL pointer
> arguments gracefully.
> 
> Fixes: 8983bfd58d61 ("platform/x86: lg-laptop: Support for battery charge limit on newer models")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/platform/x86/lg-laptop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
> index 3e520d5bca07..88b551caeaaf 100644
> --- a/drivers/platform/x86/lg-laptop.c
> +++ b/drivers/platform/x86/lg-laptop.c
> @@ -655,7 +655,7 @@ static int acpi_add(struct acpi_device *device)
>  		goto out_platform_registered;
>  	}
>  	product = dmi_get_system_info(DMI_PRODUCT_NAME);
> -	if (strlen(product) > 4)
> +	if (product && strlen(product) > 4)
seems appropriate.

--mark
>  		switch (product[4]) {
>  		case '5':
>  		case '6':
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence
  2021-09-20  9:55 [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence Arnd Bergmann
  2021-09-20 17:45 ` Mark Gross
@ 2021-09-21 10:12 ` Hans de Goede
  1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2021-09-21 10:12 UTC (permalink / raw)
  To: Arnd Bergmann, Matan Ziv-Av, Mark Gross
  Cc: Arnd Bergmann, Rafael J. Wysocki, platform-driver-x86, linux-kernel

Hi Arnd,

On 9/20/21 11:55 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> When CONFIG_DMI is disabled, dmi_get_system_info() returns a NULL
> pointer, which is now caught by a warning:
> 
> In function 'strlen',
>     inlined from 'acpi_add.part.0' at drivers/platform/x86/lg-laptop.c:658:6:
> include/linux/fortify-string.h:25:33: error: argument 1 null where non-null expected [-Werror=nonnull]
>    25 | #define __underlying_strlen     __builtin_strlen
>       |                                 ^
> include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
>    60 |                 return __underlying_strlen(p);
>       |                        ^~~~~~~~~~~~~~~~~~~
> drivers/platform/x86/lg-laptop.c: In function 'acpi_add.part.0':
> include/linux/fortify-string.h:25:33: note: in a call to built-in function '__builtin_strlen'
>    25 | #define __underlying_strlen     __builtin_strlen
>       |                                 ^
> include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
>    60 |                 return __underlying_strlen(p);
>       |                        ^~~~~~~~~~~~~~~~~~~
> 
> The code in there does not appear essential, so an explicit
> NULL check should be sufficient. The string is also printed
> to the console, but printk() is able to handle NULL pointer
> arguments gracefully.
> 
> Fixes: 8983bfd58d61 ("platform/x86: lg-laptop: Support for battery charge limit on newer models")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thank you for the patch, but this is already fixed in the pdx86 fixes branch:

https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/commit/?h=fixes&id=4c4a3d7cffb42da21ea8891fc7e6808ae05dbcb5

Regards,

Hans


> ---
>  drivers/platform/x86/lg-laptop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
> index 3e520d5bca07..88b551caeaaf 100644
> --- a/drivers/platform/x86/lg-laptop.c
> +++ b/drivers/platform/x86/lg-laptop.c
> @@ -655,7 +655,7 @@ static int acpi_add(struct acpi_device *device)
>  		goto out_platform_registered;
>  	}
>  	product = dmi_get_system_info(DMI_PRODUCT_NAME);
> -	if (strlen(product) > 4)
> +	if (product && strlen(product) > 4)
>  		switch (product[4]) {
>  		case '5':
>  		case '6':
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-21 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20  9:55 [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence Arnd Bergmann
2021-09-20 17:45 ` Mark Gross
2021-09-21 10:12 ` 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).