forked from puppylinux-woof-CE/woof-CE
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
override clock_adjtime() with eBPF instead of ld.so.preload
- Loading branch information
Showing
14 changed files
with
94 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CFLAGS ?= -O2 -Wall -pedantic | ||
CLANG ?= clang | ||
LLVM_STRIP ?= llvm-strip | ||
LIBS = $(shell pkg-config --libs libbpf) | ||
PREFIX = /usr/local | ||
|
||
rtclock: rtclock.c rtclock.skel.h | ||
$(CC) $(CFLAGS) -o $@ $< $(LIBS) | ||
|
||
rtclock.skel.h: rtclock.bpf.o | ||
bpftool gen skeleton $< > $@ | ||
|
||
rtclock.bpf.o: rtclock.bpf.c | ||
$(CLANG) -g -O2 -Wall -target bpf -D__KERNEL__ -c $< -o $@ | ||
$(LLVM_STRIP) -g $@ | ||
|
||
install: rtclock | ||
install -D -m 755 $< $(DESTDIR)$(PREFIX)/bin/$< | ||
|
||
clean: | ||
rm -f rtclock rtclock.skel.h rtclock.bpf.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rtclock prevents connman from changing the hardware clock using eBPF, to prevent conflicts with other OSs running on the same machine that may save time in UTC rather than local time. | ||
|
||
When connman's clock_adjtime() calls get intercepted by rtclock, clock synchronization over NTP only sets the software clock. /etc/rc.d/rc.sysinit is responsible for synchronizing the software clock with RTC at boot time, so if RTC is set correctly (by another OS), the software clock will show the correct time even before network is ready. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
download() { | ||
: | ||
} | ||
|
||
build() { | ||
make install | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <vmlinux.h> | ||
|
||
#include <bpf/bpf_core_read.h> | ||
|
||
#define STA_UNSYNC 0x0040 | ||
|
||
char LICENSE[] SEC("license") = "GPL"; | ||
|
||
SEC("tracepoint/syscalls/sys_enter_clock_adjtime") | ||
int override_clock_adjtime(struct trace_event_raw_sys_enter *ctx) | ||
{ | ||
struct __kernel_timex ktx; | ||
|
||
if (bpf_probe_read_user(&ktx, sizeof(ktx), (void *)ctx->args[1]) < 0) { | ||
return 0; | ||
} | ||
|
||
ktx.status |= STA_UNSYNC; | ||
bpf_probe_write_user((void *)ctx->args[1], &ktx, sizeof(ktx)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
#include <bpf/libbpf.h> | ||
#include <unistd.h> | ||
|
||
#include "rtclock.skel.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
sigset_t set; | ||
struct rtclock_bpf *skel; | ||
int sig; | ||
|
||
if (sigemptyset(&set) < 0 || sigaddset(&set, SIGTERM) < 0 || sigaddset(&set, SIGINT) < 0 || sigprocmask(SIG_BLOCK, &set, NULL) < 0) return EXIT_FAILURE; | ||
|
||
libbpf_set_strict_mode(LIBBPF_STRICT_ALL); | ||
libbpf_set_print(NULL); | ||
|
||
if (!(skel = rtclock_bpf__open_and_load())) return EXIT_FAILURE; | ||
|
||
if (rtclock_bpf__attach(skel)) { | ||
rtclock_bpf__destroy(skel); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
daemon(0, 0); | ||
sigwait(&set, &sig); | ||
|
||
rtclock_bpf__destroy(skel); | ||
return EXIT_FAILURE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters