Skip to content

Commit dca31e5

Browse files
committed
Workaround for raw tracepoint performance issues
raw tracepoint could lead > 10% performance penality for syscall intensive scenarios with linux kernels < 5.4, especially CentOS7. Disable raw tracepoint and DNS hooking for these kernels. Users could enable it with kernel module parameters like: insmod hids_driver.ko RAWTP_HOOK=1 DNS_HOOK=1 Signed-off-by: shenping.matt <shenping.matt@bytedance.com>
1 parent 9138fd9 commit dca31e5

1 file changed

Lines changed: 33 additions & 33 deletions

File tree

driver/LKM/src/smith_hook.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,41 @@ SMITH_HOOK(SETSID, 1);
4646
SMITH_HOOK(PRCTL, 1);
4747
SMITH_HOOK(MEMFD_CREATE, 1);
4848
SMITH_HOOK(MOUNT, 1);
49-
SMITH_HOOK(DNS, 1);
5049
SMITH_HOOK(USERMODEHELPER, 1);
5150
SMITH_HOOK(UDEV, 1);
5251
SMITH_HOOK(CHMOD, 1);
53-
54-
SMITH_HOOK(WRITE, 0);
55-
SMITH_HOOK(ACCEPT, 0);
56-
SMITH_HOOK(OPEN, 0);
57-
SMITH_HOOK(MPROTECT, 0);
5852
SMITH_HOOK(NANOSLEEP, 0);
59-
SMITH_HOOK(KILL, 0);
60-
SMITH_HOOK(RM, 0);
61-
SMITH_HOOK(EXIT, 0);
6253

63-
static int FAKE_SLEEP = 0;
64-
static int FAKE_RM = 0;
54+
SMITH_HOOK(WRITE, SANDBOX);
55+
SMITH_HOOK(ACCEPT, SANDBOX);
56+
SMITH_HOOK(OPEN, SANDBOX);
57+
SMITH_HOOK(MPROTECT, SANDBOX);
58+
SMITH_HOOK(KILL, SANDBOX);
59+
SMITH_HOOK(RM, SANDBOX);
60+
SMITH_HOOK(EXIT, SANDBOX);
61+
62+
/*
63+
*
64+
* raw tracepoint brings severe performance penalty for syscall-intensive ops.
65+
* so disabled by default, and enabled only for SANDBOX or kernels >= 5.4.210
66+
*
67+
*/
68+
SMITH_HOOK(RAWTP, SANDBOX || (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 210)));
69+
SMITH_HOOK(DNS, SANDBOX || (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 210)));
70+
71+
static int FAKE_RM = SANDBOX;
6572

73+
#if SANDBOX
74+
static int PID_TREE_LIMIT = 100;
75+
static int PID_TREE_LIMIT_LOW = 100;
76+
static int EXECVE_GET_SOCK_PID_LIMIT = 100;
77+
static int EXECVE_GET_SOCK_FD_LIMIT = 100;
78+
#else
6679
static int PID_TREE_LIMIT = 12;
6780
static int PID_TREE_LIMIT_LOW = 8;
6881
static int EXECVE_GET_SOCK_PID_LIMIT = 4;
6982
static int EXECVE_GET_SOCK_FD_LIMIT = 12; /* maximum fd numbers to be queried */
83+
#endif
7084

7185
static char connect_syscall_kprobe_state = 0x0;
7286
static char execve_kretprobe_state = 0x0;
@@ -2702,6 +2716,10 @@ static int __init smith_sysret_init(void)
27022716
{
27032717
int i, rc;
27042718

2719+
/* skip raw tracepoint registration */
2720+
if (!RAWTP_HOOK)
2721+
return 0;
2722+
27052723
/* check the tracepoints of our interest */
27062724
rc = smith_assert_tracepoints();
27072725
if (rc) {
@@ -2732,6 +2750,10 @@ static void smith_sysret_fini(void)
27322750
{
27332751
int i;
27342752

2753+
/* skip raw tracepoint unregistration */
2754+
if (!RAWTP_HOOK)
2755+
return;
2756+
27352757
/* register callbacks for the tracepoints of our interest */
27362758
for (i = NUM_TRACE_POINTS; i > 0; i--)
27372759
smith_unregister_tracepoint(&g_smith_tracepoints[i - 1]);
@@ -4804,28 +4826,6 @@ static void __init install_kprobe(void)
48044826
{
48054827
int ret;
48064828

4807-
if (SANDBOX == 1) {
4808-
DNS_HOOK = 1;
4809-
USERMODEHELPER_HOOK = 1;
4810-
//MPROTECT_HOOK = 1;
4811-
ACCEPT_HOOK = 1;
4812-
OPEN_HOOK = 1;
4813-
MPROTECT_HOOK = 1;
4814-
//NANOSLEEP_HOOK = 1;
4815-
KILL_HOOK = 1;
4816-
RM_HOOK = 1;
4817-
EXIT_HOOK = 1;
4818-
WRITE_HOOK = 1;
4819-
4820-
PID_TREE_LIMIT = 100;
4821-
PID_TREE_LIMIT_LOW = 100;
4822-
EXECVE_GET_SOCK_PID_LIMIT = 100;
4823-
EXECVE_GET_SOCK_FD_LIMIT = 100;
4824-
4825-
FAKE_SLEEP = 1;
4826-
FAKE_RM = 1;
4827-
}
4828-
48294829
if (UDEV_HOOK == 1) {
48304830
static void (*smith_usb_register_notify) (struct notifier_block * nb);
48314831
smith_usb_register_notify = __symbol_get("usb_register_notify");

0 commit comments

Comments
 (0)