Skip to content

Commit

Permalink
fix su list, opt user init
Browse files Browse the repository at this point in the history
  • Loading branch information
bmax committed Oct 6, 2024
1 parent 124f704 commit bce85b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion kernel/patch/android/gen/user_init.c
Original file line number Diff line number Diff line change
@@ -1 +1 @@
static const char user_init[] = "#!/bin/sh\n\nKPMS_DIR=\"/data/adb/ap/kpms/\"\nMAGISK_POLICY_PATH=\"/data/adb/ap/bin/magiskpolicy\"\nSUPERCMD=\"truncate\"\nMAGISK_SCTX=\"u:r:magisk:s0\"\nAPD_PATH=\"/data/adb/apd\"\n\nskey=\"$1\"\nevent=\"$2\"\n\nLOG_FILE=\"/dev/user_init_\"\"$event\"\".log\"\n\nexec >>$LOG_FILE 2>&1\n\nset -x\n\nload_modules() {\n for dir in \"$KPMS_DIR/*\"; do\n if [ ! -d \"$dir\" ]; then continue; fi\n if [ -e \"$dir/disable\" ]; then continue; fi\n main_sh=\"$dir/main.sh\"\n if [ -e \"$main_sh\" ]; then\n touch \"$dir/disable\"\n echo \"loading $dir/main.sh ...\"\n . \"$main_sh\"\n rm -f \"$dir/disable\"\n else\n echo \"Error: $main_sh not found in $dir\"\n fi\n done\n}\n\nhandle() {\n $SUPERCMD $skey event $event \"before\"\n case \"$event\" in\n \"early-init\" | \"init\" | \"late-init\") ;;\n \"post-fs-data\")\n $MAGISK_POLICY_PATH --magisk --live\n load_modules $skey $event\n $SUPERCMD $skey -Z $MAGISK_SCTX exec $APD_PATH -s $skey $event\n ;;\n \"services\")\n $SUPERCMD $skey -Z $MAGISK_SCTX exec $APD_PATH -s $skey $event\n ;;\n \"boot-completed\")\n $SUPERCMD $skey -Z $MAGISK_SCTX exec $APD_PATH -s $skey $event\n $SUPERCMD su -Z $MAGISK_SCTX exec $APD_PATH uid-listener &\n ;;\n *)\n echo \"unknown user_init event: $event\"\n ;;\n esac\n $SUPERCMD $skey event $event \"after\"\n}\n\nhandle\n";
static const char user_init[] = "#!/bin/sh\n\nKPMS_DIR=\"/data/adb/ap/kpms/\"\nMAGISK_POLICY_PATH=\"/data/adb/ap/bin/magiskpolicy\"\nSUPERCMD=\"truncate\"\nMAGISK_SCTX=\"u:r:magisk:s0\"\nAPD_PATH=\"/data/adb/apd\"\nDEV_LOG_DIR=\"/dev/user_init_log/\"\n\nskey=\"$1\"\nevent=\"$2\"\n\nmkdir -p \"$DEV_LOG_DIR\"\n\nLOG_FILE=\"$DEV_LOG_DIR\"\"$event\"\n\nexec >>$LOG_FILE 2>&1\n\nset -x\n\nload_modules() {\n for dir in \"$KPMS_DIR/*\"; do\n if [ ! -d \"$dir\" ]; then continue; fi\n if [ -e \"$dir/disable\" ]; then continue; fi\n main_sh=\"$dir/main.sh\"\n if [ -e \"$main_sh\" ]; then\n touch \"$dir/disable\"\n echo \"loading $dir/main.sh ...\"\n . \"$main_sh\"\n rm -f \"$dir/disable\"\n else\n echo \"Error: $main_sh not found in $dir\"\n fi\n done\n}\n\nhandle() {\n $SUPERCMD $skey event $event \"before\"\n case \"$event\" in\n \"early-init\" | \"init\" | \"late-init\") ;;\n \"post-fs-data\")\n $MAGISK_POLICY_PATH --magisk --live\n load_modules $skey $event\n $SUPERCMD $skey -Z $MAGISK_SCTX exec $APD_PATH -s $skey $event\n ;;\n \"services\")\n $SUPERCMD $skey -Z $MAGISK_SCTX exec $APD_PATH -s $skey $event\n ;;\n \"boot-completed\")\n $SUPERCMD $skey -Z $MAGISK_SCTX exec $APD_PATH -s $skey $event\n $SUPERCMD su -Z $MAGISK_SCTX exec $APD_PATH uid-listener &\n ;;\n *)\n echo \"unknown user_init event: $event\"\n ;;\n esac\n $SUPERCMD $skey event $event \"after\"\n}\n\nhandle\n";
5 changes: 4 additions & 1 deletion kernel/patch/android/user_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ MAGISK_POLICY_PATH="/data/adb/ap/bin/magiskpolicy"
SUPERCMD="truncate"
MAGISK_SCTX="u:r:magisk:s0"
APD_PATH="/data/adb/apd"
DEV_LOG_DIR="/dev/user_init_log/"

