Skip to content

Commit

Permalink
pci/of: add null check for of_pci_supply_present
Browse files Browse the repository at this point in the history
Hopefully this fixes the following:

[    0.553307] BUG: kernel NULL pointer dereference, address: 0000000000000058
[    0.554054] #PF: supervisor read access in kernel mode
[    0.554609] #PF: error_code(0x0000) - not-present page
[    0.555155] PGD 0 P4D 0
[    0.555429] Oops: Oops: 0000 [#1] PREEMPT SMP NOPTI
[    0.555947] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.12.0-next-20241121-00021-g08d9c92ab3f3 torvalds#247
[    0.556166] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
[    0.556166] RIP: 0010:of_pci_supply_present (drivers/pci/of.c:746)
[ 0.556166] Code: a5 c8 00 00 00 48 89 ab 40 03 00 00 eb c6 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 0f 1f 00 0f 1f 44 00 00 53 <48> 8b 5f 58 48 85 db 74 2e 48 8b 3b be 2d 00 00 00 e8 20 d8 63 00
All code
========
   0:	a5                   	movsl  %ds:(%rsi),%es:(%rdi)
   1:	c8 00 00 00          	enter  $0x0,$0x0
   5:	48 89 ab 40 03 00 00 	mov    %rbp,0x340(%rbx)
   c:	eb c6                	jmp    0xffffffffffffffd4
   e:	66 90                	xchg   %ax,%ax
  10:	90                   	nop
  11:	90                   	nop
  12:	90                   	nop
  13:	90                   	nop
  14:	90                   	nop
  15:	90                   	nop
  16:	90                   	nop
  17:	90                   	nop
  18:	90                   	nop
  19:	90                   	nop
  1a:	90                   	nop
  1b:	90                   	nop
  1c:	90                   	nop
  1d:	90                   	nop
  1e:	90                   	nop
  1f:	90                   	nop
  20:	66 0f 1f 00          	nopw   (%rax)
  24:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
  29:	53                   	push   %rbx
  2a:*	48 8b 5f 58          	mov    0x58(%rdi),%rbx		<-- trapping instruction
  2e:	48 85 db             	test   %rbx,%rbx
  31:	74 2e                	je     0x61
  33:	48 8b 3b             	mov    (%rbx),%rdi
  36:	be 2d 00 00 00       	mov    $0x2d,%esi
  3b:	e8 20 d8 63 00       	call   0x63d860

Code starting with the faulting instruction
===========================================
   0:	48 8b 5f 58          	mov    0x58(%rdi),%rbx
   4:	48 85 db             	test   %rbx,%rbx
   7:	74 2e                	je     0x37
   9:	48 8b 3b             	mov    (%rbx),%rdi
   c:	be 2d 00 00 00       	mov    $0x2d,%esi
  11:	e8 20 d8 63 00       	call   0x63d836
[    0.556166] RSP: 0018:ffffb6510001fb00 EFLAGS: 00010286
[    0.556166] RAX: ffff9c4d02126000 RBX: ffff9c4d02648000 RCX: ffffffff84c59080
[    0.556166] RDX: ffff9c4d02126000 RSI: 0000000000000000 RDI: 0000000000000000
[    0.556166] RBP: ffff9c4d02126000 R08: 0000000000000000 R09: 0000000000000008
[    0.556166] R10: 0000000000000002 R11: 0000000000000000 R12: 0000000000000000
[    0.556166] R13: ffff9c4d026480c8 R14: 0000000000000000 R15: ffff9c4d022eae18
[    0.556166] FS:  0000000000000000(0000) GS:ffff9c4d3ca00000(0000) knlGS:0000000000000000
[    0.556166] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.556166] CR2: 0000000000000058 CR3: 0000000030634000 CR4: 0000000000350ef0
[    0.556166] Call Trace:
[    0.556166]  <TASK>
[    0.556166] ? __die_body.cold (arch/x86/kernel/dumpstack.c:478 (discriminator 1) arch/x86/kernel/dumpstack.c:465 (discriminator 1) arch/x86/kernel/dumpstack.c:420 (discriminator 1))
[    0.556166] ? page_fault_oops (arch/x86/mm/fault.c:711 (discriminator 1))
[    0.556166] ? exc_page_fault (arch/x86/include/asm/irqflags.h:37 arch/x86/include/asm/irqflags.h:92 arch/x86/mm/fault.c:1489 arch/x86/mm/fault.c:1539)
[    0.556166] ? asm_exc_page_fault (arch/x86/include/asm/idtentry.h:623)
[    0.556166] ? __pfx_device_match_of_node (drivers/base/core.c:5248)
[    0.556166] ? of_pci_supply_present (drivers/pci/of.c:746)
[    0.556166] pci_bus_add_device (drivers/pci/bus.c:408 (discriminator 1))
[    0.556166] pci_bus_add_devices (drivers/pci/bus.c:435 (discriminator 2))
[    0.556166] acpi_pci_root_add (drivers/acpi/pci_root.c:762)
[    0.556166] ? acpi_device_is_battery (drivers/acpi/scan.c:1249 (discriminator 1))
[    0.556166] acpi_bus_attach (drivers/acpi/scan.c:2261 drivers/acpi/scan.c:2309)
[    0.556166] ? __pfx_acpi_dev_for_one_check (drivers/acpi/bus.c:1139)
[    0.556166] device_for_each_child (drivers/base/core.c:3994)
[    0.556166] acpi_dev_for_each_child (drivers/acpi/bus.c:1158)
[    0.556166] ? __pfx_acpi_bus_attach (drivers/acpi/scan.c:2274)
[    0.556166] acpi_bus_attach (drivers/acpi/scan.c:2331 (discriminator 1))
[    0.556166] ? __pfx_acpi_dev_for_one_check (drivers/acpi/bus.c:1139)
[    0.556166] device_for_each_child (drivers/base/core.c:3994)
[    0.556166] acpi_dev_for_each_child (drivers/acpi/bus.c:1158)
[    0.556166] ? __pfx_acpi_bus_attach (drivers/acpi/scan.c:2274)
[    0.556166] acpi_bus_attach (drivers/acpi/scan.c:2331 (discriminator 1))
[    0.556166] acpi_bus_scan (drivers/acpi/scan.c:2541 drivers/acpi/scan.c:2614)
[    0.556166] acpi_scan_init (drivers/acpi/scan.c:2747 (discriminator 1))
[    0.556166] ? srso_return_thunk (arch/x86/lib/retpoline.S:224)
[    0.556166] acpi_init (drivers/acpi/bus.c:1467)
[    0.556166] ? add_device_randomness (drivers/char/random.c:950)
[    0.556166] ? __pfx_acpi_init (drivers/acpi/bus.c:1438)
[    0.556166] do_one_initcall (init/main.c:1266)
[    0.556166] kernel_init_freeable (init/main.c:1327 (discriminator 3) init/main.c:1344 (discriminator 3) init/main.c:1363 (discriminator 3) init/main.c:1577 (discriminator 3))
[    0.556166] ? __pfx_kernel_init (init/main.c:1458)
[    0.556166] kernel_init (init/main.c:1468)
[    0.556166] ret_from_fork (arch/x86/kernel/process.c:153)
[    0.556166] ? __pfx_kernel_init (init/main.c:1458)
[    0.556166] ret_from_fork_asm (arch/x86/entry/entry_64.S:254)
[    0.556166]  </TASK>
[    0.556166] Modules linked in:
[    0.556166] CR2: 0000000000000058
[    0.556166] ---[ end trace 0000000000000000 ]---
[    0.556166] RIP: 0010:of_pci_supply_present (drivers/pci/of.c:746)
[ 0.556166] Code: a5 c8 00 00 00 48 89 ab 40 03 00 00 eb c6 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 0f 1f 00 0f 1f 44 00 00 53 <48> 8b 5f 58 48 85 db 74 2e 48 8b 3b be 2d 00 00 00 e8 20 d8 63 00
All code
========
   0:	a5                   	movsl  %ds:(%rsi),%es:(%rdi)
   1:	c8 00 00 00          	enter  $0x0,$0x0
   5:	48 89 ab 40 03 00 00 	mov    %rbp,0x340(%rbx)
   c:	eb c6                	jmp    0xffffffffffffffd4
   e:	66 90                	xchg   %ax,%ax
  10:	90                   	nop
  11:	90                   	nop
  12:	90                   	nop
  13:	90                   	nop
  14:	90                   	nop
  15:	90                   	nop
  16:	90                   	nop
  17:	90                   	nop
  18:	90                   	nop
  19:	90                   	nop
  1a:	90                   	nop
  1b:	90                   	nop
  1c:	90                   	nop
  1d:	90                   	nop
  1e:	90                   	nop
  1f:	90                   	nop
  20:	66 0f 1f 00          	nopw   (%rax)
  24:	0f 1f 44 00 00       	nopl   0x0(%rax,%rax,1)
  29:	53                   	push   %rbx
  2a:*	48 8b 5f 58          	mov    0x58(%rdi),%rbx		<-- trapping instruction
  2e:	48 85 db             	test   %rbx,%rbx
  31:	74 2e                	je     0x61
  33:	48 8b 3b             	mov    (%rbx),%rdi
  36:	be 2d 00 00 00       	mov    $0x2d,%esi
  3b:	e8 20 d8 63 00       	call   0x63d860

