From: Roy Marples Date: Mon, 1 Jun 2020 14:33:05 +0000 (+0100) Subject: privsep: Double the size of the send buffer. X-Git-Tag: v9.1.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74df3b70381ee3a84c363f4ffed40322490063d5;p=thirdparty%2Fdhcpcd.git privsep: Double the size of the send buffer. And ensure the buffer size is not reduced. --- diff --git a/src/privsep.c b/src/privsep.c index ce84ff80..d35b2be0 100644 --- a/src/privsep.c +++ b/src/privsep.c @@ -131,13 +131,34 @@ ps_dropprivs(struct dhcpcd_ctx *ctx) return 0; } +static int +ps_setbuf0(int fd, int ctl, int minlen) +{ + int len; + socklen_t slen; + + slen = sizeof(len); + if (getsockopt(fd, SOL_SOCKET, ctl, &len, &slen) == -1) + return -1; + +#ifdef __linux__ + len /= 2; +#endif + if (len >= minlen) + return 0; + + return setsockopt(fd, SOL_SOCKET, ctl, &minlen, sizeof(minlen)); +} + static int ps_setbuf(int fd) { - socklen_t len = (socklen_t)sizeof(struct ps_msg); + /* Ensure we can receive a fully sized privsep message. + * Double the send buffer. */ + int minlen = (int)sizeof(struct ps_msg); - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)) == -1 || - setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &len, sizeof(len)) == -1) + if (ps_setbuf0(fd, SO_RCVBUF, minlen) == -1 || + ps_setbuf0(fd, SO_SNDBUF, minlen * 2) == -1) { logerr(__func__); return -1;