skey="$1"
event="$2"

LOG_FILE="/dev/user_init_""$event"".log"
mkdir -p "$DEV_LOG_DIR"

LOG_FILE="$DEV_LOG_DIR""$event"

exec >>$LOG_FILE 2>&1

Expand Down
8 changes: 4 additions & 4 deletions kernel/patch/android/userd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

#define ADB_FLODER "/data/adb/"
#define AP_DIR "/data/adb/ap/"
#define DEV_LOG_DIR "/dev/user_init_log/"
#define AP_BIN_DIR AP_DIR "bin/"
#define AP_LOG_DIR AP_DIR "log/"
#define AP_MAGISKPOLICY_PATH AP_BIN_DIR "magiskpolicy"
#define MAGISK_SCTX "u:r:magisk:s0"
#define USER_INIT_SH_PATH "/dev/user_init.sh"
#define USER_INIT_LOG "/dev/user_init*.log"

#include "gen/user_init.c"

Expand All @@ -62,9 +62,9 @@ static const char user_rc_data[] = { //
"on property:vold.decrypt=trigger_restart_framework\n"
" exec -- " SUPERCMD " su exec " USER_INIT_SH_PATH " %s services\n"
"on property:sys.boot_completed=1\n"
// " rm " REPLACE_RC_FILE "\n"
// " rm " USER_INIT_SH_PATH "\n"
// " rm " USER_INIT_LOG "\n"
" rm " REPLACE_RC_FILE "\n"
" rm " USER_INIT_SH_PATH "\n"
" mv -f " DEV_LOG_DIR AP_LOG_DIR "\n"
" exec -- " SUPERCMD " su exec " USER_INIT_SH_PATH " %s boot-completed\n"
""
};
Expand Down
20 changes: 11 additions & 9 deletions kernel/patch/common/sucompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,27 @@ static int allow_uids_cb(struct kstorage *kstorage, void *udata)
{
int is_user;
uid_t *out_uids;
int idx;
int out_num;
} *up = (typeof(up))udata;

struct su_profile *profile = (struct su_profile *)kstorage->data;
if (up->idx >= up->out_num) {
return -ENOBUFS;
}

int num = 0;
struct su_profile *profile = (struct su_profile *)kstorage->data;

if (up->is_user) {
int cprc = compat_copy_to_user(up->out_uids + num, &profile->uid, sizeof(uid_t));
logkfd("uid: %d\n", profile->uid);
int cprc = compat_copy_to_user(up->out_uids + up->idx, &profile->uid, sizeof(uid_t));
if (cprc <= 0) {
logkfd("compat_copy_to_user error: %d", cprc);
return cprc;
}
} else {
up->out_uids[num] = profile->uid;
up->out_uids[up->idx] = profile->uid;
}

num++;
up->idx++;

return 0;
}
Expand All @@ -125,8 +127,9 @@ int su_allow_uids(int is_user, uid_t *out_uids, int out_num)
{
int iu;
uid_t *up;
int un;
} udata = { is_user, out_uids, out_num };
int idx;
int out_num;
} udata = { is_user, out_uids, 0, out_num };
on_each_kstorage_elem(su_kstorage_gid, allow_uids_cb, &udata);
return rc;
}
Expand All @@ -150,7 +153,6 @@ int su_allow_uid_profile(int is_user, uid_t uid, struct su_profile *out_profile)
logkfd("compat_copy_to_user error: %d", rc);
goto out;
}
logkfd("%d %d %s\n", profile->uid, profile->to_uid, profile->scontext);
} else {
memcpy(out_profile, profile, sizeof(struct su_profile));
}
Expand Down

0 comments on commit bce85b1

Please sign in to comment.