@@ -1832,9 +1832,15 @@ static __inline void process_syscall_data_vecs(struct pt_regs *ctx, __u64 id,
1832
1832
* BPF syscall probe/tracepoint/kfunc function entry-points
1833
1833
***********************************************************/
1834
1834
#ifndef LINUX_VER_KFUNC
1835
+ #ifdef NO_FTRACE_SYSCALL
1836
+ KPROG (ksys_write ) (struct pt_regs * ctx ) {
1837
+ int fd = (int )PT_REGS_PARM1 (ctx );
1838
+ char * buf = (char * )PT_REGS_PARM2 (ctx );
1839
+ #else
1835
1840
TP_SYSCALL_PROG (enter_write ) (struct syscall_comm_enter_ctx * ctx ) {
1836
1841
int fd = (int )ctx -> fd ;
1837
1842
char * buf = (char * )ctx -> buf ;
1843
+ #endif /*NO_FTRACE_SYSCALL*/
1838
1844
#else
1839
1845
// ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
1840
1846
KFUNC_PROG (ksys_write , unsigned int fd , const char __user * buf , size_t count )
@@ -1857,9 +1863,14 @@ KFUNC_PROG(ksys_write, unsigned int fd, const char __user * buf, size_t count)
1857
1863
}
1858
1864
1859
1865
#ifndef LINUX_VER_KFUNC
1866
+ #ifdef NO_FTRACE_SYSCALL
1867
+ KRETPROG (ksys_write ) (struct pt_regs * ctx ) {
1868
+ ssize_t bytes_count = PT_REGS_RC (ctx );
1869
+ #else
1860
1870
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_write/format
1861
1871
TP_SYSCALL_PROG (exit_write ) (struct syscall_comm_exit_ctx * ctx ) {
1862
1872
ssize_t bytes_count = ctx -> ret ;
1873
+ #endif /*NO_FTRACE_SYSCALL*/
1863
1874
#else
1864
1875
KRETFUNC_PROG (ksys_write , unsigned int fd , const char __user * buf ,
1865
1876
size_t count , ssize_t ret )
@@ -1881,10 +1892,17 @@ KRETFUNC_PROG(ksys_write, unsigned int fd, const char __user * buf,
1881
1892
}
1882
1893
1883
1894
#ifndef LINUX_VER_KFUNC
1895
+ #ifdef NO_FTRACE_SYSCALL
1896
+ // ssize_t read(int fd, void *buf, size_t count);
1897
+ KPROG (ksys_read ) (struct pt_regs * ctx ) {
1898
+ int fd = (unsigned int )PT_REGS_PARM1 (ctx );
1899
+ char * buf = (char * )PT_REGS_PARM2 (ctx );
1900
+ #else
1884
1901
// ssize_t read(int fd, void *buf, size_t count);
1885
1902
TP_SYSCALL_PROG (enter_read ) (struct syscall_comm_enter_ctx * ctx ) {
1886
1903
int fd = (int )ctx -> fd ;
1887
1904
char * buf = (char * )ctx -> buf ;
1905
+ #endif /*NO_FTRACE_SYSCALL*/
1888
1906
#else
1889
1907
// ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
1890
1908
KFUNC_PROG (ksys_read , unsigned int fd , const char __user * buf , size_t count )
@@ -1908,9 +1926,14 @@ KFUNC_PROG(ksys_read, unsigned int fd, const char __user * buf, size_t count)
1908
1926
}
1909
1927
1910
1928
#ifndef LINUX_VER_KFUNC
1929
+ #ifdef NO_FTRACE_SYSCALL
1930
+ KRETPROG (ksys_read ) (struct pt_regs * ctx ) {
1931
+ ssize_t bytes_count = PT_REGS_RC (ctx );
1932
+ #else
1911
1933
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_read/format
1912
1934
TP_SYSCALL_PROG (exit_read ) (struct syscall_comm_exit_ctx * ctx ) {
1913
1935
ssize_t bytes_count = ctx -> ret ;
1936
+ #endif /*NO_FTRACE_SYSCALL*/
1914
1937
#else
1915
1938
// ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
1916
1939
KRETFUNC_PROG (ksys_read , unsigned int fd , const char __user * buf , size_t count ,
@@ -1955,9 +1978,17 @@ KRETFUNC_PROG(ksys_read, unsigned int fd, const char __user * buf, size_t count,
1955
1978
* types of system calls, we need to save this information beforehand.
1956
1979
*/
1957
1980
#ifndef LINUX_VER_KFUNC
1981
+ #ifdef NO_FTRACE_SYSCALL
1982
+ // ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
1983
+ // const struct sockaddr *dest_addr, socklen_t addrlen);
1984
+ KPROG (__sys_sendto ) (struct pt_regs * ctx ) {
1985
+ int sockfd = (int )PT_REGS_PARM1 (ctx );
1986
+ char * buf = (char * )PT_REGS_PARM2 (ctx );
1987
+ #else
1958
1988
TP_SYSCALL_PROG (enter_sendto ) (struct syscall_comm_enter_ctx * ctx ) {
1959
1989
int sockfd = (int )ctx -> fd ;
1960
1990
char * buf = (char * )ctx -> buf ;
1991
+ #endif /*NO_FTRACE_SYSCALL*/
1961
1992
#else
1962
1993
//int __sys_sendto(int fd, void __user *buff, size_t len, unsigned int flags,
1963
1994
// struct sockaddr __user *addr, int addr_len)
@@ -2015,9 +2046,14 @@ KFUNC_PROG(__sys_sendto, int fd, void __user * buff, size_t len,
2015
2046
}
2016
2047
2017
2048
#ifndef LINUX_VER_KFUNC
2049
+ #ifdef NO_FTRACE_SYSCALL
2050
+ KRETPROG (__sys_sendto ) (struct pt_regs * ctx ) {
2051
+ ssize_t bytes_count = PT_REGS_RC (ctx );
2052
+ #else
2018
2053
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendto/format
2019
2054
TP_SYSCALL_PROG (exit_sendto ) (struct syscall_comm_exit_ctx * ctx ) {
2020
2055
ssize_t bytes_count = ctx -> ret ;
2056
+ #endif /*NO_FTRACE_SYSCALL*/
2021
2057
#else
2022
2058
KRETFUNC_PROG (__sys_sendto , int fd , void __user * buff , size_t len ,
2023
2059
unsigned int flags , struct sockaddr __user * u_addr , int addr_len ,
@@ -2039,6 +2075,18 @@ KRETFUNC_PROG(__sys_sendto, int fd, void __user * buff, size_t len,
2039
2075
}
2040
2076
2041
2077
#ifndef LINUX_VER_KFUNC
2078
+ #ifdef NO_FTRACE_SYSCALL
2079
+ // ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
2080
+ // struct sockaddr *src_addr, socklen_t *addrlen);
2081
+ KPROG (__sys_recvfrom ) (struct pt_regs * ctx ) {
2082
+ int sockfd = (int )PT_REGS_PARM1 (ctx );
2083
+ char * buf = (char * )PT_REGS_PARM2 (ctx );
2084
+ int flags = (int )PT_REGS_PARM4 (ctx );
2085
+ // If flags contains MSG_PEEK, it is returned directly.
2086
+ // ref : https://linux.die.net/man/2/recvfrom
2087
+ if (flags & MSG_PEEK )
2088
+ return 0 ;
2089
+ #else
2042
2090
// ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
2043
2091
// struct sockaddr *src_addr, socklen_t *addrlen);
2044
2092
TP_SYSCALL_PROG (enter_recvfrom ) (struct syscall_comm_enter_ctx * ctx ) {
@@ -2048,6 +2096,7 @@ TP_SYSCALL_PROG(enter_recvfrom) (struct syscall_comm_enter_ctx * ctx) {
2048
2096
return 0 ;
2049
2097
int sockfd = (int )ctx -> fd ;
2050
2098
char * buf = (char * )ctx -> buf ;
2099
+ #endif /*NO_FTRACE_SYSCALL*/
2051
2100
#else
2052
2101
//int __sys_recvfrom(int fd, void __user *ubuf, size_t size, unsigned int flags,
2053
2102
// struct sockaddr __user *addr, int __user *addr_len)
@@ -2078,9 +2127,15 @@ KFUNC_PROG(__sys_recvfrom, int fd, void __user * ubuf, size_t size,
2078
2127
}
2079
2128
2080
2129
#ifndef LINUX_VER_KFUNC
2130
+ #ifdef NO_FTRACE_SYSCALL
2131
+ // /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvfrom/format
2132
+ KRETPROG (__sys_recvfrom ) (struct pt_regs * ctx ) {
2133
+ ssize_t bytes_count = PT_REGS_RC (ctx );
2134
+ #else
2081
2135
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvfrom/format
2082
2136
TP_SYSCALL_PROG (exit_recvfrom ) (struct syscall_comm_exit_ctx * ctx ) {
2083
2137
ssize_t bytes_count = ctx -> ret ;
2138
+ #endif /*NO_FTRACE_SYSCALL*/
2084
2139
#else
2085
2140
KRETFUNC_PROG (__sys_recvfrom , int fd , void __user * ubuf , size_t size ,
2086
2141
unsigned int flags , struct sockaddr __user * addr ,
@@ -2142,9 +2197,14 @@ KFUNC_PROG(__sys_sendmsg, int fd, struct user_msghdr __user * msg,
2142
2197
}
2143
2198
2144
2199
#ifndef LINUX_VER_KFUNC
2200
+ #ifdef NO_FTRACE_SYSCALL
2201
+ KRETPROG (__sys_sendmsg ) (struct pt_regs * ctx ) {
2202
+ ssize_t bytes_count = PT_REGS_RC (ctx );
2203
+ #else
2145
2204
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendmsg/format
2146
2205
TP_SYSCALL_PROG (exit_sendmsg ) (struct syscall_comm_exit_ctx * ctx ) {
2147
2206
ssize_t bytes_count = ctx -> ret ;
2207
+ #endif /*NO_FTRACE_SYSCALL*/
2148
2208
#else
2149
2209
KRETFUNC_PROG (__sys_sendmsg , int sockfd , const struct msghdr * msg , int flags ,
2150
2210
bool forbid_cmsg_compat , long ret )
@@ -2206,9 +2266,14 @@ KFUNC_PROG(__sys_sendmmsg, int fd, struct mmsghdr __user * mmsg,
2206
2266
}
2207
2267
2208
2268
#ifndef LINUX_VER_KFUNC
2269
+ #ifdef NO_FTRACE_SYSCALL
2270
+ KRETPROG (__sys_sendmmsg )(struct pt_regs * ctx ) {
2271
+ int num_msgs = PT_REGS_RC (ctx );
2272
+ #else
2209
2273
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendmmsg/format
2210
2274
TP_SYSCALL_PROG (exit_sendmmsg ) (struct syscall_comm_exit_ctx * ctx ) {
2211
2275
int num_msgs = ctx -> ret ;
2276
+ #endif /* NO_FTRACE_SYSCALL */
2212
2277
#else
2213
2278
KRETFUNC_PROG (__sys_sendmmsg , int fd , struct mmsghdr __user * mmsg ,
2214
2279
unsigned int vlen , unsigned int flags , bool forbid_cmsg_compat ,
@@ -2276,9 +2341,14 @@ KFUNC_PROG(__sys_recvmsg, int fd, struct user_msghdr __user * msg,
2276
2341
}
2277
2342
2278
2343
#ifndef LINUX_VER_KFUNC
2344
+ #ifdef NO_FTRACE_SYSCALL
2345
+ KRETPROG (__sys_recvmsg ) (struct pt_regs * ctx ) {
2346
+ ssize_t bytes_count = PT_REGS_RC (ctx );
2347
+ #else
2279
2348
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvmsg/format
2280
2349
TP_SYSCALL_PROG (exit_recvmsg ) (struct syscall_comm_exit_ctx * ctx ) {
2281
2350
ssize_t bytes_count = ctx -> ret ;
2351
+ #endif /* NO_FTRACE_SYSCALL */
2282
2352
#else
2283
2353
KRETFUNC_PROG (__sys_recvmsg , int fd , struct user_msghdr __user * msg ,
2284
2354
unsigned int flags , bool forbid_cmsg_compat , long ret )
@@ -2357,9 +2427,14 @@ KFUNC_PROG(__sys_recvmmsg, int fd, struct mmsghdr __user * mmsg,
2357
2427
}
2358
2428
2359
2429
#ifndef LINUX_VER_KFUNC
2430
+ #ifdef NO_FTRACE_SYSCALL
2431
+ KRETPROG (__sys_recvmmsg ) (struct pt_regs * ctx ) {
2432
+ int num_msgs = PT_REGS_RC (ctx );
2433
+ #else
2360
2434
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvmmsg/format
2361
2435
TP_SYSCALL_PROG (exit_recvmmsg ) (struct syscall_comm_exit_ctx * ctx ) {
2362
2436
int num_msgs = ctx -> ret ;
2437
+ #endif /* NO_FTRACE_SYSCALL */
2363
2438
#else
2364
2439
KRETFUNC_PROG (__sys_recvmmsg , int fd , struct mmsghdr __user * mmsg ,
2365
2440
unsigned int vlen , unsigned int flags ,
@@ -2421,9 +2496,14 @@ KFUNC_PROG(do_writev, unsigned long fd, const struct iovec __user * vec,
2421
2496
}
2422
2497
2423
2498
#ifndef LINUX_VER_KFUNC
2499
+ #ifdef NO_FTRACE_SYSCALL
2500
+ KRETPROG (do_writev ) (struct pt_regs * ctx ) {
2501
+ ssize_t bytes_count = PT_REGS_RC (ctx );
2502
+ #else
2424
2503
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_writev/format
2425
2504
TP_SYSCALL_PROG (exit_writev ) (struct syscall_comm_exit_ctx * ctx ) {
2426
2505
ssize_t bytes_count = ctx -> ret ;
2506
+ #endif /* NO_FTRACE_SYSCALL */
2427
2507
#else
2428
2508
KRETFUNC_PROG (do_writev , unsigned long fd , const struct iovec __user * vec ,
2429
2509
unsigned long vlen , rwf_t flags , ssize_t ret )
@@ -2481,9 +2561,14 @@ KFUNC_PROG(do_readv, unsigned long fd, const struct iovec __user * vec,
2481
2561
}
2482
2562
2483
2563
#ifndef LINUX_VER_KFUNC
2564
+ #ifdef NO_FTRACE_SYSCALL
2565
+ KRETPROG (do_readv ) (struct pt_regs * ctx ) {
2566
+ ssize_t bytes_count = PT_REGS_RC (ctx );
2567
+ #else
2484
2568
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_readv/format
2485
2569
TP_SYSCALL_PROG (exit_readv ) (struct syscall_comm_exit_ctx * ctx ) {
2486
2570
ssize_t bytes_count = ctx -> ret ;
2571
+ #endif /* NO_FTRACE_SYSCALL */
2487
2572
#else
2488
2573
KRETFUNC_PROG (do_readv , unsigned long fd , const struct iovec __user * vec ,
2489
2574
unsigned long vlen , rwf_t flags , ssize_t ret )
@@ -2557,9 +2642,14 @@ static __inline void __push_close_event(__u64 pid_tgid, __u64 uid, __u64 seq,
2557
2642
}
2558
2643
2559
2644
#ifndef LINUX_VER_KFUNC
2645
+ #ifdef NO_FTRACE_SYSCALL
2646
+ KPROG (__close_fd ) (struct pt_regs * ctx ) {
2647
+ int fd = (int )PT_REGS_PARM2 (ctx );
2648
+ #else
2560
2649
// /sys/kernel/debug/tracing/events/syscalls/sys_enter_close/format
2561
2650
TP_SYSCALL_PROG (enter_close ) (struct syscall_comm_enter_ctx * ctx ) {
2562
2651
int fd = ctx -> fd ;
2652
+ #endif /* NO_FTRACE_SYSCALL */
2563
2653
#else
2564
2654
#if defined(__x86_64__ )
2565
2655
//asmlinkage long __x64_sys_close(const struct pt_regs *regs) {
@@ -2605,8 +2695,13 @@ KFUNC_PROG(__arm64_sys_close, const struct pt_regs *regs)
2605
2695
//int __sys_socket(int family, int type, int protocol)
2606
2696
// /sys/kernel/debug/tracing/events/syscalls/sys_exit_socket/format
2607
2697
#ifndef LINUX_VER_KFUNC
2698
+ #ifdef NO_FTRACE_SYSCALL
2699
+ KRETPROG (__sys_socket ) (struct pt_regs * ctx ) {
2700
+ __u64 fd = (__u64 )PT_REGS_RC (ctx );
2701
+ #else
2608
2702
TP_SYSCALL_PROG (exit_socket ) (struct syscall_comm_exit_ctx * ctx ) {
2609
2703
__u64 fd = (__u64 ) ctx -> ret ;
2704
+ #endif /* NO_FTRACE_SYSCALL */
2610
2705
#else
2611
2706
KRETFUNC_PROG (__sys_socket , int family , int type , int protocol , int ret )
2612
2707
{
@@ -2655,8 +2750,13 @@ KRETFUNC_PROG(__sys_socket, int family, int type, int protocol, int ret)
2655
2750
* `kfunc` type should directly use `__sys_accept4()`.
2656
2751
*/
2657
2752
#ifndef LINUX_VER_KFUNC
2753
+ #ifdef NO_FTRACE_SYSCALL
2754
+ KRETPROG (__sys_accept4 ) (struct pt_regs * ctx ) {
2755
+ int sockfd = PT_REGS_RC (ctx );
2756
+ #else
2658
2757
TP_SYSCALL_PROG (exit_accept ) (struct syscall_comm_exit_ctx * ctx ) {
2659
2758
int sockfd = ctx -> ret ;
2759
+ #endif /* NO_FTRACE_SYSCALL */
2660
2760
#else
2661
2761
//int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
2662
2762
// int __user *upeer_addrlen, int flags)
@@ -2673,7 +2773,7 @@ KRETFUNC_PROG(__sys_accept4, int fd, struct sockaddr __user * upeer_sockaddr,
2673
2773
return 0 ;
2674
2774
}
2675
2775
2676
- #ifndef LINUX_VER_KFUNC
2776
+ #if !defined( LINUX_VER_KFUNC ) && !defined( NO_FTRACE_SYSCALL )
2677
2777
TP_SYSCALL_PROG (exit_accept4 ) (struct syscall_comm_exit_ctx * ctx ) {
2678
2778
int sockfd = ctx -> ret ;
2679
2779
__u64 pid_tgid = bpf_get_current_pid_tgid ();
@@ -2686,8 +2786,13 @@ TP_SYSCALL_PROG(exit_accept4) (struct syscall_comm_exit_ctx * ctx) {
2686
2786
#endif
2687
2787
2688
2788
#ifndef LINUX_VER_KFUNC
2789
+ #ifdef NO_FTRACE_SYSCALL
2790
+ KPROG (__sys_connect ) (struct pt_regs * ctx ) {
2791
+ int sockfd = (int )PT_REGS_PARM1 (ctx );
2792
+ #else
2689
2793
TP_SYSCALL_PROG (enter_connect ) (struct syscall_comm_enter_ctx * ctx ) {
2690
2794
int sockfd = ctx -> fd ;
2795
+ #endif /* NO_FTRACE_SYSCALL */
2691
2796
#else
2692
2797
// int __sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen)
2693
2798
KFUNC_PROG (__sys_connect , int fd , struct sockaddr __user * uservaddr ,
@@ -3394,7 +3499,11 @@ static __inline int push_socket_data(struct syscall_comm_enter_ctx *ctx)
3394
3499
// /sys/kernel/debug/tracing/events/syscalls/sys_enter_getppid
3395
3500
// Here, the tracepoint is used to periodically send the data residing in the cache but not
3396
3501
// yet transmitted to the user-level receiving program for processing.
3502
+ #ifdef NO_FTRACE_SYSCALL
3503
+ KPROG (sys_getppid ) (struct pt_regs * ctx ) {
3504
+ #else
3397
3505
TP_SYSCALL_PROG (enter_getppid ) (struct syscall_comm_enter_ctx * ctx ) {
3506
+ #endif /* NO_FTRACE_SYSCALL */
3398
3507
// Only pre-specified Pid is allowed to trigger.
3399
3508
if (!check_pid_validity ())
3400
3509
return 0 ;
0 commit comments