Skip to content

kernel: simpler copy policydb implementation#3350

Merged
5ec1cff merged 1 commit intomainfrom
copypol
May 10, 2026
Merged

kernel: simpler copy policydb implementation#3350
5ec1cff merged 1 commit intomainfrom
copypol

Conversation

@5ec1cff
Copy link
Copy Markdown
Collaborator

@5ec1cff 5ec1cff commented Mar 27, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors SELinux policy duplication in the kernel SELinux integration to use a simpler “serialize + deserialize” approach instead of hand-copying selected policydb structures.

Changes:

  • Replace the custom partial/deep copy logic for policydb with policydb_write() into a buffer followed by policydb_read() into a fresh policydb.
  • Simplify policy destruction by calling policydb_destroy() directly.
  • Add a small “config” fixup in the serialized policy buffer before reading it back.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kernel/selinux/sepolicy.c Outdated
Comment thread kernel/selinux/sepolicy.c Outdated
Comment thread kernel/selinux/sepolicy.c
Comment thread kernel/selinux/sepolicy.c
AlexLiuDev233 added a commit to ReSukiSU/ReSukiSU that referenced this pull request May 3, 2026
use policydb_read/policydb_write for dup_policy

add same way for nongki to fix the problem as below
<3>[    4.086580] BUG: sleeping function called from invalid context at security/selinux/ss/hashtab.c:47
<3>[    4.086583] in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 1, name: init
<4>[    4.086586] CPU: 7 PID: 1 Comm: init Tainted: G        W         5.4.302-qgki-g342369d45f2a #451
<4>[    4.086589] Hardware name: Qualcomm Technologies, Inc. Blair QRD NOPMI (DT)
<4>[    4.086591] Call trace:
<4>[    4.086599] dump_backtrace+0x0/0x19c
<4>[    4.086603] dump_stack+0x90/0xcc
<4>[    4.086606] ___might_sleep+0x110/0x12c
<4>[    4.086610] hashtab_insert+0x3c/0x18c
<4>[    4.086614] add_type.llvm.13442088749150705041+0x98/0x1f0
<4>[    4.086616] ksu_type+0x28/0x5c
<4>[    4.086618] apply_kernelsu_rules+0xb8/0x5b4
<4>[    4.086621] ksu_initialize_selinux+0x10/0x24
<4>[    4.086623] ksu_handle_execveat_ksud+0x1a8/0x388
<4>[    4.086626] ksu_handle_execveat+0xec/0xf4
<4>[    4.086629] __arm64_sys_execve+0x50/0x84
<4>[    4.086632] el0_svc_common+0xdc/0x1ac
<4>[    4.086634] el0_svc_handler+0x24/0x64
<4>[    4.086637] el0_svc+0x8/0x140

for backslashxx's afraid of time window to race, use lock sel_mutex to solve
Thanks for 5ec1cff's idea and help!

Off topic:
I don't want use stop_machine like:
backslashxx/KernelSU@4309f10
backslashxx/KernelSU@454b0c9
Even only in sel_mutex/policy_rwlock not exported
This severely impacts performance

