Skip to content

Commit

Permalink
add exclude supercall
Browse files Browse the repository at this point in the history
  • Loading branch information
bmax committed Oct 3, 2024
1 parent 9d90bf0 commit 67ab867
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 44 deletions.
10 changes: 5 additions & 5 deletions kernel/patch/common/sucompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static void su_handler_arg1_ufilename_before(hook_fargs6_t *args, void *udata)
}
}

int set_su_mod_exclude(uid_t uid, int exclude)
int set_ap_mod_exclude(uid_t uid, int exclude)
{
int rc = 0;
if (exclude) {
Expand All @@ -325,16 +325,16 @@ int set_su_mod_exclude(uid_t uid, int exclude)
}
return rc;
}
KP_EXPORT_SYMBOL(set_su_mod_exclude);
KP_EXPORT_SYMBOL(set_ap_mod_exclude);

int get_su_mod_exclude(uid_t uid)
int get_ap_mod_exclude(uid_t uid)
{
int exclude = 0;
int rc = read_kstorage(exclude_kstorage_gid, uid, &exclude, 0, sizeof(exclude), false);
if (rc < 0) return false;
if (rc < 0) return 0;
return exclude;
}
KP_EXPORT_SYMBOL(get_su_mod_exclude);
KP_EXPORT_SYMBOL(get_ap_mod_exclude);

int su_compat_init()
{
Expand Down
25 changes: 25 additions & 0 deletions kernel/patch/common/supercall.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <linux/random.h>
#include <sucompat.h>
#include <accctl.h>
#include <kstorage.h>

#define MAX_KEY_LEN 128

Expand Down Expand Up @@ -230,6 +231,21 @@ static long call_su_set_allow_sctx(char *__user usctx)
return set_all_allow_sctx(buf);
}

static long call_kstorage_read(int gid, long did, void *out_data, int offset, int dlen)
{
return read_kstorage(gid, did, out_data, offset, dlen, true);
}

static long call_kstorage_write(int gid, long did, void *data, int offset, int dlen)
{
return write_kstorage(gid, did, data, offset, dlen, true);
}

static long call_kstorage_remove(int gid, long did)
{
return remove_kstorage(gid, did);
}

static long supercall(int is_key_auth, long cmd, long arg1, long arg2, long arg3, long arg4)
{
switch (cmd) {
Expand Down Expand Up @@ -268,6 +284,15 @@ static long supercall(int is_key_auth, long cmd, long arg1, long arg2, long arg3
return call_su_get_allow_sctx((char *__user)arg1, (int)arg2);
case SUPERCALL_SU_SET_ALLOW_SCTX:
return call_su_set_allow_sctx((char *__user)arg1);

case SUPERCALL_KSTORAGE_READ:
return call_kstorage_read((int)arg1, (long)arg2, (void *)arg3, (int)((long)arg4 >> 32), (long)arg4 << 32 >> 32);
case SUPERCALL_KSTORAGE_WRITE:
return call_kstorage_write((int)arg1, (long)arg2, (void *)arg3, (int)((long)arg4 >> 32),
(long)arg4 << 32 >> 32);
case SUPERCALL_KSTORAGE_REMOVE:
return call_kstorage_remove((int)arg1, (long)arg2);

#ifdef ANDROID
case SUPERCALL_SU_GET_SAFEMODE:
return call_su_get_safemode();
Expand Down
6 changes: 3 additions & 3 deletions kernel/patch/common/supercmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ static void handle_cmd_sumgr(char **__user u_filename_p, const char **carr, char
return;
} else {
if (!carr[3]) {
int exclude = get_su_mod_exclude(uid);
int exclude = get_ap_mod_exclude(uid);
sprintf(buffer, "%d", exclude);
cmd_res->msg = buffer;
} else {
if (carr[3][0] == '0') {
set_su_mod_exclude(uid, 0);
set_ap_mod_exclude(uid, 0);
cmd_res->msg = "0";
} else {
set_su_mod_exclude(uid, 1);
set_ap_mod_exclude(uid, 1);
cmd_res->msg = "1";
}
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/patch/include/sucompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int su_allow_uid_profile(int is_user, uid_t uid, struct su_profile *profile);
int su_reset_path(const char *path);
const char *su_get_path();

int get_su_mod_exclude(uid_t uid);
int set_su_mod_exclude(uid_t uid, int exclude);
int get_ap_mod_exclude(uid_t uid);
int set_ap_mod_exclude(uid_t uid, int exclude);

#endif
118 changes: 84 additions & 34 deletions user/supercall.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,39 +121,89 @@ static inline long sc_su_task(const char *key, pid_t tid, struct su_profile *pro
return ret;
}

// /**
// * @brief
// *
// * @param key
// * @param gid group id
// * @param did data id
// * @param data
// * @param dlen
// * @return long
// */
// static inline long sc_kstorage_write(const char *key, int gid, long did, void *data, int offset, int dlen)
// {
// if (!key || !key[0]) return -EINVAL;
// long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_WRITE), gid, did, data, dlen);
// return ret;
// }

// /**
// * @brief
// *
// * @param key
// * @param gid
// * @param did
// * @param out_data
// * @param dlen
// * @return long
// */
// static inline long sc_kstorage_read(const char *key, int gid, long did, void *out_data, int offset, int dlen)
// {
// if (!key || !key[0]) return -EINVAL;
// long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_READ), gid, did, out_data, dlen);
// return ret;
// }
/**
* @brief
*
* @param key
* @param gid group id
* @param did data id
* @param data
* @param dlen
* @return long
*/
static inline long sc_kstorage_write(const char *key, int gid, long did, void *data, int offset, int dlen)
{
if (!key || !key[0]) return -EINVAL;
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_WRITE), gid, did, data, ((offset << 32) | dlen));
return ret;
}

/**
* @brief
*
* @param key
* @param gid
* @param did
* @param out_data
* @param dlen
* @return long
*/
static inline long sc_kstorage_read(const char *key, int gid, long did, void *out_data, int offset, int dlen)
{
if (!key || !key[0]) return -EINVAL;
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_READ), gid, did, out_data, ((offset << 32) | dlen));
return ret;
}

/**
* @brief
*
* @param key
* @param gid
* @param did
* @return long
*/
static inline long sc_kstorage_remove(const char *key, int gid, long did)
{
if (!key || !key[0]) return -EINVAL;
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_REMOVE), gid, did);
return ret;
}


/**
* @brief
*
* @param key
* @param uid
* @param exclude
* @return long
*/
static inline long sc_set_ap_mod_exclude(const char *key, uid_t uid, int exclude)
{
if(exclude) {
return sc_kstorage_write(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid, &exclude, 0, sizeof(exclude));
} else {
return sc_kstorage_remove(key, SUPERCALL_KSTORAGE_REMOVE, uid, gid);
}
}


/**
* @brief
*
* @param key
* @param uid
* @param exclude
* @return long
*/
static inline int sc_get_ap_mod_exclude(const char *key, uid_t uid)
{
int exclude = 0;
int rc = sc_kstorage_read(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid, &exclude, 0, sizeof(exclude));
if (rc < 0) return 0;
return exclude;
}

/**
* @brief Grant su permission
Expand Down Expand Up @@ -238,7 +288,7 @@ static inline long sc_su_uid_profile(const char *key, uid_t uid, struct su_profi
static inline long sc_su_get_path(const char *key, char *out_path, int path_len)
{
if (!key || !key[0]) return -EINVAL;
if (!out_path || out_path <= 0) return -EINVAL;
if (!out_path || path_len <= 0) return -EINVAL;
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_SU_GET_PATH), out_path, path_len);
return ret;
}
Expand Down

0 comments on commit 67ab867

Please sign in to comment.