kernel: prune redundant avtab nodes after deny rules#3439
kernel: prune redundant avtab nodes after deny rules#3439XiaoTong6666 wants to merge 3 commits intotiann:mainfrom
Conversation
Runtime deny rules clear permission bits from AVTAB_ALLOWED entries. When all permissions are removed from an existing entry, the update can leave an AVTAB_ALLOWED node with data == 0. Such zero-permission avtab nodes are redundant and can make external policy parsers, such as sepatch, reject /sys/fs/selinux/policy with errors like: Invalid access vector Invalid avtab Invalid policydb policy image is invalid This was observed when applying: deny appdomain cgroup_v2 dir search The rule itself is valid, but the runtime patch left a redundant avtab entry behind. Avoid creating new entries for deny updates when the target entry does not exist, and prune redundant nodes after access-vector rule updates by rebuilding the avtab and destroying the old table through avtab_destroy(). This preserves deny semantics while keeping the live policy parseable by policydb-based tools.
|
Modules that use sepatch, such as https://github.com/chenxiaolong/MSD, can trigger this issue. |
|
Magisk's sepolicy implementation appears to handle this case as well: it defines redundant avtab node detection and removes such nodes after rule updates when necessary. See: |
Runtime deny rules clear permission bits from AVTAB_ALLOWED entries. When all permissions are removed from an existing entry, the update can leave an AVTAB_ALLOWED node with data == 0. Such zero-permission avtab nodes are redundant and can make external policy parsers, such as sepatch, reject /sys/fs/selinux/policy with errors like: Invalid access vector Invalid avtab Invalid policydb policy image is invalid This was observed when applying: deny appdomain cgroup_v2 dir search The rule itself is valid, but the runtime patch left a redundant avtab entry behind. Avoid creating new entries for deny updates when the target entry does not exist, and prune redundant nodes after access-vector rule updates by rebuilding the avtab and destroying the old table through avtab_destroy(). This preserves deny semantics while keeping the live policy parseable by policydb-based tools.
Runtime deny rules clear permission bits from AVTAB_ALLOWED entries. When all permissions are removed from an existing entry, the update can leave an AVTAB_ALLOWED node with data == 0. Such zero-permission avtab nodes are redundant and can make external policy parsers, such as sepatch, reject /sys/fs/selinux/policy with errors like: Invalid access vector Invalid avtab Invalid policydb policy image is invalid This was observed when applying: deny appdomain cgroup_v2 dir search The rule itself is valid, but the runtime patch left a redundant avtab entry behind. Avoid creating new entries for deny updates when the target entry does not exist, and prune redundant nodes after access-vector rule updates by rebuilding the avtab and destroying the old table through avtab_destroy(). This preserves deny semantics while keeping the live policy parseable by policydb-based tools.
There was a problem hiding this comment.
Pull request overview
This PR updates KernelSU's live SELinux policy patching so runtime deny-style AV rule changes do not leave redundant zero-permission AVTAB entries behind, which helps keep the in-kernel policy export parseable by policydb-based tools.
Changes:
- add helpers to detect and remove redundant AVTAB nodes after access-vector updates
- change inverted rule handling so missing target entries are not created for deny-style updates
- add failure checks when inserting AVTAB nodes for normal and type-rule updates
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Prune redundant avtab nodes by detaching the target node and releasing it through a temporary avtab with avtab_destroy(), instead of rebuilding the entire te_avtab. Propagate add_rule_raw() and avtab removal failures to callers so failed insertions or prune operations are not reported as successful updates. Keep AVTAB_AUDITDENY updates able to create missing entries, while missing deny-style AVTAB_ALLOWED entries remain no-ops.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Runtime deny rules clear permission bits from AVTAB_ALLOWED entries. When all permissions are removed from an existing entry, the update can leave an AVTAB_ALLOWED node with data == 0.
Such zero-permission avtab nodes are redundant and can make external policy parsers, such as sepatch, reject /sys/fs/selinux/policy with errors like:
Invalid access vector
Invalid avtab
Invalid policydb
policy image is invalid
This was observed when applying:
deny appdomain cgroup_v2 dir search
The rule itself is valid, but the runtime patch left a redundant avtab entry behind.
Avoid creating new entries for deny updates when the target entry does not exist, and prune redundant nodes after access-vector rule updates by rebuilding the avtab and destroying the old table through avtab_destroy().
This preserves deny semantics while keeping the live policy parseable by policydb-based tools.