Repository navigation
userspace: restrict SOF syscalls to the threads that need them #11408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kv2019i
wants to merge
4
commits into
thesofproject:main
Choose a base branch
from
kv2019i:202611-syscall-restrictions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d69cd0d
userspace: add kernel-only registry of SOF syscall callers
kv2019i 5762d92
userspace: restrict SOF syscalls to the threads that need them
kv2019i d72dbd5
userspace: doc: document syscall caller restrictions
kv2019i c171548
zephyr: test: add negative tests for syscall validators
kv2019i File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2026 Intel Corporation. | ||
| */ | ||
|
|
||
| /** | ||
| * \file | ||
| * \brief Restrict SOF system calls to the user threads that need them. | ||
| * | ||
| * Zephyr lets any user thread invoke any system call. SOF user threads have | ||
| * different trust levels: the LL scheduler thread and the IPC user thread | ||
| * are SOF infrastructure, while DP threads run module code that can come | ||
| * from a third party. Most SOF system calls are only needed by the | ||
| * infrastructure threads, so their validators check the caller here. | ||
| * | ||
| * The thread registry is kept in kernel-only memory. Do not derive caller | ||
| * identity from data reachable by user threads, such as ipc_user->thread[] | ||
| * or the LL domain objects, as a user thread could rewrite it. | ||
| */ | ||
|
|
||
| #ifndef __SOF_USERSPACE_SYSCALL_CALLER_H__ | ||
| #define __SOF_USERSPACE_SYSCALL_CALLER_H__ | ||
|
|
||
| #include <stdbool.h> | ||
|
|
||
| struct k_thread; | ||
|
|
||
| /** LL scheduler user thread (one per core) */ | ||
| #define SOF_SYSUSER_LL (1U << 0) | ||
| /** IPC user thread (one per core) */ | ||
| #define SOF_SYSUSER_IPC (1U << 1) | ||
| /** Either SOF infrastructure user thread */ | ||
| #define SOF_SYSUSER_INFRA (SOF_SYSUSER_LL | SOF_SYSUSER_IPC) | ||
|
|
||
| #ifdef CONFIG_SOF_USERSPACE_SYSCALL_CALLER_CHECK | ||
|
|
||
| /** | ||
| * Record @thread as the user thread with @role on @core. | ||
| * | ||
| * Kernel context only. Call before the thread is started, and call again | ||
| * with @thread NULL before the thread object is freed. | ||
| * | ||
| * @param role SOF_SYSUSER_LL or SOF_SYSUSER_IPC (exactly one bit) | ||
| * @param core DSP core the thread is pinned to | ||
| * @param thread the k_thread to register, or NULL to clear the entry | ||
| */ | ||
| void sof_sysuser_thread_set(unsigned int role, unsigned int core, struct k_thread *thread); | ||
|
|
||
| /** | ||
| * Check whether the current thread holds one of @roles. | ||
| * | ||
| * For use in z_vrfy_*() validators. | ||
| * | ||
| * @param roles bitmask of SOF_SYSUSER_* roles that are allowed | ||
| * @return true if the calling thread is registered with an allowed role | ||
| */ | ||
| bool sof_syscall_caller_allowed(unsigned int roles); | ||
|
|
||
| /** Kill the calling user thread unless it holds one of @roles. */ | ||
| #define SOF_SYSCALL_CALLER_CHECK(roles) K_OOPS(!sof_syscall_caller_allowed(roles)) | ||
|
|
||
| #else | ||
|
|
||
| static inline void sof_sysuser_thread_set(unsigned int role, unsigned int core, | ||
| struct k_thread *thread) | ||
| { | ||
| } | ||
|
|
||
| #define SOF_SYSCALL_CALLER_CHECK(roles) do { } while (0) | ||
|
|
||
| #endif /* CONFIG_SOF_USERSPACE_SYSCALL_CALLER_CHECK */ | ||
|
|
||
| #endif /* __SOF_USERSPACE_SYSCALL_CALLER_H__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.