[Adapted from upstream pull request tiann/KernelSU#3350]

Co-authored-by: 5ec1cff <ewtqyqyewtqyqy@gmail.com>
Signed-off-by: AlexLiuDev233 <wzylin11@outlook.com>
AlexLiuDev233 added a commit to ReSukiSU/ReSukiSU that referenced this pull request May 3, 2026
use policydb_read/policydb_write for dup_policy

add same way for nongki to fix the problem as below
<3>[    4.086580] BUG: sleeping function called from invalid context at security/selinux/ss/hashtab.c:47
<3>[    4.086583] in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 1, name: init
<4>[    4.086586] CPU: 7 PID: 1 Comm: init Tainted: G        W         5.4.302-qgki-g342369d45f2a #451
<4>[    4.086589] Hardware name: Qualcomm Technologies, Inc. Blair QRD NOPMI (DT)
<4>[    4.086591] Call trace:
<4>[    4.086599] dump_backtrace+0x0/0x19c
<4>[    4.086603] dump_stack+0x90/0xcc
<4>[    4.086606] ___might_sleep+0x110/0x12c
<4>[    4.086610] hashtab_insert+0x3c/0x18c
<4>[    4.086614] add_type.llvm.13442088749150705041+0x98/0x1f0
<4>[    4.086616] ksu_type+0x28/0x5c
<4>[    4.086618] apply_kernelsu_rules+0xb8/0x5b4
<4>[    4.086621] ksu_initialize_selinux+0x10/0x24
<4>[    4.086623] ksu_handle_execveat_ksud+0x1a8/0x388
<4>[    4.086626] ksu_handle_execveat+0xec/0xf4
<4>[    4.086629] __arm64_sys_execve+0x50/0x84
<4>[    4.086632] el0_svc_common+0xdc/0x1ac
<4>[    4.086634] el0_svc_handler+0x24/0x64
<4>[    4.086637] el0_svc+0x8/0x140

for backslashxx's afraid of time window to race, use lock sel_mutex to solve
Thanks for 5ec1cff's idea and help!

Off topic:
I don't want use stop_machine like:
backslashxx/KernelSU@4309f10
backslashxx/KernelSU@454b0c9
Even only in sel_mutex/policy_rwlock not exported
This severely impacts performance

[Adapted from upstream pull request tiann/KernelSU#3350]

Co-authored-by: 5ec1cff <ewtqyqyewtqyqy@gmail.com>
Signed-off-by: AlexLiuDev233 <wzylin11@outlook.com>
AlexLiuDev233 added a commit to ReSukiSU/ReSukiSU that referenced this pull request May 3, 2026
use policydb_read/policydb_write for dup_policy

add same way for nongki to fix the problem as below
<3>[    4.086580] BUG: sleeping function called from invalid context at security/selinux/ss/hashtab.c:47
<3>[    4.086583] in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 1, name: init
<4>[    4.086586] CPU: 7 PID: 1 Comm: init Tainted: G        W         5.4.302-qgki-g342369d45f2a #451
<4>[    4.086589] Hardware name: Qualcomm Technologies, Inc. Blair QRD NOPMI (DT)
<4>[    4.086591] Call trace:
<4>[    4.086599] dump_backtrace+0x0/0x19c
<4>[    4.086603] dump_stack+0x90/0xcc
<4>[    4.086606] ___might_sleep+0x110/0x12c
<4>[    4.086610] hashtab_insert+0x3c/0x18c
<4>[    4.086614] add_type.llvm.13442088749150705041+0x98/0x1f0
<4>[    4.086616] ksu_type+0x28/0x5c
<4>[    4.086618] apply_kernelsu_rules+0xb8/0x5b4
<4>[    4.086621] ksu_initialize_selinux+0x10/0x24
<4>[    4.086623] ksu_handle_execveat_ksud+0x1a8/0x388
<4>[    4.086626] ksu_handle_execveat+0xec/0xf4
<4>[    4.086629] __arm64_sys_execve+0x50/0x84
<4>[    4.086632] el0_svc_common+0xdc/0x1ac
<4>[    4.086634] el0_svc_handler+0x24/0x64
<4>[    4.086637] el0_svc+0x8/0x140

for backslashxx's afraid of time window to race, use lock sel_mutex to solve
Thanks for 5ec1cff's idea and help!

Off topic:
I don't want use stop_machine like:
backslashxx/KernelSU@4309f10
backslashxx/KernelSU@454b0c9
Even only in sel_mutex/policy_rwlock not exported
This severely impacts performance

[Adapted from upstream pull request tiann/KernelSU#3350]

Co-authored-by: 5ec1cff <ewtqyqyewtqyqy@gmail.com>
Signed-off-by: AlexLiuDev233 <wzylin11@outlook.com>
@5ec1cff 5ec1cff marked this pull request as ready for review May 10, 2026 13:57
@5ec1cff 5ec1cff merged commit f9c7823 into main May 10, 2026
19 checks passed
@5ec1cff 5ec1cff deleted the copypol branch May 10, 2026 14:09
pershoot pushed a commit to KernelSU-Next/KernelSU-Next that referenced this pull request May 11, 2026
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.

2 participants