From c7eefc66f942e1e0a6685fc6cee716c1591310d1 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Tue, 12 Sep 2017 20:45:50 +0200 Subject: [PATCH 01/10] test helloworld syscall, not working --- Makefile | 2 +- arch/arm/include/uapi/asm/unistd.h | 1 + arch/arm/kernel/calls.S | 1 + helloworld/Kconfig | 4 ++++ helloworld/Makefile | 1 + helloworld/helloworld.c | 8 ++++++++ include/linux/syscalls.h | 1 + kernel/sys_ni.c | 2 ++ 8 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 helloworld/Kconfig create mode 100644 helloworld/Makefile create mode 100644 helloworld/helloworld.c diff --git a/Makefile b/Makefile index cfa188b427b1dd..4c288c0ee1fcbf 100644 --- a/Makefile +++ b/Makefile @@ -913,7 +913,7 @@ export mod_sign_cmd ifeq ($(KBUILD_EXTMOD),) -core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ +core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ helloworld/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ diff --git a/arch/arm/include/uapi/asm/unistd.h b/arch/arm/include/uapi/asm/unistd.h index 314100a06ccb6c..f9f5f90076bd16 100644 --- a/arch/arm/include/uapi/asm/unistd.h +++ b/arch/arm/include/uapi/asm/unistd.h @@ -423,6 +423,7 @@ #define __NR_pkey_mprotect (__NR_SYSCALL_BASE+394) #define __NR_pkey_alloc (__NR_SYSCALL_BASE+395) #define __NR_pkey_free (__NR_SYSCALL_BASE+396) +#define __NR_helloworld (__NR_SYSCALL_BASE+397) /* * The following SWIs are ARM private. diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S index 08030b18f10a3b..1326ee4ebbcdcf 100644 --- a/arch/arm/kernel/calls.S +++ b/arch/arm/kernel/calls.S @@ -406,6 +406,7 @@ CALL(sys_pkey_mprotect) /* 395 */ CALL(sys_pkey_alloc) CALL(sys_pkey_free) + CALL(sys_helloworld) #ifndef syscalls_counted .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls #define syscalls_counted diff --git a/helloworld/Kconfig b/helloworld/Kconfig new file mode 100644 index 00000000000000..5315b1ef956804 --- /dev/null +++ b/helloworld/Kconfig @@ -0,0 +1,4 @@ +config MYSERVICE + bool "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + default y + \ No newline at end of file diff --git a/helloworld/Makefile b/helloworld/Makefile new file mode 100644 index 00000000000000..d900514ceac6d1 --- /dev/null +++ b/helloworld/Makefile @@ -0,0 +1 @@ +obj-y := helloworld.o diff --git a/helloworld/helloworld.c b/helloworld/helloworld.c new file mode 100644 index 00000000000000..61f03726fc2a29 --- /dev/null +++ b/helloworld/helloworld.c @@ -0,0 +1,8 @@ +#include +#include + +SYSCALL_DEFINE0(helloworld) +{ + printk("helloworld\n"); + return 0; +} diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 91a740f6b88423..b4efe74a0fa186 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -902,5 +902,6 @@ asmlinkage long sys_pkey_mprotect(unsigned long start, size_t len, unsigned long prot, int pkey); asmlinkage long sys_pkey_alloc(unsigned long flags, unsigned long init_val); asmlinkage long sys_pkey_free(int pkey); +asmlinkage long sys_helloworld(void); #endif diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 635482e60ca39f..d148fc547c9e25 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -255,3 +255,5 @@ cond_syscall(sys_membarrier); cond_syscall(sys_pkey_mprotect); cond_syscall(sys_pkey_alloc); cond_syscall(sys_pkey_free); + +cond_syscall(sys_helloworld); From 97b7d30d0cc004f91898dad65ec400acc2baadf9 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Wed, 13 Sep 2017 19:23:23 +0200 Subject: [PATCH 02/10] still not working --- Makefile | 2 +- helloworld/Kconfig | 4 ---- helloworld/Makefile | 1 - include/linux/helloworld.h | 6 ++++++ include/uapi/asm-generic/unistd.h | 4 +++- init/Kconfig | 1 + kernel/Kconfig.helloworld | 3 +++ kernel/Makefile | 2 ++ {helloworld => kernel}/helloworld.c | 1 + 9 files changed, 17 insertions(+), 7 deletions(-) delete mode 100644 helloworld/Kconfig delete mode 100644 helloworld/Makefile create mode 100644 include/linux/helloworld.h create mode 100644 kernel/Kconfig.helloworld rename {helloworld => kernel}/helloworld.c (80%) diff --git a/Makefile b/Makefile index 4c288c0ee1fcbf..cfa188b427b1dd 100644 --- a/Makefile +++ b/Makefile @@ -913,7 +913,7 @@ export mod_sign_cmd ifeq ($(KBUILD_EXTMOD),) -core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ helloworld/ +core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ diff --git a/helloworld/Kconfig b/helloworld/Kconfig deleted file mode 100644 index 5315b1ef956804..00000000000000 --- a/helloworld/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -config MYSERVICE - bool "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - default y - \ No newline at end of file diff --git a/helloworld/Makefile b/helloworld/Makefile deleted file mode 100644 index d900514ceac6d1..00000000000000 --- a/helloworld/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-y := helloworld.o diff --git a/include/linux/helloworld.h b/include/linux/helloworld.h new file mode 100644 index 00000000000000..60ef9fb372e4ed --- /dev/null +++ b/include/linux/helloworld.h @@ -0,0 +1,6 @@ +#ifndef _LINUX_HELLOWORLD_H +#define _LINUX_HELLOWORLD_H + + + +#endif /* _LINUX_HELLOWORLD_H */ diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 9b1462e38b821a..09631535347c79 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -730,9 +730,11 @@ __SYSCALL(__NR_pkey_mprotect, sys_pkey_mprotect) __SYSCALL(__NR_pkey_alloc, sys_pkey_alloc) #define __NR_pkey_free 290 __SYSCALL(__NR_pkey_free, sys_pkey_free) +#define __NR_helloworld 291 +__SYSCALL(__NR_helloworld, sys_helloworld) #undef __NR_syscalls -#define __NR_syscalls 291 +#define __NR_syscalls 292 /* * All syscalls below here should go away really, diff --git a/init/Kconfig b/init/Kconfig index 34407f15e6d34d..b87275d9856931 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2128,3 +2128,4 @@ config ASN1 functions to call on what tags. source "kernel/Kconfig.locks" +source "kernel/Kconfig.helloworld" \ No newline at end of file diff --git a/kernel/Kconfig.helloworld b/kernel/Kconfig.helloworld new file mode 100644 index 00000000000000..ef1e8af6ca9a42 --- /dev/null +++ b/kernel/Kconfig.helloworld @@ -0,0 +1,3 @@ +config HELLOWORLD + bool "HELLOWORLD" + default y \ No newline at end of file diff --git a/kernel/Makefile b/kernel/Makefile index 314e7d62f5f0a3..90a3272ca1f294 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -114,6 +114,8 @@ obj-$(CONFIG_MEMBARRIER) += membarrier.o obj-$(CONFIG_HAS_IOMEM) += memremap.o +obj-$(CONFIG_HELLOWORLD) += helloworld.o + $(obj)/configs.o: $(obj)/config_data.h # config_data.h contains the same information as ikconfig.h but gzipped. diff --git a/helloworld/helloworld.c b/kernel/helloworld.c similarity index 80% rename from helloworld/helloworld.c rename to kernel/helloworld.c index 61f03726fc2a29..1855b4c7fbe4b0 100644 --- a/helloworld/helloworld.c +++ b/kernel/helloworld.c @@ -1,5 +1,6 @@ #include #include +#include SYSCALL_DEFINE0(helloworld) { From 17c6f48dedf7af8c726f8c4a37759ec3d84d212b Mon Sep 17 00:00:00 2001 From: pajasson <1982konig@gmail.com> Date: Fri, 15 Sep 2017 05:37:45 +0200 Subject: [PATCH 03/10] =?UTF-8?q?den=20verkar=20lista=20upp=20siffror=20ia?= =?UTF-8?q?f=20som=20jag=20inte=20hunnit=20kolla...och=20att=20filtrera=20?= =?UTF-8?q?efter=20currentuser=20fors=C3=A4tter=20att=20vara=20ett=20myste?= =?UTF-8?q?rium?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arch/arm/include/uapi/asm/unistd.h | 3 +- arch/arm/kernel/calls.S | 1 + include/linux/syscalls.h | 1 + init/Kconfig | 3 +- kernel/Kconfig.processInfo | 3 ++ kernel/Makefile | 1 + kernel/processInfo.c | 48 ++++++++++++++++++++++++++++++ kernel/processInfo.h | 2 ++ kernel/sys_ni.c | 1 + 9 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 kernel/Kconfig.processInfo create mode 100644 kernel/processInfo.c create mode 100644 kernel/processInfo.h diff --git a/arch/arm/include/uapi/asm/unistd.h b/arch/arm/include/uapi/asm/unistd.h index f9f5f90076bd16..8bc31b2f09ee93 100644 --- a/arch/arm/include/uapi/asm/unistd.h +++ b/arch/arm/include/uapi/asm/unistd.h @@ -423,7 +423,8 @@ #define __NR_pkey_mprotect (__NR_SYSCALL_BASE+394) #define __NR_pkey_alloc (__NR_SYSCALL_BASE+395) #define __NR_pkey_free (__NR_SYSCALL_BASE+396) -#define __NR_helloworld (__NR_SYSCALL_BASE+397) +#define __NR_helloworld (__NR_SYSCALL_BASE+397) +#define __NR_processInfo (__NR_SYSCALL_BASE+398) /* * The following SWIs are ARM private. diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S index 1326ee4ebbcdcf..9ee1ef8f24346f 100644 --- a/arch/arm/kernel/calls.S +++ b/arch/arm/kernel/calls.S @@ -407,6 +407,7 @@ /* 395 */ CALL(sys_pkey_alloc) CALL(sys_pkey_free) CALL(sys_helloworld) + CALL(sys_processInfo) #ifndef syscalls_counted .equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls #define syscalls_counted diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index b4efe74a0fa186..b4bd5acc00f8a2 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -903,5 +903,6 @@ asmlinkage long sys_pkey_mprotect(unsigned long start, size_t len, asmlinkage long sys_pkey_alloc(unsigned long flags, unsigned long init_val); asmlinkage long sys_pkey_free(int pkey); asmlinkage long sys_helloworld(void); +asmlinkage long sys_processInfo(void); #endif diff --git a/init/Kconfig b/init/Kconfig index b87275d9856931..be938866e31188 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2128,4 +2128,5 @@ config ASN1 functions to call on what tags. source "kernel/Kconfig.locks" -source "kernel/Kconfig.helloworld" \ No newline at end of file +source "kernel/Kconfig.helloworld" +source "kernel/Kconfig.processInfo" diff --git a/kernel/Kconfig.processInfo b/kernel/Kconfig.processInfo new file mode 100644 index 00000000000000..e547b5bb3c9693 --- /dev/null +++ b/kernel/Kconfig.processInfo @@ -0,0 +1,3 @@ +config PROCESSINFO + bool "PROCESSINFO" + default y diff --git a/kernel/Makefile b/kernel/Makefile index 90a3272ca1f294..2527f1ec515e48 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -115,6 +115,7 @@ obj-$(CONFIG_MEMBARRIER) += membarrier.o obj-$(CONFIG_HAS_IOMEM) += memremap.o obj-$(CONFIG_HELLOWORLD) += helloworld.o +obj-$(CONFIG_PROCESSINFO) += processInfo.o $(obj)/configs.o: $(obj)/config_data.h diff --git a/kernel/processInfo.c b/kernel/processInfo.c new file mode 100644 index 00000000000000..431dd3b75a6e55 --- /dev/null +++ b/kernel/processInfo.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +#include "processInfo.h" + +asmlinkage long sys_processInfo(void) { + + struct task_struct *proces; + int processes = 0; + int fd = 0; + int pending = 0; + + for_each_process(proces) { + + //if(proces->parent->uid == (unsigned short)sys_getuid()){ + pending = pending + proces->signal->sigcnt.counter; + fd = fd + proces->files->count.counter; + processes++; + + //} + + + + } + printk("\nThe current user has:\n%d processes running\n%dfiledescriptors watched\n%dsignals pendning\n", processes, fd, pending); + + + + + + + return 0; +} + + +/*unsigned int bitCount (unsigned long value) { + unsigned int count = 0; + while (value > 0) { // until all bits are zero + if ((value & 1) == 1) // check lower bit + count++; + value >>= 1; // shift bits, removing lower bit + } + return count; +}*/ + diff --git a/kernel/processInfo.h b/kernel/processInfo.h new file mode 100644 index 00000000000000..c42956a69732f7 --- /dev/null +++ b/kernel/processInfo.h @@ -0,0 +1,2 @@ +asmlinkage long sys_processInfo(void); +//unsigned int bitCount (struct signal_struct* value); diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index d148fc547c9e25..9621265fc43255 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -257,3 +257,4 @@ cond_syscall(sys_pkey_alloc); cond_syscall(sys_pkey_free); cond_syscall(sys_helloworld); +cond_syscall(sys_processInfo); From be10cce18d016f092a85436a7d727912c7ea4bf0 Mon Sep 17 00:00:00 2001 From: pajasson <1982konig@gmail.com> Date: Fri, 15 Sep 2017 19:12:15 +0200 Subject: [PATCH 04/10] =?UTF-8?q?kollar=20mot=20id=20nu.=20task=5Fuid=20ta?= =?UTF-8?q?r=20fram=20en=20kuid=5Ft=20struct=20som=20man=20sen=20kan=20plo?= =?UTF-8?q?cka=20v=C3=A4rdet=20av=20med=20=5F=5Fkuid=5Fvalfunktionen.=20en?= =?UTF-8?q?ligt=20n=C3=A5n=20random=20p=C3=A5=20internet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {kernel => include/linux}/processInfo.h | 0 kernel/processInfo.c | 7 +++---- 2 files changed, 3 insertions(+), 4 deletions(-) rename {kernel => include/linux}/processInfo.h (100%) diff --git a/kernel/processInfo.h b/include/linux/processInfo.h similarity index 100% rename from kernel/processInfo.h rename to include/linux/processInfo.h diff --git a/kernel/processInfo.c b/kernel/processInfo.c index 431dd3b75a6e55..7103cffc4046f9 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -3,8 +3,7 @@ #include #include #include - -#include "processInfo.h" +#include asmlinkage long sys_processInfo(void) { @@ -15,12 +14,12 @@ asmlinkage long sys_processInfo(void) { for_each_process(proces) { - //if(proces->parent->uid == (unsigned short)sys_getuid()){ + if(__kuid_val(task_uid(proces)) == (uid_t)sys_getuid()){ pending = pending + proces->signal->sigcnt.counter; fd = fd + proces->files->count.counter; processes++; - //} + } From 364f1017b7d0c7b0138e47aabcc14c64612aef99 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Sat, 16 Sep 2017 01:11:04 +0200 Subject: [PATCH 05/10] implemented pending signals - compiles --- kernel/processInfo.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/kernel/processInfo.c b/kernel/processInfo.c index 7103cffc4046f9..59e6392683758d 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -4,6 +4,7 @@ #include #include #include +#include asmlinkage long sys_processInfo(void) { @@ -11,20 +12,30 @@ asmlinkage long sys_processInfo(void) { int processes = 0; int fd = 0; int pending = 0; + int bitmask; + + printk("My user Id: %ld\n", sys_getuid()); for_each_process(proces) { - if(__kuid_val(task_uid(proces)) == (uid_t)sys_getuid()){ - pending = pending + proces->signal->sigcnt.counter; - fd = fd + proces->files->count.counter; - processes++; - + if(__kuid_val(task_uid(proces)) == (uid_t)sys_getuid()){ + //pending = pending + proces->signal->sigcnt.counter; + fd = fd + proces->files->count.counter; + processes++; + bitmask = *proces->pending.signal.sig; + + + while (bitmask > 0) { // until all bits are zero + if ((bitmask & 1) == 1) // check lower bit + pending++; + bitmask >>= 1; // shift bits, removing lower bit + } + + } + } - - - } - printk("\nThe current user has:\n%d processes running\n%dfiledescriptors watched\n%dsignals pendning\n", processes, fd, pending); + printk("\nThe current user has:\n%d processes running\n%d filedescriptors watched\n%d signals pendning\n", processes, fd, pending); From 0b80c650712943c91dda82ea48994926e346833f Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Sat, 16 Sep 2017 08:06:58 +0200 Subject: [PATCH 06/10] number of watched fds or files implemented --- kernel/processInfo.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/processInfo.c b/kernel/processInfo.c index 59e6392683758d..07cac37ac609ae 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -19,8 +19,8 @@ asmlinkage long sys_processInfo(void) { for_each_process(proces) { if(__kuid_val(task_uid(proces)) == (uid_t)sys_getuid()){ - //pending = pending + proces->signal->sigcnt.counter; - fd = fd + proces->files->count.counter; + + fd = fd + *proces->files->fdtab.open_fds; processes++; bitmask = *proces->pending.signal.sig; @@ -30,7 +30,6 @@ asmlinkage long sys_processInfo(void) { pending++; bitmask >>= 1; // shift bits, removing lower bit } - } } From 120a2c5f4239efa62f332d6f7837fdb59530690c Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Sat, 16 Sep 2017 13:49:57 +0200 Subject: [PATCH 07/10] fixed the signal reporting --- include/linux/processInfo.h | 5 ++++- kernel/processInfo.c | 38 +++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/linux/processInfo.h b/include/linux/processInfo.h index c42956a69732f7..8e9fd385785950 100644 --- a/include/linux/processInfo.h +++ b/include/linux/processInfo.h @@ -1,2 +1,5 @@ + asmlinkage long sys_processInfo(void); -//unsigned int bitCount (struct signal_struct* value); + +int bitmaskSum(int bitmask); + diff --git a/kernel/processInfo.c b/kernel/processInfo.c index 07cac37ac609ae..1e80135a20e752 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -12,7 +12,8 @@ asmlinkage long sys_processInfo(void) { int processes = 0; int fd = 0; int pending = 0; - int bitmask; + int bitmaskShared; + int bitmaskPrivate; printk("My user Id: %ld\n", sys_getuid()); @@ -22,36 +23,31 @@ asmlinkage long sys_processInfo(void) { fd = fd + *proces->files->fdtab.open_fds; processes++; - bitmask = *proces->pending.signal.sig; + bitmaskShared = *proces->signal->shared_pending.signal.sig; + bitmaskPrivate = *proces->pending.signal.sig; + pending = pending + bitmaskSum(bitmaskShared); + pending = pending + bitmaskSum(bitmaskPrivate); - while (bitmask > 0) { // until all bits are zero - if ((bitmask & 1) == 1) // check lower bit - pending++; - bitmask >>= 1; // shift bits, removing lower bit - } } } printk("\nThe current user has:\n%d processes running\n%d filedescriptors watched\n%d signals pendning\n", processes, fd, pending); - - - - - return 0; } +int bitmaskSum(int bitmask){ + int sum = 0; + + while (bitmask > 0) { + if ((bitmask & 1) == 1) + sum++; + bitmask >>= 1; + } + + return sum; +} -/*unsigned int bitCount (unsigned long value) { - unsigned int count = 0; - while (value > 0) { // until all bits are zero - if ((value & 1) == 1) // check lower bit - count++; - value >>= 1; // shift bits, removing lower bit - } - return count; -}*/ From c1b087c91c9cd8dddf84a00cf189f0559bf037a1 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Sat, 16 Sep 2017 15:23:18 +0200 Subject: [PATCH 08/10] first draft, compiles --- include/linux/processInfo.h | 6 +++++- include/linux/syscalls.h | 2 +- kernel/processInfo.c | 29 ++++++++++++++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/linux/processInfo.h b/include/linux/processInfo.h index 8e9fd385785950..b9762e6a60a006 100644 --- a/include/linux/processInfo.h +++ b/include/linux/processInfo.h @@ -1,5 +1,9 @@ +#ifndef _LINUX_PROCESSINFO_H +#define _LINUX_PROCESSINFO_H -asmlinkage long sys_processInfo(void); +asmlinkage long sys_processInfo(int* buf, int size); int bitmaskSum(int bitmask); + +#endif /* _LINUX_PROCESSINFO_H */ diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index b4bd5acc00f8a2..e40e0bb36f70b8 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -903,6 +903,6 @@ asmlinkage long sys_pkey_mprotect(unsigned long start, size_t len, asmlinkage long sys_pkey_alloc(unsigned long flags, unsigned long init_val); asmlinkage long sys_pkey_free(int pkey); asmlinkage long sys_helloworld(void); -asmlinkage long sys_processInfo(void); +asmlinkage long sys_processInfo(int* buf, int size); #endif diff --git a/kernel/processInfo.c b/kernel/processInfo.c index 1e80135a20e752..d7ca649f083b78 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -1,12 +1,12 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -asmlinkage long sys_processInfo(void) { +SYSCALL_DEFINE2(processInfo, int*, buf, int, size) { struct task_struct *proces; int processes = 0; @@ -15,7 +15,12 @@ asmlinkage long sys_processInfo(void) { int bitmaskShared; int bitmaskPrivate; - printk("My user Id: %ld\n", sys_getuid()); + + int buffers_in_kernel[size]; + //int *user_pointers[size]; + //int i; + //unsigned long res; + for_each_process(proces) { @@ -32,6 +37,16 @@ asmlinkage long sys_processInfo(void) { } } + + buffers_in_kernel[0] = processes; + buffers_in_kernel[1] = fd; + buffers_in_kernel[2] = pending; + /* + res = copy_from_user(user_pointers, buf, sizeof(user_pointers[size])); + + for (i = 0; i < size; i++) { + res = copy_to_user(user_pointers[i], &buffers_in_kernel[i], sizeof(int)); + }*/ printk("\nThe current user has:\n%d processes running\n%d filedescriptors watched\n%d signals pendning\n", processes, fd, pending); From c30ace86665e4498b10a7b20453a9f9a6e2b0277 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Sun, 17 Sep 2017 13:42:06 +0200 Subject: [PATCH 09/10] works without using SYSCALL_DEFINE --- include/linux/processInfo.h | 3 ++- include/linux/syscalls.h | 2 +- kernel/processInfo.c | 20 ++++---------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/include/linux/processInfo.h b/include/linux/processInfo.h index b9762e6a60a006..105d85e21eb15b 100644 --- a/include/linux/processInfo.h +++ b/include/linux/processInfo.h @@ -1,7 +1,8 @@ #ifndef _LINUX_PROCESSINFO_H #define _LINUX_PROCESSINFO_H -asmlinkage long sys_processInfo(int* buf, int size); + +asmlinkage long sys_processInfo(int* procs, int* fds, int* sigpends); int bitmaskSum(int bitmask); diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index e40e0bb36f70b8..0359e0cd8ff724 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -903,6 +903,6 @@ asmlinkage long sys_pkey_mprotect(unsigned long start, size_t len, asmlinkage long sys_pkey_alloc(unsigned long flags, unsigned long init_val); asmlinkage long sys_pkey_free(int pkey); asmlinkage long sys_helloworld(void); -asmlinkage long sys_processInfo(int* buf, int size); +asmlinkage long sys_processInfo(int*, int*, int*); #endif diff --git a/kernel/processInfo.c b/kernel/processInfo.c index d7ca649f083b78..eba6afa647af5d 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -6,7 +6,7 @@ #include #include -SYSCALL_DEFINE2(processInfo, int*, buf, int, size) { +asmlinkage long sys_processInfo(int* procs, int* fds, int* sigpends) { struct task_struct *proces; int processes = 0; @@ -16,12 +16,6 @@ SYSCALL_DEFINE2(processInfo, int*, buf, int, size) { int bitmaskPrivate; - int buffers_in_kernel[size]; - //int *user_pointers[size]; - //int i; - //unsigned long res; - - for_each_process(proces) { if(__kuid_val(task_uid(proces)) == (uid_t)sys_getuid()){ @@ -38,15 +32,9 @@ SYSCALL_DEFINE2(processInfo, int*, buf, int, size) { } - buffers_in_kernel[0] = processes; - buffers_in_kernel[1] = fd; - buffers_in_kernel[2] = pending; - /* - res = copy_from_user(user_pointers, buf, sizeof(user_pointers[size])); - - for (i = 0; i < size; i++) { - res = copy_to_user(user_pointers[i], &buffers_in_kernel[i], sizeof(int)); - }*/ + put_user(fd, procs); + put_user(pending, fds); + put_user(processes, sigpends); printk("\nThe current user has:\n%d processes running\n%d filedescriptors watched\n%d signals pendning\n", processes, fd, pending); From 350245c6f52e3c82f62cfbe35a410baa1d71e392 Mon Sep 17 00:00:00 2001 From: Lorenz Gerber Date: Sun, 17 Sep 2017 14:11:22 +0200 Subject: [PATCH 10/10] fixed everything --- kernel/processInfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/processInfo.c b/kernel/processInfo.c index eba6afa647af5d..a70722062fdf89 100644 --- a/kernel/processInfo.c +++ b/kernel/processInfo.c @@ -6,7 +6,7 @@ #include #include -asmlinkage long sys_processInfo(int* procs, int* fds, int* sigpends) { +SYSCALL_DEFINE3(processInfo, int*, procs, int*, fds, int*, sigpends) { struct task_struct *proces; int processes = 0;