From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 3766D5A026E; Sun, 4 Jun 2023 07:49:57 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] tap: With pasta, don't reset on tap errors, handle write failures Date: Sun, 4 Jun 2023 07:49:57 +0200 Message-Id: <20230604054957.619904-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ET3F5OLZEY3XP73I5SNOUXNCOXSWRJ4C X-Message-ID-Hash: ET3F5OLZEY3XP73I5SNOUXNCOXSWRJ4C X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Gianluca Stivan , Chris Kuhn X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Since commit 0515adceaa8f ("passt, pasta: Namespace-based sandboxing, defer seccomp policy application"), it makes no sense to close and reopen the tap device on error: we don't have access to /dev/net/tun after the initial setup phase. If we hit ENOBUFS while writing (as reported: in one case because the kernel actually ran out of memory, with another case under investigation), or ENOSPC, we're supposed to drop whatever data we were trying to send: there's no room for it. Handle EINTR just like we handled EAGAIN/EWOULDBLOCK: there's no particular reason why sending the same data should fail again. Anything else I can think of would be an unrecoverable error: exit with failure then. While at it, drop a useless cast on the write() call: it takes a const void * anyway. Reported-by: Gianluca Stivan Reported-by: Chris Kuhn Fixes: 0515adceaa8f ("passt, pasta: Namespace-based sandboxing, defer seccomp policy application") Signed-off-by: Stefano Brivio --- tap.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tap.c b/tap.c index c0b7f33..e323529 100644 --- a/tap.c +++ b/tap.c @@ -320,12 +320,23 @@ static size_t tap_send_frames_pasta(struct ctx *c, size_t i; for (i = 0; i < n; i++) { - if (write(c->fd_tap, (char *)iov[i].iov_base, - iov[i].iov_len) < 0) { + if (write(c->fd_tap, iov[i].iov_base, iov[i].iov_len) < 0) { debug("tap write: %s", strerror(errno)); - if (errno != EAGAIN && errno != EWOULDBLOCK) - tap_handler(c, c->fd_tap, EPOLLERR, NULL); - i--; + + switch (errno) { + case EAGAIN: +#if EAGAIN != EWOULDBLOCK + case EWOULDBLOCK: +#endif + case EINTR: + i--; + break; + case ENOBUFS: + case ENOSPC: + break; + default: + die("Write error on tap device, exiting"); + } } } @@ -1237,6 +1248,9 @@ void tap_handler(struct ctx *c, int fd, uint32_t events, exit(EXIT_SUCCESS); } + if (c->mode == MODE_PASTA) + die("Error on tap device, exiting"); + tap_sock_init(c); } } -- 2.39.2