Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BSD: Detect route(4) overflows #7242

Merged
merged 2 commits into from Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions zebra/kernel_socket.c
Expand Up @@ -1340,13 +1340,27 @@ static int kernel_read(struct thread *thread)

nbytes = read(sock, &buf, sizeof(buf));

if (nbytes <= 0) {
if (nbytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN)
if (nbytes < 0) {
if (errno == ENOBUFS) {
flog_err(EC_ZEBRA_RECVMSG_OVERRUN,
"routing socket overrun: %s",
safe_strerror(errno));
/*
* In this case we are screwed.
* There is no good way to
* recover zebra at this point.
*/
exit(-1);
}
if (errno != EAGAIN && errno != EWOULDBLOCK)
flog_err_sys(EC_LIB_SOCKET, "routing socket error: %s",
safe_strerror(errno));
return 0;
}

if (nbytes == 0)
return 0;

thread_add_read(zrouter.master, kernel_read, NULL, sock, NULL);

if (IS_ZEBRA_DEBUG_KERNEL)
Expand Down Expand Up @@ -1412,6 +1426,15 @@ static void routing_socket(struct zebra_ns *zns)
return;
}

#ifdef SO_RERROR
/* Allow reporting of route(4) buffer overflow errors */
int n = 1;

if (setsockopt(routing_sock, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) < 0)
flog_err_sys(EC_LIB_SOCKET,
"Can't set SO_RERROR on routing socket");
#endif

/* XXX: Socket should be NONBLOCK, however as we currently
* discard failed writes, this will lead to inconsistencies.
* For now, socket must be blocking.
Expand Down