Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
bmax committed Mar 25, 2024
1 parent ab774a7 commit e067529
Show file tree
Hide file tree
Showing 79 changed files with 228 additions and 911 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,23 @@ jobs:
mv kpimg.elf kpimg.elf-android
cd ..
cd kpm-demo
cd hello
cd kpms
cd demo-hello
make
mv hello.kpm demo-hello.kpm
cd ../inlinehook
cd ../demo-inlinehook
make
mv inlinehook.kpm demo-inlinehook.kpm
cd ../syscallhook
cd ../demo-syscallhook
make
mv syscallhook.kpm demo-syscallhook.kpm
cd ../make-shamiko-happy
make
- name: Upload elf
uses: actions/upload-artifact@v3
with:
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/build_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ jobs:
mv kpimg.elf kpimg.elf-android
cd ..
cd kpm-demo
cd hello
cd kpms
cd demo-hello
make
mv hello.kpm demo-hello.kpm
cd ../inlinehook
cd ../demo-inlinehook
make
mv inlinehook.kpm demo-inlinehook.kpm
cd ../syscallhook
cd ../demo-syscallhook
make
mv syscallhook.kpm demo-syscallhook.kpm
cd ../make-shamiko-happy
make
- name: Upload elf
uses: actions/upload-artifact@v3
with:
Expand Down
29 changes: 29 additions & 0 deletions kernel/patch/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@
#include <predata.h>
#include <linux/ptrace.h>
#include <linux/err.h>
#include <linux/errno.h>

int kfunc_def(xt_data_to_user)(void __user *dst, const void *src, int usersize, int size, int aligned_size);

static inline int compat_xt_data_copy_to_user(void __user *dst, const void *src, int size)
{
kfunc_direct_call(xt_data_to_user, dst, src, size, size, size);
}

// todo: static method
int kfunc_def(bits_to_user)(unsigned long *bits, unsigned int maxbit, unsigned int maxlen, void __user *p, int compat);

static inline int compat_bits_copy_to_user(void __user *dst, const void *src, int size)
{
kfunc_direct_call(bits_to_user, src, size * sizeof(long), size, dst, 0);
}

// todo: n > page_size
int trace_seq_copy_to_user(void __user *to, const void *from, int n)
{
unsigned char trace_seq_data[page_size + 0x20];
Expand Down Expand Up @@ -42,14 +59,26 @@ int seq_buf_copy_to_user(void __user *to, const void *from, int n)
return seq_buf_to_user(&seq_buf, to, n);
}

// return copied length
int __must_check compat_copy_to_user(void __user *to, const void *from, int n)
{
int copy_len;
if (kfunc(seq_buf_to_user)) {
copy_len = seq_buf_copy_to_user((void *__user)to, from, n);
} else if (kfunc(bits_to_user)) {
// bits_to_user, str_to_user
// int ret = compat_bits_to_user(to, from, n);
// if (ret == n) return -EFAULT;
// copy_len -= ret;
} else if (kfunc(xt_data_to_user)) {
// xt_data_to_user, xt_obj_to_user
// int ret = compat_xt_data_copy_to_user(to, from, n);
// if (ret == n) return -EFAULT;
// copy_len -= ret;
} else {
copy_len = trace_seq_copy_to_user((void *__user)to, from, n);
}
// alt: copy_arg_to_user,
return copy_len;
}
KP_EXPORT_SYMBOL(compat_copy_to_user);
Expand Down
19 changes: 19 additions & 0 deletions kpms/make-shamiko-happy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Libraries
*.lib
*.a
*.la
*.lo

*.bin
*.elf

*.kpm
30 changes: 30 additions & 0 deletions kpms/make-shamiko-happy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ifndef TARGET_COMPILE
$(error TARGET_COMPILE not set)
endif

ifndef KP_DIR
KP_DIR = ../..
endif


CC = $(TARGET_COMPILE)gcc
LD = $(TARGET_COMPILE)ld

INCLUDE_DIRS := . include patch/include linux/include linux/arch/arm64/include linux/tools/arch/arm64/include

INCLUDE_FLAGS := $(foreach dir,$(INCLUDE_DIRS),-I$(KP_DIR)/kernel/$(dir))

objs := main.o

all: shamiko.kpm

shamiko.kpm: ${objs}
${CC} -r -o $@ $^

%.o: %.c
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -Thello.lds -c -O2 -o $@ $<

.PHONY: clean
clean:
rm -rf *.kpm
find . -name "*.o" | xargs rm -f
95 changes: 95 additions & 0 deletions kpms/make-shamiko-happy/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2023 bmax121. All Rights Reserved.
*/

