From a7aef7ef4f74e1155833c9abcf3720be40092282 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 3 Nov 2022 14:16:05 +0100 Subject: seitan: Read the rest of the netlink message on event mismatch ...the PROC_EVENT_EXEC we're looking for might be hiding there. Also, avoid a possible endless loop on NLMSG_NOOP. Signed-off-by: Stefano Brivio --- seitan.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'seitan.c') diff --git a/seitan.c b/seitan.c index bc98aed..d1e55a6 100644 --- a/seitan.c +++ b/seitan.c @@ -74,9 +74,10 @@ static int event(int s) return -EIO; nlh = (struct nlmsghdr *)buf; - while (NLMSG_OK(nlh, n)) { + for (; NLMSG_OK(nlh, n); nlh = NLMSG_NEXT(nlh, n)) { if (nlh->nlmsg_type == NLMSG_NOOP) continue; + if ((nlh->nlmsg_type == NLMSG_ERROR) || (nlh->nlmsg_type == NLMSG_OVERRUN)) break; @@ -85,7 +86,7 @@ static int event(int s) ev = (struct proc_event *)cnh->data; if (ev->what != PROC_EVENT_EXEC) - return -EAGAIN; + continue; snprintf(path, PATH_MAX, "/proc/%i/exe", ev->event_data.exec.process_pid); @@ -97,8 +98,6 @@ static int event(int s) if (nlh->nlmsg_type == NLMSG_DONE) break; - - nlh = NLMSG_NEXT(nlh, n); } return -EAGAIN; -- cgit v1.2.3