All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86: panasonic-laptop: fix NULL dereference
@ 2024-03-28 10:35 Maxim Korotkov
  2024-03-28 21:53 ` Kuppuswamy Sathyanarayanan
  2024-03-29  0:21 ` Armin Wolf
  0 siblings, 2 replies; 6+ messages in thread
From: Maxim Korotkov @ 2024-03-28 10:35 UTC (permalink / raw)
  To: Kenneth Chan
  Cc: Maxim Korotkov, Len Brown, Henrique de Moraes Holschuh,
	Harald Welte, Matthew Garrett, Ivan Kapranov, lvc-project,
	platform-driver-x86, linux-kernel

When initializing the pcc by calling acpi_driver_data(), the "device"
pointer was dereferenced without checking for NULL. This seems like
a logical mistake.

Added a pointer check to ensure that it is valid
before using it for pcc initialization.

Found by Security Code and Linux Verification Center(linuxtesting.org)

Fixes: 709ee531c153 ("panasonic-laptop: add Panasonic Let's Note laptop extras driver v0.94")

Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
---
 drivers/platform/x86/panasonic-laptop.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index cf845ee1c7b1..de29758b0384 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -1067,9 +1067,12 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 
 static void acpi_pcc_hotkey_remove(struct acpi_device *device)
 {
-	struct pcc_acpi *pcc = acpi_driver_data(device);
+	struct pcc_acpi *pcc;
 
-	if (!device || !pcc)
+	if (!device)
+		return;
+	pcc = acpi_driver_data(device);
+	if (!pcc)
 		return;
 
 	i8042_remove_filter(panasonic_i8042_filter);
-- 
2.34.1


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

* Re: [PATCH] platform/x86: panasonic-laptop: fix NULL dereference
  2024-03-28 10:35 [PATCH] platform/x86: panasonic-laptop: fix NULL dereference Maxim Korotkov
@ 2024-03-28 21:53 ` Kuppuswamy Sathyanarayanan
  2024-03-29  0:21 ` Armin Wolf
  1 sibling, 0 replies; 6+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2024-03-28 21:53 UTC (permalink / raw)
  To: Maxim Korotkov, Kenneth Chan
  Cc: Len Brown, Henrique de Moraes Holschuh, Harald Welte,
	Matthew Garrett, Ivan Kapranov, lvc-project, platform-driver-x86,
	linux-kernel


On 3/28/24 3:35 AM, Maxim Korotkov wrote:
> When initializing the pcc by calling acpi_driver_data(), the "device"
> pointer was dereferenced without checking for NULL. This seems like
> a logical mistake.
>
> Added a pointer check to ensure that it is valid
> before using it for pcc initialization.
>
> Found by Security Code and Linux Verification Center(linuxtesting.org)
>
> Fixes: 709ee531c153 ("panasonic-laptop: add Panasonic Let's Note laptop extras driver v0.94")

Since this is a remove function within kernel, is there any change for
device being NULL?

> Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
> ---
>  drivers/platform/x86/panasonic-laptop.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
> index cf845ee1c7b1..de29758b0384 100644
> --- a/drivers/platform/x86/panasonic-laptop.c
> +++ b/drivers/platform/x86/panasonic-laptop.c
> @@ -1067,9 +1067,12 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
>  
>  static void acpi_pcc_hotkey_remove(struct acpi_device *device)
>  {
> -	struct pcc_acpi *pcc = acpi_driver_data(device);
> +	struct pcc_acpi *pcc;
>  
> -	if (!device || !pcc)
> +	if (!device)
> +		return;
> +	pcc = acpi_driver_data(device);
> +	if (!pcc)
>  		return;
>  
>  	i8042_remove_filter(panasonic_i8042_filter);

-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer


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

* Re: [PATCH] platform/x86: panasonic-laptop: fix NULL dereference
  2024-03-28 10:35 [PATCH] platform/x86: panasonic-laptop: fix NULL dereference Maxim Korotkov
  2024-03-28 21:53 ` Kuppuswamy Sathyanarayanan
@ 2024-03-29  0:21 ` Armin Wolf
  2024-03-29  8:20   ` Maxim Korotkov
  1 sibling, 1 reply; 6+ messages in thread
From: Armin Wolf @ 2024-03-29  0:21 UTC (permalink / raw)
  To: Maxim Korotkov, Kenneth Chan
  Cc: Len Brown, Henrique de Moraes Holschuh, Harald Welte,
	Matthew Garrett, Ivan Kapranov, lvc-project, platform-driver-x86,
	linux-kernel

Am 28.03.24 um 11:35 schrieb Maxim Korotkov:

> When initializing the pcc by calling acpi_driver_data(), the "device"
> pointer was dereferenced without checking for NULL. This seems like
> a logical mistake.
>
> Added a pointer check to ensure that it is valid
> before using it for pcc initialization.

Hi,

is this check even needed? I think the ACPI driver core takes care
of passing a valid ACPI device pointer to acpi_pcc_hotkey_remove().

Thanks,
Armin Wolf

> Found by Security Code and Linux Verification Center(linuxtesting.org)
>
> Fixes: 709ee531c153 ("panasonic-laptop: add Panasonic Let's Note laptop extras driver v0.94")
>
> Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
> ---
>   drivers/platform/x86/panasonic-laptop.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
> index cf845ee1c7b1..de29758b0384 100644
> --- a/drivers/platform/x86/panasonic-laptop.c
> +++ b/drivers/platform/x86/panasonic-laptop.c
> @@ -1067,9 +1067,12 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
>
>   static void acpi_pcc_hotkey_remove(struct acpi_device *device)
>   {
> -	struct pcc_acpi *pcc = acpi_driver_data(device);
> +	struct pcc_acpi *pcc;
>
> -	if (!device || !pcc)
> +	if (!device)
> +		return;
> +	pcc = acpi_driver_data(device);
> +	if (!pcc)
>   		return;
>
>   	i8042_remove_filter(panasonic_i8042_filter);

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

* Re: [PATCH] platform/x86: panasonic-laptop: fix NULL dereference
  2024-03-29  0:21 ` Armin Wolf
@ 2024-03-29  8:20   ` Maxim Korotkov
  2024-03-29 18:44     ` Kuppuswamy Sathyanarayanan
  2024-04-02 12:36     ` Ilpo Järvinen
  0 siblings, 2 replies; 6+ messages in thread
From: Maxim Korotkov @ 2024-03-29  8:20 UTC (permalink / raw)
  To: Armin Wolf, Kenneth Chan, Kuppuswamy Sathyanarayanan
  Cc: Len Brown, Henrique de Moraes Holschuh, Harald Welte,
	Matthew Garrett, Ivan Kapranov, lvc-project, platform-driver-x86,
	linux-kernel

Hi,
On 29.03.2024 03:21, Armin Wolf wrote:
>> Added a pointer check to ensure that it is valid
>> before using it for pcc initialization.
> 
> Hi,
> 
> is this check even needed? I think the ACPI driver core takes care
> of passing a valid ACPI device pointer to acpi_pcc_hotkey_remove().
> 
> Thanks,
> Armin Wolf

I proceeded from the assumption that the current check was not redundant.
Kuppuswamy correctly noted in the message that the device would most 
likely be valid for the function of removal.

However, in my opinion, checking for NULL is a good coding practice, and 
has now been implemented incorrectly in this case.

Eliminating NULL checks could potentially cause bugs in this context.

Best regards, Max

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

* Re: [PATCH] platform/x86: panasonic-laptop: fix NULL dereference
  2024-03-29  8:20   ` Maxim Korotkov
@ 2024-03-29 18:44     ` Kuppuswamy Sathyanarayanan
  2024-04-02 12:36     ` Ilpo Järvinen
  1 sibling, 0 replies; 6+ messages in thread
From: Kuppuswamy Sathyanarayanan @ 2024-03-29 18:44 UTC (permalink / raw)
  To: Maxim Korotkov, Armin Wolf, Kenneth Chan
  Cc: Len Brown, Henrique de Moraes Holschuh, Harald Welte,
	Matthew Garrett, Ivan Kapranov, lvc-project, platform-driver-x86,
	linux-kernel


On 3/29/24 1:20 AM, Maxim Korotkov wrote:
> Hi,
> On 29.03.2024 03:21, Armin Wolf wrote:
>>> Added a pointer check to ensure that it is valid
>>> before using it for pcc initialization.
>>
>> Hi,
>>
>> is this check even needed? I think the ACPI driver core takes care
>> of passing a valid ACPI device pointer to acpi_pcc_hotkey_remove().
>>
>> Thanks,
>> Armin Wolf
>
> I proceeded from the assumption that the current check was not redundant.
> Kuppuswamy correctly noted in the message that the device would most likely be valid for the function of removal.
>
> However, in my opinion, checking for NULL is a good coding practice, and has now been implemented incorrectly in this case.
>
> Eliminating NULL checks could potentially cause bugs in this context.

Usually such checks are added when dealing with input that can change dynamically (like user input).

Since, as per the current usage, there is no chance for this device to be NULL, I don't think we need it.

>
> Best regards, Max

-- 
Sathyanarayanan Kuppuswamy
Linux Kernel Developer


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

* Re: [PATCH] platform/x86: panasonic-laptop: fix NULL dereference
  2024-03-29  8:20   ` Maxim Korotkov
  2024-03-29 18:44     ` Kuppuswamy Sathyanarayanan
@ 2024-04-02 12:36     ` Ilpo Järvinen
  1 sibling, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2024-04-02 12:36 UTC (permalink / raw)
  To: Maxim Korotkov
  Cc: Armin Wolf, Kenneth Chan, Kuppuswamy Sathyanarayanan, Len Brown,
	Henrique de Moraes Holschuh, Harald Welte, Matthew Garrett,
	Ivan Kapranov, lvc-project, platform-driver-x86, LKML

On Fri, 29 Mar 2024, Maxim Korotkov wrote:
> On 29.03.2024 03:21, Armin Wolf wrote:
> > > Added a pointer check to ensure that it is valid
> > > before using it for pcc initialization.
> > 
> > is this check even needed? I think the ACPI driver core takes care
> > of passing a valid ACPI device pointer to acpi_pcc_hotkey_remove().
> 
> I proceeded from the assumption that the current check was not redundant.
> Kuppuswamy correctly noted in the message that the device would most likely be
> valid for the function of removal.
> 
> However, in my opinion, checking for NULL is a good coding practice, and has
> now been implemented incorrectly in this case.
> 
> Eliminating NULL checks could potentially cause bugs in this context.

Hi,

If you're going to be submitting patches based on some automated tool 
which finds "bugs" in kernel, you need to be ready to go through the hoops 
of the review process and not just assume the patches are good as is.

We do not do pointless NULL checks in the kernel, this is not a matter of 
opinion. If there are unnecessary NULL checks, they should to be 
eventually removed (and definitely not used as an excuse to add more).

If the NULL check is not required as was implied to you by the reviewers, 
the correct response is to go check that the what the reviewers pointed 
out is true and _adapt_ the patch based on that. Then send a v2 of the 
patch. It how the kernel development process works. You might sometimes 
find the reviewers are wrong too, if that happens you can come back and 
point out why the patch is correct.

Either removing that check adds a bug or it doesn't. Not "potentially" 
which is just an excuse for not wanting to figure it out from the code.
It takes time and significant effort, I know, but spending time is 
required if you want to participate in the kernel development.

-- 
 i.


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

end of thread, other threads:[~2024-04-02 12:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 10:35 [PATCH] platform/x86: panasonic-laptop: fix NULL dereference Maxim Korotkov
2024-03-28 21:53 ` Kuppuswamy Sathyanarayanan
2024-03-29  0:21 ` Armin Wolf
2024-03-29  8:20   ` Maxim Korotkov
2024-03-29 18:44     ` Kuppuswamy Sathyanarayanan
2024-04-02 12:36     ` Ilpo Järvinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.