From cb3fbc1010d5dafa0e2582767502b21d5e136866 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Wed, 24 Jun 2020 08:59:31 -0700 Subject: [PATCH] Catch unexpected socket polling errors. The poll(2) system call may set POLLERR in the returned events. Normally no errors are returned unless specifically requested by setting an appropriate socket option. Nevertheless, the poll(2) API is quite generic, and there is no guarantee that the kernel networking stack might push an error event one day. This patch adds defensive code in order to catch any unexpected error condition. Signed-off-by: Richard Cochran --- clock.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/clock.c b/clock.c index f43cc2a..a66d189 100644 --- a/clock.c +++ b/clock.c @@ -1559,8 +1559,14 @@ int clock_poll(struct clock *c) LIST_FOREACH(p, &c->ports, list) { /* Let the ports handle their events. */ for (i = 0; i < N_POLLFD; i++) { - if (cur[i].revents & (POLLIN|POLLPRI)) { - event = port_event(p, i); + if (cur[i].revents & (POLLIN|POLLPRI|POLLERR)) { + if (cur[i].revents & POLLERR) { + pr_err("port %d: unexpected socket error", + port_number(p)); + event = EV_FAULT_DETECTED; + } else { + event = port_event(p, i); + } if (EV_STATE_DECISION_EVENT == event) { c->sde = 1; }