Skip to content

Commit 41f9246

Browse files
committed
apd/manager: update to match KP's kstorage read/write
This commit is an extension of bmax121/KernelPatch#256 which also update the "kstorage" methods to allow 32-bit userspace processes to utilize them.
1 parent 05984a6 commit 41f9246

3 files changed

Lines changed: 39 additions & 13 deletions

File tree

apd/src/supercall.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ struct SuProfile {
3636
scontext: [u8; SUPERCALL_SCONTEXT_LEN],
3737
}
3838

39+
#[repr(C)]
40+
struct DataItem {
41+
data: *mut c_void,
42+
dlen: i32,
43+
offset: i32,
44+
}
45+
3946
fn ver_and_cmd(cmd: c_long) -> c_long {
4047
let version_code: u32 = ((MAJOR << 16) + (MINOR << 8) + PATCH).try_into().unwrap();
4148
((version_code as c_long) << 32) | (0x1158 << 16) | (cmd & 0xFFFF)
@@ -73,9 +80,7 @@ fn sc_kstorage_write(
7380
key: &CStr,
7481
gid: i32,
7582
did: i64,
76-
data: *mut c_void,
77-
offset: i32,
78-
dlen: i32,
83+
data: &DataItem,
7984
) -> c_long {
8085
if key.to_bytes().is_empty() {
8186
return (-EINVAL).into();
@@ -88,19 +93,22 @@ fn sc_kstorage_write(
8893
gid as c_long,
8994
did as c_long,
9095
data,
91-
(((offset as i64) << 32) | (dlen as i64)) as c_long,
9296
) as c_long
9397
}
9498
}
9599

96100
fn sc_set_ap_mod_exclude(key: &CStr, uid: i64, exclude: i32) -> c_long {
101+
let data_item = DataItem {
102+
data: &exclude as *const i32 as *mut c_void,
103+
dlen: size_of::<i32>() as i32,
104+
offset: 0,
105+
};
106+
97107
sc_kstorage_write(
98108
key,
99109
KSTORAGE_EXCLUDE_LIST_GROUP,
100110
uid,
101-
&exclude as *const i32 as *mut c_void,
102-
0,
103-
size_of::<i32>() as i32,
111+
&data_item,
104112
)
105113
}
106114

app/src/main/cpp/supercall.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ static inline long sc_su_task(const char *key, pid_t tid, struct su_profile *pro
147147
* @param dlen
148148
* @return long
149149
*/
150-
static inline long sc_kstorage_write(const char *key, int gid, long did, void *data, int offset, int dlen)
150+
static inline long sc_kstorage_write(const char *key, int gid, long did, struct data_item *data)
151151
{
152152
if (!key || !key[0]) return -EINVAL;
153-
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_WRITE), gid, did, data, (((long)offset << 32) | dlen));
153+
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_WRITE), gid, did, data);
154154
return ret;
155155
}
156156

@@ -164,10 +164,10 @@ static inline long sc_kstorage_write(const char *key, int gid, long did, void *d
164164
* @param dlen
165165
* @return long
166166
*/
167-
static inline long sc_kstorage_read(const char *key, int gid, long did, void *out_data, int offset, int dlen)
167+
static inline long sc_kstorage_read(const char *key, int gid, long did, struct data_item *out_data)
168168
{
169169
if (!key || !key[0]) return -EINVAL;
170-
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_READ), gid, did, out_data, (((long)offset << 32) | dlen));
170+
long ret = syscall(__NR_supercall, key, ver_and_cmd(key, SUPERCALL_KSTORAGE_READ), gid, did, out_data);
171171
return ret;
172172
}
173173

@@ -216,7 +216,13 @@ static inline long sc_kstorage_remove(const char *key, int gid, long did)
216216
static inline long sc_set_ap_mod_exclude(const char *key, uid_t uid, int exclude)
217217
{
218218
if(exclude) {
219-
return sc_kstorage_write(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid, &exclude, 0, sizeof(exclude));
219+
struct data_item data_item = {
220+
.data = &exclude,
221+
.dlen = sizeof(exclude),
222+
.offset = 0,
223+
};
224+
225+
return sc_kstorage_write(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid, &data_item);
220226
} else {
221227
return sc_kstorage_remove(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid);
222228
}
@@ -234,7 +240,12 @@ static inline long sc_set_ap_mod_exclude(const char *key, uid_t uid, int exclude
234240
static inline int sc_get_ap_mod_exclude(const char *key, uid_t uid)
235241
{
236242
int exclude = 0;
237-
int rc = sc_kstorage_read(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid, &exclude, 0, sizeof(exclude));
243+
struct data_item data_item = {
244+
.data = &exclude,
245+
.dlen = sizeof(exclude),
246+
.offset = 0,
247+
};
248+
int rc = sc_kstorage_read(key, KSTORAGE_EXCLUDE_LIST_GROUP, uid, &data_item);
238249
if (rc < 0) return 0;
239250
return exclude;
240251
}

app/src/main/cpp/uapi/scdefs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ struct su_profile
7474
char scontext[SUPERCALL_SCONTEXT_LEN];
7575
};
7676

77+
struct data_item
78+
{
79+
void *data;
80+
int dlen;
81+
int offset;
82+
};
83+
7784
#ifdef ANDROID
7885
#define SH_PATH "/system/bin/sh"
7986
#define SU_PATH "/system/bin/kp"

0 commit comments

Comments
 (0)