Skip to content

Commit 7f13edf

Browse files
authored
building issues resolved for latest kernels (#308)
* build failure for CentOS (backported kernels) PDE_DATA was replaced by pde_data after 5.17rc, and the patch was backported to latest CentOS8 kernels Signed-off-by: shenping.matt <shenping.matt@bytedance.com> * build warnings resolved for latest kernels warnings reported when compiling for latest kernels (5.19.x and 6.0rc), since more strict boundary check of memory manupiluation are introduced Signed-off-by: shenping.matt <shenping.matt@bytedance.com> Signed-off-by: shenping.matt <shenping.matt@bytedance.com>
1 parent ebe7e6f commit 7f13edf

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

driver/LKM/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ ifeq ($(TRACE_EVENTS_HEADER_CHECK),$(TRACE_EVENTS_HEADER))
4444
ccflags-y += -D SMITH_TRACE_EVENTS
4545
endif
4646

47+
PROCFS_H_FILES := $(shell find -L $(K_I_PATH) -path "*/linux/proc_fs.h") /dev/null
48+
PROCFS_PDE_DATA := $(shell sh -c "grep -s pde_data $(PROCFS_H_FILES)")
49+
ifneq ($(PROCFS_PDE_DATA),)
50+
ccflags-y += -D SMITH_PROCFS_PDE_DATA
51+
endif
52+
4753
else
4854

4955
MODULE_DIR := $(shell pwd)

driver/LKM/src/anti_rootkit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static void analyze_modules(void)
175175
}
176176

177177
kobj = container_of(cur, struct module_kobject, kobj);
178-
if (kobj && kobj->mod && kobj->mod->name) {
178+
if (kobj && kobj->mod) {
179179
if (mod_find_module && !mod_find_module(kobj->mod->name))
180180
mod_print(kobj->mod->name);
181181
}

driver/LKM/src/smith_hook.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ int connect_syscall_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
740740
dip6 = &(sk->sk_v6_daddr);
741741
sip6 = &(sk->sk_v6_rcv_saddr);
742742
sport = ntohs(inet->inet_sport);
743-
dport = ntohs(((struct sockaddr_in6 *)&tmp_dirp)->sin6_port);
743+
dport = ntohs(((struct sockaddr_in *)&tmp_dirp)->sin_port);
744744
if(dport == 0)
745745
dport = ntohs(inet->inet_dport);
746746
flag = 1;
@@ -751,7 +751,7 @@ int connect_syscall_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
751751
dip6 = &(inet->pinet6->daddr);
752752
sip6 = &(inet->pinet6->saddr);
753753
sport = ntohs(inet->inet_sport);
754-
dport = ntohs(((struct sockaddr_in6 *)&tmp_dirp)->sin6_port);
754+
dport = ntohs(((struct sockaddr_in *)&tmp_dirp)->sin_port);
755755
if(dport)
756756
dport = ntohs(inet->inet_dport);
757757
flag = 1;
@@ -762,7 +762,7 @@ int connect_syscall_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
762762
dip6 = &(inet->pinet6->daddr);
763763
sip6 = &(inet->pinet6->saddr);
764764
sport = ntohs(inet->sport);
765-
dport = ntohs(((struct sockaddr_in6 *)&tmp_dirp)->sin6_port);
765+
dport = ntohs(((struct sockaddr_in *)&tmp_dirp)->sin_port);
766766
if(dport)
767767
dport = ntohs(inet->dport);
768768
flag = 1;

driver/LKM/src/trace.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int trace_open_pipe(struct inode *inode, struct file *filp)
6767
trace_seq_init(&iter->seq);
6868
mutex_init(&iter->mutex);
6969

70-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0)
70+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0) || defined(SMITH_PROCFS_PDE_DATA)
7171
iter->ring = pde_data(inode);
7272
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
7373
iter->ring = PDE_DATA(inode);
@@ -270,7 +270,8 @@ static ssize_t trace_read_pipe(struct file *filp, char __user * ubuf,
270270
if (cnt >= PAGE_SIZE)
271271
cnt = PAGE_SIZE - 1;
272272

273-
memset(&iter->seq, 0, sizeof(*iter) - offsetof(struct print_event_iterator, seq));
273+
memset((void *)iter + offsetof(struct print_event_iterator, seq), 0,
274+
sizeof(*iter) - offsetof(struct print_event_iterator, seq));
274275

275276
mutex_lock(&access_lock);
276277
while (trace_next_entry_inc(iter) != NULL) {

0 commit comments

Comments
 (0)