Files
DroidDeck/tools/proot/patches/0012-fake_id0-identity-only.patch
T
2026-10-13 21:27:42 -04:00

104 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: DroidDeck <droiddeck@users.noreply.github.com>
Date: Tue, 29 Sep 2026 00:00:00 +0000
Subject: [PATCH] fake_id0: only trace the set*id and xattr calls when the ids
are PRoot's own
---
src/extension/fake_id0/config.h | 5 ++++
src/extension/fake_id0/fake_id0.c | 44 ++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/src/extension/fake_id0/config.h b/src/extension/fake_id0/config.h
index 2e78783..5227ced 100644
--- a/src/extension/fake_id0/config.h
+++ b/src/extension/fake_id0/config.h
@@ -2,6 +2,7 @@
#define FAKE_ID0_CONFIG_H
#include <sys/types.h> /* uid_t, gid_t */
+#include <stdbool.h>
typedef struct {
uid_t ruid;
@@ -15,6 +16,10 @@ typedef struct {
gid_t fsgid;
mode_t umask;
+
+
+
+ bool identity;
} Config;
#endif /* FAKE_ID0_CONFIG_H */
diff --git a/src/extension/fake_id0/fake_id0.c b/src/extension/fake_id0/fake_id0.c
index 9477f1c..fe08372 100644
--- a/src/extension/fake_id0/fake_id0.c
+++ b/src/extension/fake_id0/fake_id0.c
@@ -352,6 +352,40 @@ static FilteredSysnum filtered_sysnums[] = {
FILTERED_SYSNUM_END,
};
+
+
+
+
+
+
+
+
+
+
+
+static FilteredSysnum identity_sysnums[] = {
+ { PR_fsetxattr, FILTER_SYSEXIT },
+ { PR_lsetxattr, FILTER_SYSEXIT },
+ { PR_setfsgid, FILTER_SYSEXIT },
+ { PR_setfsgid32, FILTER_SYSEXIT },
+ { PR_setfsuid, FILTER_SYSEXIT },
+ { PR_setfsuid32, FILTER_SYSEXIT },
+ { PR_setgid, FILTER_SYSEXIT },
+ { PR_setgid32, FILTER_SYSEXIT },
+ { PR_setregid, FILTER_SYSEXIT },
+ { PR_setregid32, FILTER_SYSEXIT },
+ { PR_setresgid, FILTER_SYSEXIT },
+ { PR_setresgid32, FILTER_SYSEXIT },
+ { PR_setresuid, FILTER_SYSEXIT },
+ { PR_setresuid32, FILTER_SYSEXIT },
+ { PR_setreuid, FILTER_SYSEXIT },
+ { PR_setreuid32, FILTER_SYSEXIT },
+ { PR_setuid, FILTER_SYSEXIT },
+ { PR_setuid32, FILTER_SYSEXIT },
+ { PR_setxattr, FILTER_SYSEXIT },
+ FILTERED_SYSNUM_END,
+};
+
/**
* Restore the @node->mode for the given @node->path.
*
@@ -1051,6 +1085,11 @@ static int handle_sysexit_start(Tracee *tracee, Config *config) {
if ((int) result < 0 || tracee->status < 0 || sysnum != PR_execve)
return 0;
+
+
+ if (config->identity)
+ return 0;
+
/* This has to be done before PRoot pushes the load
* script into tracee's stack. */
if (!tracee->skip_proot_loader)
@@ -1119,7 +1158,10 @@ int fake_id0_callback(Extension *extension, ExtensionEvent event, intptr_t data1
/* Set the umask to the typical linux value. */
config->umask = 022;
- extension->filtered_sysnums = filtered_sysnums;
+ config->identity = (uid != 0 && uid == (int) getuid() && gid == (int) getgid());
+ extension->filtered_sysnums = config->identity
+ ? identity_sysnums
+ : filtered_sysnums;
return 0;
}