Skip to content

support drop capabilities #8791

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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

support drop capabilities #8791

wants to merge 2 commits into from

Conversation

vvb2060
Copy link
Collaborator

@vvb2060 vvb2060 commented Feb 15, 2025

No description provided.

@topjohnwu topjohnwu added the next Planned for the release *after* the next release label Apr 1, 2025
@yujincheng08 yujincheng08 requested a review from Copilot April 2, 2025 04:12
Copy link

@Copilot 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 adds support for dropping capabilities by introducing a new field (drop_cap) in the SuRequest structure and a corresponding SuPolicy variant (Restrict).

  • Add the drop_cap field with a default value and adjust its behavior based on the SuPolicy setting.
  • Introduce the new SuPolicy::Restrict variant to trigger the drop capabilities.

Reviewed Changes

Copilot reviewed 2 out of 19 changed files in this pull request and generated no comments.

File Description
native/src/core/su/daemon.rs Added drop_cap initialization and updated logic based on SuPolicy.
native/src/core/lib.rs Added drop_cap field definition and new SuPolicy::Restrict variant.
Files not reviewed (17)
  • app/apk/src/main/java/com/topjohnwu/magisk/databinding/DataBindingAdapters.kt: Language not supported
  • app/apk/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt: Language not supported
  • app/apk/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt: Language not supported
  • app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/PolicyRvItem.kt: Language not supported
  • app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt: Language not supported
  • app/apk/src/main/res/layout/item_log_access_md2.xml: Language not supported
  • app/apk/src/main/res/layout/item_policy_md2.xml: Language not supported
  • app/core/src/main/java/com/topjohnwu/magisk/core/Config.kt: Language not supported
  • app/core/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt: Language not supported
  • app/core/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt: Language not supported
  • app/core/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt: Language not supported
  • app/core/src/main/res/values-zh-rCN/strings.xml: Language not supported
  • app/core/src/main/res/values/strings.xml: Language not supported
  • native/src/base/misc.cpp: Language not supported
  • native/src/base/misc.hpp: Language not supported
  • native/src/core/selinux.cpp: Language not supported
  • native/src/core/su/su.cpp: Language not supported
Comments suppressed due to low confidence (2)

native/src/core/su/daemon.rs:172

  • The logic for setting the drop_cap flag currently only covers the 'Restrict' policy. Verify if additional policy branches should also manage the drop_cap flag to ensure consistent behavior.
if access.settings.policy == SuPolicy::Restrict { req.drop_cap = true; }

native/src/core/lib.rs:87

  • Ensure that the new SuPolicy::Restrict variant is handled in all pattern matching expressions and related logic throughout the codebase to avoid potential runtime issues.
Restrict,

@yujincheng08 yujincheng08 requested a review from Copilot April 10, 2025 05:36
Copy link

@Copilot 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.

Copilot reviewed 15 out of 19 changed files in this pull request and generated no comments.

Files not reviewed (4)
  • app/apk/src/main/res/layout/item_log_access_md2.xml: Language not supported
  • app/apk/src/main/res/layout/item_policy_md2.xml: Language not supported
  • app/core/src/main/res/values-zh-rCN/strings.xml: Language not supported
  • app/core/src/main/res/values/strings.xml: Language not supported
Comments suppressed due to low confidence (3)

native/src/core/su/su.cpp:275

  • Consider checking the return value of prctl(PR_CAPBSET_DROP, cap) to ensure that capability dropping succeeds, and handle any failures accordingly.
prctl(PR_CAPBSET_DROP, cap);

native/src/core/selinux.cpp:122

  • Verify that setting MAGISKDB permissions to 0000 is intended and will not unintentionally block required access in later operations.
chmod(MAGISKDB, 0000);

native/src/base/misc.cpp:189

  • Ensure that using a 32-bit return type for hex parsing is safe in all contexts and that no hex values exceeding 32 bits are expected.
uint32_t parse_uint32_hex(string_view s) {

Copy link

@Copilot 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 adds support for dropping Linux capabilities while also introducing a new "restrict" policy in both native and Android code. Key changes include:

  • Adding the new MAGISKDB constant and applying secure permission restrictions.
  • Implementing drop-capability logic in the native SU command and updating command-line options.
  • Updating Android models, views, and data binding to support the new policy states.

Reviewed Changes

Copilot reviewed 16 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
native/src/include/consts.rs Added MAGISKDB constant for database path handling.
native/src/core/su/su.cpp Implemented drop-capability logic and updated command-line parsing.
native/src/core/selinux.rs Applied secure permissions to MAGISKDB after restorecon.
native/src/core/lib.rs Expanded SuRequest with new drop_cap field.
native/src/base/misc.hpp & misc.cpp Added support for parsing hexadecimal capability values.
app/core/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt Updated response logic to handle restrict policy when configured.
app/core/src/main/java/com/topjohnwu/magisk/ui/superuser/* Renamed and refactored methods to support updated policy handling.
app/core/src/main/java/com/topjohnwu/magisk/core/model/su/SuPolicy.kt Updated SuPolicy constants to include new states.
app/core/src/main/java/com/topjohnwu/magisk/core/Config.kt Added configuration support for SU restrict.
app/apk/src/main/java/com/topjohnwu/magisk/ui/* Updated settings and UI binding adapters to support enhanced policy updates.
Files not reviewed (4)
  • app/apk/src/main/res/layout/item_log_access_md2.xml: Language not supported
  • app/apk/src/main/res/layout/item_policy_md2.xml: Language not supported
  • app/core/src/main/res/values-zh-rCN/strings.xml: Language not supported
  • app/core/src/main/res/values/strings.xml: Language not supported
Comments suppressed due to low confidence (1)

app/apk/src/main/java/com/topjohnwu/magisk/databinding/DataBindingAdapters.kt:330

  • [nitpick] The function name 'policyToSliderValve' appears to be a typo; consider renaming it to 'policyToSliderValue' for consistency with related naming conventions.
fun policyToSliderValve(policy: Int): Float {

@@ -70,6 +70,7 @@ pub(crate) fn restorecon() {
path.clear();
path.push_str(DATABIN);
restore_syscon(&mut path).log_ok();
unsafe { libc::chmod(cstr!(MAGISKDB).as_ptr(), 0o000) };
Copy link
Preview

Copilot AI May 6, 2025

Choose a reason for hiding this comment

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

Consider adding error handling for the chmod call on MAGISKDB to log or manage failures, as a silent failure could complicate debugging.

Suggested change
unsafe { libc::chmod(cstr!(MAGISKDB).as_ptr(), 0o000) };
let chmod_result = unsafe { libc::chmod(cstr!(MAGISKDB).as_ptr(), 0o000) };
if chmod_result != 0 {
eprintln!("Failed to change permissions for MAGISKDB: {}", std::io::Error::last_os_error());
}

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next Planned for the release *after* the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants