cormander / tpe-lkm

Trusted Path Execution (TPE) Linux Kernel Module
Other
157 stars 55 forks source link

Can't compile on Debian/Devuan 8 #27

Open eagle1maledetto opened 6 years ago

eagle1maledetto commented 6 years ago

Hi,

I'm trying to compile on a 3.16.0-4-amd64 kernel, on an host with Devuan 8 (same kernel and issue on Debian 8).

# make
make -C /usr/src/linux-headers-3.16.0-4-amd64 M=/root/tpe-lkm modules
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
  CC [M]  /root/tpe-lkm/fopskit.o
In file included from /root/tpe-lkm/fopskit.c:2:0:
/root/tpe-lkm/fopskit.h:48:38: error: ‘FTRACE_OPS_FL_IPMODIFY’ undeclared here (not in a function)
   .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY, \
                                      ^
/root/tpe-lkm/fopskit.c:63:1: note: in expansion of macro ‘fopskit_hook_handler’
 fopskit_hook_handler(security_prepare_creds) {
 ^
/usr/src/linux-headers-3.16.0-4-common/scripts/Makefile.build:262: recipe for target '/root/tpe-lkm/fopskit.o' failed
make[4]: *** [/root/tpe-lkm/fopskit.o] Error 1
/usr/src/linux-headers-3.16.0-4-common/Makefile:1355: recipe for target '_module_/root/tpe-lkm' failed
make[3]: *** [_module_/root/tpe-lkm] Error 2
Makefile:181: recipe for target 'sub-make' failed
make[2]: *** [sub-make] Error 2
Makefile:8: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'
Makefile:24: recipe for target 'tpe.ko' failed
make: *** [tpe.ko] Error 2`

The CONFIG_FUNCTION_TRACER is enabled.

# cat .config |grep CONFIG_FUNCTION_TRACER
CONFIG_FUNCTION_TRACER=y

Any hint?

Gianluca

cormander commented 6 years ago

Finally got a chance to look at this today - my latest system is kernel 4.15.6 which compiles without issue, so it's likely a change to the upstream between 4.15 and 4.16 that I need to account for. Will have to build out a new VM to start testing this. Thanks for the report.

eagle1maledetto commented 6 years ago

Any news?

h-amine commented 6 years ago

you should prob. add the following lines in fopskit.c

ifndef FTRACE_OPS_FL_IPMODIFY

define FTRACE_OPS_FL_IPMODIFY 0

endif

eagle1maledetto commented 6 years ago

you should prob. add the following lines in fopskit.c

ifndef FTRACE_OPS_FL_IPMODIFY

define FTRACE_OPS_FL_IPMODIFY 0

endif

No luck

# make
make -C /usr/src/linux-headers-3.16.0-4-amd64 M=/root/tpe-lkm modules
make[1]: ingresso nella directory "/usr/src/linux-headers-3.16.0-4-amd64"
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
  CC [M]  /root/tpe-lkm/fopskit.o
  CC [M]  /root/tpe-lkm/tpe_core.o
  CC [M]  /root/tpe-lkm/tpe_module.o
In file included from /root/tpe-lkm/tpe_module.c:3:0:
/root/tpe-lkm/fopskit.h:48:38: error: ‘FTRACE_OPS_FL_IPMODIFY’ undeclared here (not in a function)
   .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY, \
                                      ^
/root/tpe-lkm/tpe_module.c:32:1: note: in expansion of macro ‘fopskit_hook_handler’
 fopskit_hook_handler(security_mmap_file) {
 ^

I've modified the file according to your suggestion:

# head -n 4 fopskit.c

#include "fopskit.h"
#ifndef FTRACE_OPS_FL_IPMODIFY
#define FTRACE_OPS_FL_IPMODIFY 0
#endif

Thank you

h-amine commented 6 years ago

Sorry, the modification should to be added in "fopskit.h" before this portion of code:

define fopskit_hook_handler(val) \

static void notrace fopskit_##val(unsigned long, unsigned long, \
    struct ftrace_ops *, struct pt_regs *); \
static struct ftrace_ops fops_##val __read_mostly = { \
    .func = fopskit_##val, \
    .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY, \
}; \
static void notrace fopskit_##val(unsigned long ip, unsigned long parent_ip, \
    struct ftrace_ops *fops, struct pt_regs *regs)
eagle1maledetto commented 6 years ago

@h-amine it worked like a charm! Now the module is built and loadable in the kernel.

When I load it I get this messages tho:

[39606818.901490] fopskit: fopskit_find_sym_addr() failed with return code -14 for fops_hook { name => selinux_enabled, addr => 0, found => 0, hooked => 0 } at fopskit_find_sym_addr() line 222 [39606818.907077] fopskit: fopskit_find_sym_addr() failed with return code -14 for fops_hook { name => selinux_disabled, addr => 0, found => 0, hooked => 0 } at fopskit_find_sym_addr() line 222 [39606818.907080] tpe: warning: cred->security was not remapped; the soften_mmap flag won't persist to child processes. [39606818.968566] tpe: added to kernel

Is another issue?

Thank you