#include <compiler.h>
#include <kpmodule.h>
#include <linux/printk.h>
#include <common.h>
#include <kputils.h>
#include <taskext.h>
#include <asm/current.h>
#include <hook.h>
#include <syscall.h>
#include <linux/sched.h>
#include <linux/cred.h>
#include <linux/string.h>

KPM_NAME("make-shamiko-happy");
KPM_VERSION("1.0.0");
KPM_LICENSE("GPL v2");
KPM_AUTHOR("bmax121");
KPM_DESCRIPTION("Tell Shamiko(0.7.4) that we're KernelSU, make it happy.");

void prctl_before(hook_fargs6_t *args, void *udata)
{
uint64_t option = syscall_argn(args, 0);
if (option != 0xDEADBEEF) return;

struct task_struct *task = current;

struct cred *cred = *(struct cred **)((uintptr_t)task + task_struct_offset.cred_offset);
uid_t uid = *(uid_t *)((uintptr_t)cred + cred_offset.euid_offset);

if (uid) return;

uint64_t cmd = syscall_argn(args, 1);
uint64_t arg2 = syscall_argn(args, 2);
uint64_t arg3 = syscall_argn(args, 3);
uint64_t arg4 = syscall_argn(args, 4);
uint64_t arg5 = syscall_argn(args, 5);

uint32_t reply_ok = 0xDEADBEEF;

pr_info("ksu prctl: %x, %x, %x, %x, %x, %x\n", option, cmd, arg2, arg3, arg4, arg5);

if (cmd == 2) {
uint32_t version = 11682;
int rc = compat_copy_to_user((void *)arg2, &version, 4);
printk("fake ksu version: %d, %d", version, rc);
} else if (cmd == 12 || cmd == 13) {
bool res;
if (cmd == 13) {
res = true;
printk("fake ksu unmount: uid: %d\n", arg2);
} else {
res = false;
printk("fake ksu allow: uid: %d\n", arg2);
}
compat_copy_to_user((void *)arg3, &res, sizeof(res));
compat_copy_to_user((void *)arg4, &reply_ok, sizeof(reply_ok));
} else {
}

args->ret = 0;
args->skip_origin = true;
}

static long do_init(const char *args, const char *event, void *__user reserved)
{
int rc = fp_hook_syscalln(__NR_prctl, 6, prctl_before, 0, 0);
pr_info("init rc: %d\n", rc);
return 0;
}

static long do_control0(const char *args, char *__user out_msg, int outlen)
{
return 0;
}

static long do_control1(void *a1, void *a2, void *a3)
{
return 0;
}

static long do_exit(void *__user reserved)
{
fp_unhook_syscall(__NR_prctl, prctl_before, 0);
return 0;
}

KPM_INIT(do_init);
KPM_CTL0(do_control0);
KPM_CTL1(do_control1);
KPM_EXIT(do_exit);
5 changes: 5 additions & 0 deletions kpms/make-shamiko-happy/main.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SECTIONS {
.plt (NOLOAD) : { BYTE(0) }
.init.plt (NOLOAD) : { BYTE(0) }
.text.ftrace_trampoline (NOLOAD) : { BYTE(0) }
}
7 changes: 0 additions & 7 deletions kpms/shmem/user/Cargo.lock

This file was deleted.

8 changes: 0 additions & 8 deletions kpms/shmem/user/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions kpms/shmem/user/src/main.rs

This file was deleted.

1 change: 0 additions & 1 deletion kpms/shmem/user/target/.rustc_info.json

This file was deleted.

1 change: 0 additions & 1 deletion kpms/shmem/user/target/.rustdoc_fingerprint.json

This file was deleted.

3 changes: 0 additions & 3 deletions kpms/shmem/user/target/CACHEDIR.TAG

This file was deleted.

Empty file.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Empty file.
Empty file.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Binary file removed kpms/shmem/user/target/debug/ushmem
Binary file not shown.
Empty file removed kpms/shmem/user/target/doc/.lock
Empty file.
1 change: 0 additions & 1 deletion kpms/shmem/user/target/doc/crates.js

This file was deleted.

2 changes: 0 additions & 2 deletions kpms/shmem/user/target/doc/help.html

This file was deleted.

5 changes: 0 additions & 5 deletions kpms/shmem/user/target/doc/search-index.js

This file was deleted.

2 changes: 0 additions & 2 deletions kpms/shmem/user/target/doc/settings.html

This file was deleted.

4 changes: 0 additions & 4 deletions kpms/shmem/user/target/doc/src-files.js

This file was deleted.

Loading

0 comments on commit e067529

Please sign in to comment.