Skip to content

misc: amd-apml: fix UAF on SBRMI/SBTSI unbind - #339

Open
pnavalag wants to merge 2 commits into
AMDESE:integ_sp8from
pnavalag:apml_port
Open

pnavalag wants to merge 2 commits into
AMDESE:integ_sp8from
pnavalag:apml_port

Conversation

@pnavalag

Copy link
Copy Markdown

Summary

  • Reject new SBRMI and SBTSI transactions during remove.
  • Unregister misc and hwmon, clear regmap under the device mutex, and keep driver data alive until the last close.
  • Preserve DIMM temperature conversion and existing SBRMI in-progress handling.

Testing

  • Congo-0555, OpenBMC sp7_v2.18.0.100I-8.
  • One persistent-ioctl unbind completed without a reboot or Oops.
  • 100 unbind/bind cycles completed with TEST_EXIT:0.
  • SB-TSI, SB-RMI, and hwmon reads succeeded after rebind.
  • Tested tree was built as 26dbb7a; this commit differs only by the amended commit message.

@abinayaddhandapani abinayaddhandapani left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google has provided 2 different patches for the issue. Please submit 2 separate commits as provided by google with the same commit message.

Also please add signed-off by Jake Chiang along with your signed-off message.

@pnavalag

Copy link
Copy Markdown
Author

Split into the two Google commits, in order:

  1. 7b99c43 amd-apml: Fix UAF and race condition on driver unbind
  2. 44a7032 misc: amd-apml: use kref to prevent ioctl UAF

Signed-off-by for Jake Chiang and Eugene Huang are included with mine.

One difference from Google's first patch: this tree still uses in_progress/misc_fops_done and the trace buffer, so those are not removed and the commit message does not claim they are. The combined code is the same tree that passed the unbind/bind cycles and the apml_tool checks on the Congo platform.

eugenetyhuang and others added 2 commits October 19, 2026 13:53
The SBRMI mailbox transfer (rmi_mailbox_xfer) can block for up
to 2 seconds waiting for firmware response. If the driver is
unbound while a hwmon read/write (sbrmi_read/sbrmi_write), ioctl
or sbrmi_open is in progress, the devm-managed rmi_dev structure
is freed while the transaction thread still holds a reference to
it, causing a Use-After-Free kernel panic.

Additionally, the original in_progress/misc_fops_done
completion mechanism only protected the ioctl path and had a
race window between the no_new_trans check and the
in_progress atomic set.

Fix this by:
- Replacing devm_hwmon_device_register_with_info with
  hwmon_device_register_with_info so the hwmon device can be
  explicitly unregistered early in the remove path.
- Setting no_new_trans=1 at the start of remove to signal
  shutdown to new requests.
- Calling misc_deregister() and hwmon_device_unregister()
  before acquiring the mutex, to close both entry points
  without holding the lock (avoids deadlock).
- Acquiring rmi_dev->lock in remove to wait for any in-flight
  critical section to complete, then setting regmap=NULL as a
  fail-safe to prevent stale hardware accesses.
- Acquiring rmi_dev->lock in sbrmi_open() to protect
  configure_regmap() from concurrent driver unbinds, since
  it can trigger SBRMI mailbox transfers.
- Checking no_new_trans under lock in sbrmi_read, sbrmi_write,
  and sbrmi_ioctl to reject new transactions during shutdown.

This port keeps in_progress and misc_fops_done, and it keeps the
existing DIMM temperature conversion. The trace buffer allocation
is unchanged.

Apply the same fix to apml_sbtsi.c, which had an identical
vulnerability with no synchronization in its remove path.

Change-Id: I27d2c52724a52df40ec9c9517d17c02ae9b83a30
Signed-off-by: Eugene Huang <eugene.ty.huang@fii-na.corp-partner.google.com>
Signed-off-by: Jake Chiang <hung-tse.chiang@fii-na.corp-partner.google.com>
Signed-off-by: Pradeep Navalagi <pnavalag@amd.com>
Existing file descriptors may remain open after misc_deregister(), causing
ioctl to access freed driver data after unbind.

Manage the driver data lifetime with kref and hold a reference for each
open file. During remove, mark the device unavailable and drop the driver
reference, allowing unbind to complete while existing ioctls fail safely.

Apply the same fix to the sbtsi driver, which is affected by the same
lifetime issue.

Change-Id: I76c65f005efa3501e27f9d5337fea01534d77848
Signed-off-by: Jake Chiang <hung-tse.chiang@fii-na.corp-partner.google.com>
Signed-off-by: Eugene Huang <eugene.ty.huang@fii-na.corp-partner.google.com>
Signed-off-by: Pradeep Navalagi <pnavalag@amd.com>

@mahkurap mahkurap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like the DCSM team to take the ownership of these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants