Skip to content

ipc: improve isolation between user and kernel IPC code - #11378

Open
kv2019i wants to merge 2 commits into
thesofproject:mainfrom
kv2019i:202610-user-ipc-fixes
Open

kv2019i wants to merge 2 commits into
thesofproject:mainfrom
kv2019i:202610-user-ipc-fixes

Conversation

@kv2019i

@kv2019i kv2019i commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Two patches to lock down kernel IPC resources.

With CONFIG_SOF_USERSPACE_LL, struct ipc is placed in a memory partition
that the LL and IPC user threads can write. It embedded the IPC send work
queue, including the k_thread object of its supervisor thread, and the
delayable work item holding the handler the queue calls. A user thread
could redirect supervisor execution with a plain store.

Move both to kernel-only static storage and add ipc_send_wq_get() for
the IPC4 logging code that queues work on it.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical startup race allows an active core to overwrite shared pointers before they enter the trusted cache, causing subsequent kernel calls to use attacker-selected pointers.

1 open issue
What changed in this PR

This PR strengthens SOF’s user/kernel IPC isolation by moving privileged work-queue resources out of user-writable state and introducing kernel-side IPC object references.

Changes:

  • Move the IPC send queue and delayed work into kernel-only storage.
  • Add kernel-side references for IPC synchronization objects and user threads.
  • Route logging and secondary-core initialization through dedicated helpers.
File Description
src/​ipc/​ipc4/​logging.c Uses the IPC send-queue accessor.
src/​ipc/​ipc4/​handler-kernel.c Delegates secondary-core initialization waiting to a helper.
src/​ipc/​ipc-common.c Adds kernel-only IPC resources, object references and helper implementations.
src/​include/​sof/​ipc/​common.h Removes embedded work-queue objects and declares kernel-context helpers.

Review effort: Balanced

Comment thread src/ipc/ipc-common.c Outdated
return -ENOMEM;
}
k_event_init(ipc_user->event[core]);
ipc_user_kevent[core] = ipc_user->event[core];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in V2.

@intel-sofci

intel-sofci commented Oct 29, 2026 •

Copy link
Copy Markdown

PR 11378: test results

Run date: 2026-10-31 04:37 UTC

Tested commit: 7bc89bd5a2cfc260571ddb17fd51e8b38558703c

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kv2019i just a copilot open.

@kv2019i
kv2019i force-pushed the 202610-user-ipc-fixes branch from aaee753 to 9a3f02a Compare October 30, 2026 14:43
@kv2019i

kv2019i commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

V2 pushed:

  • address code review comments so far

The kernel side of the user-space IPC handoff took the semaphore, event
and thread pointers, and the ipc_user pointer itself, from struct
ipc_user and ipc->ipc_user_pdata. Both are writable by user threads, so
the kernel could be made to operate on forged kernel objects or write
to an address chosen by a user thread.

Record these pointers in kernel-only variables at init and use them in
ipc_user_forward_cmd(), secondary core setup and ipc_thread_user()
when called from kernel context. Move the secondary core boot wait into
ipc_user_wait_core_init() so handler-kernel.c no longer reads them, and
keep the per-core init_needed flags in kernel-only storage as well.

Build new objects in locals and publish them to struct ipc_user only
after the kernel-only copies are set. On secondary core bring-up the
IPC user thread of the primary core is already running and could
otherwise overwrite the fields before they are read back.

Add ipc_user_get() for kernel code that needs the ipc_user context and
use it in ipc4_user_process_module_message() instead of
ipc->ipc_user_pdata.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i
kv2019i force-pushed the 202610-user-ipc-fixes branch from 9a3f02a to 7bc89bd Compare October 30, 2026 16:40
@kv2019i

kv2019i commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

V3 pushed:

  • fix doxygen error

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