Skip to content

schedule: dp: keep DP task kernel objects in a kernel-only record - #11360

Open
kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202610-sched-robust-fix1
Open

kv2019i wants to merge 1 commit into
thesofproject:mainfrom
kv2019i:202610-sched-robust-fix1

Conversation

@kv2019i

@kv2019i kv2019i commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

scheduler_dp_internal_free() freed the event and thread objects, removed memory domain partitions and deinitialized the memory domain using pointers read from task_memory. That memory is in the module heap, which user threads can write, and the validator did not check mod->mdom at all. A caller could make the kernel free arbitrary kernel objects or operate on a forged memory domain.

Record the event, thread, memory domain, partitions and component id in kernel memory when the DP task is created. The free path, including the syscall, now only uses the task pointer as a lookup key, and rejects unknown or already freed tasks.

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

Teardown removes caller authorization checks and still follows user-writable allocator metadata in privileged context.

2 open issues
What changed in this PR

This PR hardens DP scheduler teardown by recording kernel-object ownership outside user-writable task memory.

Changes:

  • Adds a kernel-only task registry protected by a spinlock.
  • Uses recorded objects, domain partitions, and component IDs during cleanup.
  • Rejects unknown or already-freed task pointers and adds allocation-failure cleanup for records.
File Description
src/​schedule/​zephyr_dp_schedule_application.c Adds trusted task records and routes teardown through registry lookup.

Review effort: Balanced

k_object_free(kobj->thread);
scheduler_dp_domain_free(kobj->mod, kobj->mdom, kobj->mpart, kobj->comp_id);

mod_free(kobj->mod, container_of(task, struct scheduler_dp_task_memory, task));

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

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.

Sorry, that was not correct, this was not fixed in V2 or subsequent PR updates. Agreed this is a real issue, but it is not introduced by this PR: the base code runs the same mod_free() with the same checks. The root cause is that module resource bookkeeping lives in user-writable memory, and it affects all mod_* syscalls and other kernel-side sof_ctx_free() users, not only DP teardown. A partial fix here would leave a stale entry in the module's resource list. I propose to handle this in a follow-up that moves the module allocation context and resource bookkeeping to kernel-owned storage.

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.

What's your plan for splitting this further? I'm plan moving the fields intended exclusively for kernel-side usage out of struct processing_module into a separate pipeline_module structure. The pipeline would then maintain a list of pipeline_module instances, while individual modules would use a minimal processing_module containing module-specific data.

Comment thread src/schedule/zephyr_dp_schedule_application.c Outdated
@intel-sofci

intel-sofci commented Oct 26, 2026 •

Copy link
Copy Markdown

PR 11360: test results

Run date: 2026-10-28 15:10 UTC

Tested commit: e403aceb12622a9c97b99d7ccadaf3c5f0b9953e

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.

LGTM, some copilot opens..

@kv2019i
kv2019i force-pushed the 202610-sched-robust-fix1 branch from 2d0e980 to 8168e00 Compare October 28, 2026 11:51
@kv2019i
kv2019i requested a balanced review from Copilot October 28, 2026 11:51
@kv2019i

kv2019i commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

V2 pushed:

  • addressing code review comments

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

Active issues allow a userspace race to substitute a thread pointer later used by supervisor teardown, while self-teardown unlinks the record before aborting the caller and leaks resources.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/schedule/zephyr_dp_schedule_application.c Outdated
Comment thread src/schedule/zephyr_dp_schedule_application.c Outdated
@kv2019i
kv2019i force-pushed the 202610-sched-robust-fix1 branch from 8168e00 to 5d63e01 Compare October 28, 2026 12:34
@kv2019i

kv2019i commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

V3 pushed:

  • address findings to V2

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

The expected-record check can accept a replacement task when allocation addresses are reused, allowing a paused free syscall to tear down objects it never validated.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment on lines +221 to +224
if (kobj && expected &&
(kobj->event != expected->event || kobj->thread != expected->thread ||
kobj->mod != expected->mod))
kobj = NULL;
scheduler_dp_internal_free() freed the event and thread objects, removed
memory domain partitions and deinitialized the memory domain using
pointers read from task_memory. That memory is in the module heap, which
user threads can write, and the validator did not check mod->mdom at
all. A caller could make the kernel free arbitrary kernel objects or
operate on a forged memory domain.

Record the event, thread, memory domain, partitions and component id in
kernel memory when the DP task is created. The free path, including the
syscall, now only uses the task pointer as a lookup key, and rejects
unknown or already freed tasks.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i
kv2019i force-pushed the 202610-sched-robust-fix1 branch from 5d63e01 to e403ace Compare October 28, 2026 13:20
@kv2019i

kv2019i commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

V4 pushed:

  • yet more fixes to syscall validation, now including a record number

@lgirdwood

Copy link
Copy Markdown
Member

V4 pushed:

  • yet more fixes to syscall validation, now including a record number

@kv2019i can you check CI thanks !

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.

5 participants