Code starting with the faulting instruction
===========================================
   0:	48 8b 5f 58          	mov    0x58(%rdi),%rbx
   4:	48 85 db             	test   %rbx,%rbx
   7:	74 2e                	je     0x37
   9:	48 8b 3b             	mov    (%rbx),%rdi
   c:	be 2d 00 00 00       	mov    $0x2d,%esi
  11:	e8 20 d8 63 00       	call   0x63d836
[    0.556166] RSP: 0018:ffffb6510001fb00 EFLAGS: 00010286
[    0.556166] RAX: ffff9c4d02126000 RBX: ffff9c4d02648000 RCX: ffffffff84c59080
[    0.556166] RDX: ffff9c4d02126000 RSI: 0000000000000000 RDI: 0000000000000000
[    0.556166] RBP: ffff9c4d02126000 R08: 0000000000000000 R09: 0000000000000008
[    0.556166] R10: 0000000000000002 R11: 0000000000000000 R12: 0000000000000000
[    0.556166] R13: ffff9c4d026480c8 R14: 0000000000000000 R15: ffff9c4d022eae18
[    0.556166] FS:  0000000000000000(0000) GS:ffff9c4d3ca00000(0000) knlGS:0000000000000000
[    0.556166] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    0.556166] CR2: 0000000000000058 CR3: 0000000030634000 CR4: 0000000000350ef0
[    0.556166] note: swapper/0[1] exited with irqs disabled
[    0.556170] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
[    0.557012] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009 ]---

Fixes: 30ccf07 ("PCI/pwrctl: Create pwrctl device only if at least one power supply is present")
Signed-off-by: Klara Modin <klarasmodin@gmail.com>
  • Loading branch information
klarasm committed Nov 21, 2024
1 parent 08d9c92 commit 0264924
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/pci/of.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ bool of_pci_supply_present(struct device_node *np)
struct property *prop;
char *supply;

if (!np) return false;

for_each_property_of_node(np, prop) {
supply = strrchr(prop->name, '-');
if (supply && !strcmp(supply, "-supply"))
Expand Down

0 comments on commit 0264924

Please sign in to comment.