CVE: CVE-2022-49196
Published: 2025-02-26
Description: In the Linux kernel, the following vulnerability has been resolved:

powerpc/pseries: Fix use after free in remove_phb_dynamic()

In remove_phb_dynamic() we use &phb->io_resource, after we've called
device_unregister(&host_bridge->dev). But the unregister may have freed
phb, because pcibios_free_controller_deferred() is the release function
for the host_bridge.

If there are no outstanding references when we call device_unregister()
then phb will be freed out from under us.

This has gone mainly unnoticed, but with slub_debug and page_poison
enabled it can lead to a crash:

  PID: 7574   TASK: c0000000d492cb80  CPU: 13  COMMAND: "drmgr"
   #0 [c0000000e4f075a0] crash_kexec at c[PII_REDACTED]7d7dc
   #1 [c0000000e4f075d0] oops_end at c[PII_REDACTED]29608
   #2 [c0000000e4f07650] __bad_page_fault at c[PII_REDACTED]904b4
   #3 [c0000000e4f076c0] do_bad_slb_fault at c[PII_REDACTED]9a5a8
   #4 [c0000000e4f076f0] data_access_slb_common_virt at c[PII_REDACTED]08b30
   Data SLB Access [380] exception frame:
   R0:  c[PII_REDACTED]67250    R1:  c0000000e4f07a00    R2:  c000000002a46100
   R3:  c000000002b39ce8    R4: [PII_REDACTED]0000c0    R5: [PII_REDACTED]0000a9
   R6:  3894674d000000c0    R7:  [PII_REDACTED]    R8: [PII_REDACTED]0000ff
   R9:  [PII_REDACTED]    R10: 6b6b6b6b6b6b6b6b    R11: [PII_REDACTED]
   R12: c[PII_REDACTED]3da80    R13: c0000009ffd38b00    R14: [PII_REDACTED]
   R15: 000000011c87f0f0    R16: [PII_REDACTED]    R17: [PII_REDACTED]
   R18: [PII_REDACTED]    R19: [PII_REDACTED]    R20: [PII_REDACTED]
   R21: 000000011c87ede8    R22: 000000011c87c5a8    R23: 000000011c87d3a0
   R24: [PII_REDACTED]    R25: [PII_REDACTED]    R26: c0000000e4f07cc8
   R27: c00000004d1cc400    R28: c[PII_REDACTED]d00e8    R29: c00000004d23d800
   R30: c00000004d1d2400    R31: c00000004d1d2540
   NIP: c[PII_REDACTED]67258    MSR: [PII_REDACTED]    OR3: c000000000e9f474
   CTR: [PII_REDACTED]    LR:  c[PII_REDACTED]67250    XER: [PII_REDACTED]
   CCR: [PII_REDACTED]    MQ:  [PII_REDACTED]    DAR: 6b6b6b6b6b6b6ba3
   DSISR: c0000000e4f07920     Syscall Result: fffffffffffffff2
   [NIP  : release_resource+56]
   [LR   : release_resource+48]
   #5 [c0000000e4f07a00] release_resource at c[PII_REDACTED]67258  (unreliable)
   #6 [c0000000e4f07a30] remove_phb_dynamic at c[PII_REDACTED]05648
   #7 [c0000000e4f07ab0] dlpar_remove_slot at c[PII_REDACTED]a09e8 [rpadlpar_io]
   #8 [c0000000e4f07b50] remove_slot_store at c[PII_REDACTED]a0b9c [rpadlpar_io]
   #9 [c0000000e4f07be0] kobj_attr_store at c[PII_REDACTED]17d8c
  #10 [c0000000e4f07c00] sysfs_kf_write at c[PII_REDACTED]3e504
  #11 [c0000000e4f07c20] kernfs_fop_write_iter at c[PII_REDACTED]3d868
  #12 [c0000000e4f07c70] new_sync_write at c[PII_REDACTED]4339c
  #13 [c0000000e4f07d10] vfs_write at c[PII_REDACTED]46624
  #14 [c0000000e4f07d60] ksys_write at c[PII_REDACTED]469f4
  #15 [c0000000e4f07db0] system_call_exception at c[PII_REDACTED]30840
  #16 [c0000000e4f07e10] system_call_vectored_common at c[PII_REDACTED]0c168

To avoid it, we can take a reference to the host_bridge->dev until we're
done using phb. Then when we drop the reference the phb will be freed.
CVSS Score: 7.8 (HIGH)
CWE: CWE-416
References: https://git.kernel.org/stable/c/33d39efb61a84e055ca2386157d39ebbdf6b7d31; https://git.kernel.org/stable/c/403f9e0bc5535a0a5184d1352fa3a70e6ffacb6f; https://git.kernel.org/stable/c/895ca4ae1f72e0a0160ab162723e59c9f265ec93