From: "Kurt Borja" <kuurtb@gmail.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
"Hans de Goede" <hdegoede@redhat.com>,
"Mark Pearson" <mpearson-lenovo@squebb.ca>,
<ibm-acpi-devel@lists.sourceforge.net>,
<platform-driver-x86@vger.kernel.org>,
"LKML" <linux-kernel@vger.kernel.org>,
<linux-riscv@lists.infradead.org>,
"Damian Tometzki" <damian@riscv-rocks.de>
Subject: Re: [PATCH] platform/x86: thinkpad_acpi: Fix NULL pointer dereferences while probing
Date: Tue, 01 Apr 2025 11:43:54 -0300 [thread overview]
Message-ID: <D8VDRV58EWSK.MKGI5JBD8RX6@gmail.com> (raw)
In-Reply-To: <455d5e7d-6f1e-a0a0-773b-85c26418bf54@linux.intel.com>
Hi Ilpo,
On Tue Apr 1, 2025 at 8:24 AM -03, Ilpo Järvinen wrote:
> On Sun, 30 Mar 2025, Kurt Borja wrote:
>
>> Some subdrivers make use of the global reference tpacpi_pdev during
>> initialization, which is called from the platform driver's probe.
>> However, after
>>
>> commit 38b9ab80db31 ("platform/x86: thinkpad_acpi: Move subdriver initialization to tpacpi_pdriver's probe.")
>>
>
> Next time, please include these into the paragraph flow normally obeying
> the normal paragraph formatting. I changed them in this case.
Thanks, won't happen next time.
>
>> this variable is only properly initialized *after* probing and this can
>> result in a NULL pointer dereference.
>>
>> In order to fix this without reverting the commit, register the platform
>> bundle in two steps, first create and initialize tpacpi_pdev, then
>> register the driver synchronously with platform_driver_probe(). This way
>> the benefits of commit 38b9ab80db31 are preserved.
>>
>> Additionally,
>>
>> commit 43fc63a1e8f6 ("platform/x86: thinkpad_acpi: Move HWMON initialization to tpacpi_hwmon_pdriver's probe")
>>
>> introduced a similar problem, however tpacpi_sensors_pdev is only used
>> once inside the probe, so replace the global reference with the one
>> given by the probe.
>>
>> Reported-by: Damian Tometzki <damian@riscv-rocks.de>
>> Closes: https://lore.kernel.org/r/CAL=B37kdL1orSQZD2A3skDOevRXBzF__cJJgY_GFh9LZO3FMsw@mail.gmail.com/
>> Fixes: 38b9ab80db31 ("platform/x86: thinkpad_acpi: Move subdriver initialization to tpacpi_pdriver's probe.")
>> Fixes: 43fc63a1e8f6 ("platform/x86: thinkpad_acpi: Move HWMON initialization to tpacpi_hwmon_pdriver's probe")
>> Tested-by: Damian Tometzki <damian@riscv-rocks.de>
>> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
>
> Applied to the review-ilpo-fixes branch.
Thank you!
>
>> ---
>> Hi all,
>>
>> The commit message is pretty self-explanatory. I have one question
>> though. As you can see in the crash dump of the original report:
>>
>> Mar 29 17:43:16.180758 fedora kernel: ? asm_exc_page_fault+0x26/0x30
>> Mar 29 17:43:16.180769 fedora kernel: ? __pfx_klist_children_get+0x10/0x10
>> Mar 29 17:43:16.180781 fedora kernel: ? kobject_get+0xd/0x70
>> Mar 29 17:43:16.180792 fedora kernel: device_add+0x8f/0x6e0
>> Mar 29 17:43:16.180804 fedora kernel: rfkill_register+0xbc/0x2c0 [rfkill]
>> Mar 29 17:43:16.180813 fedora kernel: tpacpi_new_rfkill+0x185/0x230 [thinkpad_acpi]
>>
>> The NULL dereference happens in device_add(), inside rfkill_register().
>> This bothers me because, as you can see here:
>>
>> 1198 atp_rfk->rfkill = rfkill_alloc(name,
>> 1199 &tpacpi_pdev->dev,
>> 1200 rfktype,
>> 1201 &tpacpi_rfk_rfkill_ops,
>> 1202 atp_rfk);
>>
>> the NULL deference happens in line 1199, inside tpacpi_new_rfkill(). I
>> think this disagreement might be due to compile time optimizations?
>
> How did you map it to line numbers? Is it just about difference in the
> compiled binaries that results in different line numbers?
Oh - I just manually followed the dump trace in search of the first
instance of a NULL derefence. If I understand correctly, inside
thinkpad_acpi we do reach rfkill_register(), which is line
1227 res = rfkill_register(atp_rfk->rfkill);
and I imagine the RIP happens when device_add() tries to get a reference
to the parent of the allocated rfkill device. But it's weird because we
shouldn't even reach 1227, as the NULL deref first happens at 1199.
NULL deref is UB so I guess it makes sense?
BTW I got all these line numbers using the base commit.
--
~ Kurt
prev parent reply other threads:[~2025-04-01 14:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-30 15:39 [PATCH] platform/x86: thinkpad_acpi: Fix NULL pointer dereferences while probing Kurt Borja
2025-03-30 18:43 ` Kurt Borja
2025-03-31 17:26 ` Genes Lists
2025-04-01 11:24 ` Ilpo Järvinen
2025-04-01 14:43 ` Kurt Borja [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D8VDRV58EWSK.MKGI5JBD8RX6@gmail.com \
--to=kuurtb@gmail.com \
--cc=damian@riscv-rocks.de \
--cc=hdegoede@redhat.com \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox