Skip to content

Commit dee0a6f

Browse files
committed
use recvfrom instead of recv
To make sure the messages are actually from the kernel and not somebody else use recvfrom. Signed-off-by: Stefan Assmann <[email protected]>
1 parent d838703 commit dee0a6f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

and-proc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ int proc_handle_ev(int nl_sock)
9191
struct proc_event proc_ev;
9292
};
9393
} nlcn_msg;
94+
struct sockaddr_nl addr;
95+
socklen_t addrlen;
9496

9597
while (!need_exit) {
96-
rc = recv(nl_sock, &nlcn_msg, sizeof(nlcn_msg), 0);
98+
rc = recvfrom(nl_sock, &nlcn_msg, sizeof(nlcn_msg), 0, (struct sockaddr *)&addr, &addrlen);
99+
if (addr.nl_pid) /* check that message is from kernel */
100+
continue;
97101
if (rc == 0) {
98102
/* shutdown? */
99103
return -1;

0 commit comments

Comments
 (0)