Skip to content

Commit 5d2f430

Browse files
Gang Yanintel-lab-lkp
authored andcommitted
bpf: Allow error injection for update_socket_protocol
The "update_socket_protocol" interface is designed to empower user space with the capability to customize and modify socket protocols leveraging BPF methods. Currently, it has only granted the fmod_ret permission, allowing for modifications to return values. We are extending the permissions further by 'ALLOW_ERROR_INJECTION', thereby facilitating the development of user-space programs with enhanced flexibility and convenience. When we attempt to modify the return value of "update_socket_protocol" to "IPPROTO_MPTCP" using the below code based on the BCC tool: ''' int kprobe__update_socket_protocol(void* ctx) { ... bpf_override_return(ctx,IPPROTO_MPTCP); ... } ''' But an error occurs: ''' ioctl(PERF_EVENT_IOC_SET_BPF): Invalid argument Traceback (most recent call last): File "/media/yangang/work/Code/BCC/test.py", line 27, in <module> b = BPF(text=prog) ^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 487, \ in __init__ self._trace_autoload() File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 1466, \ in _trace_autoload self.attach_kprobe( File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 855,\ in attach_kprobe raise Exception("Failed to attach BPF program %s to kprobe %s" Exception: Failed to attach BPF program b'kprobe__update_socket_protocol' \ to kprobe b'update_socket_protocol', it's not traceable \ (either non-existing, inlined, or marked as "notrace") ''' This patch can fix the issue. Suggested-by: Geliang Tang <[email protected]> Signed-off-by: Gang Yan <[email protected]>
1 parent 4e59dc8 commit 5d2f430

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

net/socket.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,7 @@ __weak noinline int update_socket_protocol(int family, int type, int protocol)
16951695
{
16961696
return protocol;
16971697
}
1698+
ALLOW_ERROR_INJECTION(update_socket_protocol, ERRNO);
16981699

16991700
__bpf_hook_end();
17001701

0 commit comments

Comments
 (0)