@@ -31,48 +31,51 @@ static void __stop_umh(void)
31
31
shutdown_umh ();
32
32
}
33
33
34
- static int __bpfilter_process_sockopt (struct sock * sk , int optname ,
35
- char __user * optval ,
36
- unsigned int optlen , bool is_set )
34
+ static int bpfilter_send_req (struct mbox_request * req )
37
35
{
38
- struct mbox_request req ;
39
36
struct mbox_reply reply ;
40
37
loff_t pos ;
41
38
ssize_t n ;
42
- int ret = - EFAULT ;
43
39
44
- req .is_set = is_set ;
45
- req .pid = current -> pid ;
46
- req .cmd = optname ;
47
- req .addr = (uintptr_t )optval ;
48
- req .len = optlen ;
49
40
if (!bpfilter_ops .info .tgid )
50
- goto out ;
41
+ return - EFAULT ;
51
42
pos = 0 ;
52
- n = kernel_write (bpfilter_ops .info .pipe_to_umh , & req , sizeof (req ),
43
+ n = kernel_write (bpfilter_ops .info .pipe_to_umh , req , sizeof (* req ),
53
44
& pos );
54
- if (n != sizeof (req )) {
45
+ if (n != sizeof (* req )) {
55
46
pr_err ("write fail %zd\n" , n );
56
- __stop_umh ();
57
- ret = - EFAULT ;
58
- goto out ;
47
+ goto stop ;
59
48
}
60
49
pos = 0 ;
61
50
n = kernel_read (bpfilter_ops .info .pipe_from_umh , & reply , sizeof (reply ),
62
51
& pos );
63
52
if (n != sizeof (reply )) {
64
53
pr_err ("read fail %zd\n" , n );
65
- __stop_umh ();
66
- ret = - EFAULT ;
67
- goto out ;
54
+ goto stop ;
68
55
}
69
- ret = reply .status ;
70
- out :
71
- return ret ;
56
+ return reply .status ;
57
+ stop :
58
+ __stop_umh ();
59
+ return - EFAULT ;
60
+ }
61
+
62
+ static int bpfilter_process_sockopt (struct sock * sk , int optname ,
63
+ char __user * optval , unsigned int optlen ,
64
+ bool is_set )
65
+ {
66
+ struct mbox_request req = {
67
+ .is_set = is_set ,
68
+ .pid = current -> pid ,
69
+ .cmd = optname ,
70
+ .addr = (uintptr_t )optval ,
71
+ .len = optlen ,
72
+ };
73
+ return bpfilter_send_req (& req );
72
74
}
73
75
74
76
static int start_umh (void )
75
77
{
78
+ struct mbox_request req = { .pid = current -> pid };
76
79
int err ;
77
80
78
81
/* fork usermode process */
@@ -82,7 +85,7 @@ static int start_umh(void)
82
85
pr_info ("Loaded bpfilter_umh pid %d\n" , pid_nr (bpfilter_ops .info .tgid ));
83
86
84
87
/* health check that usermode process started correctly */
85
- if (__bpfilter_process_sockopt ( NULL , 0 , NULL , 0 , 0 ) != 0 ) {
88
+ if (bpfilter_send_req ( & req ) != 0 ) {
86
89
shutdown_umh ();
87
90
return - EFAULT ;
88
91
}
@@ -103,7 +106,7 @@ static int __init load_umh(void)
103
106
mutex_lock (& bpfilter_ops .lock );
104
107
err = start_umh ();
105
108
if (!err && IS_ENABLED (CONFIG_INET )) {
106
- bpfilter_ops .sockopt = & __bpfilter_process_sockopt ;
109
+ bpfilter_ops .sockopt = & bpfilter_process_sockopt ;
107
110
bpfilter_ops .start = & start_umh ;
108
111
}
109
112
mutex_unlock (& bpfilter_ops .lock );
0 commit comments