From nobody Thu Apr 18 00:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500122093683470.4384393389116; Sat, 15 Jul 2017 05:34:53 -0700 (PDT) Received: from localhost ([::1]:42010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMHb-00088A-1L for importer@patchew.org; Sat, 15 Jul 2017 08:34:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDw-0005AU-TR for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWMDv-000654-V9 for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:04 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:52277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDv-00064n-NL for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:03 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 3D797D726; Sat, 15 Jul 2017 14:31:03 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vwsNouctzl51; Sat, 15 Jul 2017 14:30:59 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 1DCF6D6E8; Sat, 15 Jul 2017 14:30:59 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.89) (envelope-from ) id 1dWMDq-0002EK-EW; Sat, 15 Jul 2017 14:30:58 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sat, 15 Jul 2017 14:30:54 +0200 Message-Id: <20170715123057.8529-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> References: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:474::1 Subject: [Qemu-devel] [PULL 1/4] slirp: use DIV_ROUND_UP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Samuel Thibault --- slirp/ip6.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slirp/ip6.h b/slirp/ip6.h index 0908855f0f..b1bea43b3c 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -57,9 +57,9 @@ static inline bool in6_equal_mach(const struct in6_addr *= a, const struct in6_addr *b, int prefix_len) { - if (memcmp(&(a->s6_addr[(prefix_len + 7) / 8]), - &(b->s6_addr[(prefix_len + 7) / 8]), - 16 - (prefix_len + 7) / 8) !=3D 0) { + if (memcmp(&(a->s6_addr[DIV_ROUND_UP(prefix_len, 8)]), + &(b->s6_addr[DIV_ROUND_UP(prefix_len, 8)]), + 16 - DIV_ROUND_UP(prefix_len, 8)) !=3D 0) { return 0; } =20 --=20 2.13.2 From nobody Thu Apr 18 00:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150012198620923.718834677372; Sat, 15 Jul 2017 05:33:06 -0700 (PDT) Received: from localhost ([::1]:42004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMFs-0006Fj-T3 for importer@patchew.org; Sat, 15 Jul 2017 08:33:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDv-00059J-13 for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWMDu-000643-1A for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:03 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:52260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDt-00063p-QO for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:01 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 5525BC7B9; Sat, 15 Jul 2017 14:31:01 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YiejvIz-WyCN; Sat, 15 Jul 2017 14:31:00 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 32177D6E9; Sat, 15 Jul 2017 14:30:59 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.89) (envelope-from ) id 1dWMDq-0002EM-FR; Sat, 15 Jul 2017 14:30:58 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sat, 15 Jul 2017 14:30:55 +0200 Message-Id: <20170715123057.8529-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> References: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:474::1 Subject: [Qemu-devel] [PULL 2/4] slirp: fork_exec(): Don't close() a negative number in fork_exec() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell In a fork_exec() error path we try to closesocket(s) when s might be a negative number because the thing that failed was the qemu_socket() call. Add a guard so we don't do this. (Spotted by Coverity: CID 1005727 issue 1 of 2.) Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Samuel Thibault --- slirp/misc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slirp/misc.c b/slirp/misc.c index 88e9d94197..260187b6b6 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -112,7 +112,9 @@ fork_exec(struct socket *so, const char *ex, int do_pty) bind(s, (struct sockaddr *)&addr, addrlen) < 0 || listen(s, 1) < 0) { error_report("Error: inet socket: %s", strerror(errno)); - closesocket(s); + if (s >=3D 0) { + closesocket(s); + } =20 return 0; } --=20 2.13.2 From nobody Thu Apr 18 00:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500121990338374.3673542526212; Sat, 15 Jul 2017 05:33:10 -0700 (PDT) Received: from localhost ([::1]:42006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMFw-0006Jq-2f for importer@patchew.org; Sat, 15 Jul 2017 08:33:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDw-0005A2-4d for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWMDu-00064O-Mz for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:04 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:52266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDu-00064D-G5 for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:02 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 0360DD6E9; Sat, 15 Jul 2017 14:31:02 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z4OKGuHGUuo5; Sat, 15 Jul 2017 14:31:01 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 32A80D725; Sat, 15 Jul 2017 14:30:59 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.89) (envelope-from ) id 1dWMDq-0002EO-GF; Sat, 15 Jul 2017 14:30:58 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sat, 15 Jul 2017 14:30:56 +0200 Message-Id: <20170715123057.8529-4-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> References: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:474::1 Subject: [Qemu-devel] [PULL 3/4] slirp: Handle error returns from slirp_send() in sosendoob() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell The code in sosendoob() assumes that slirp_send() always succeeds, but it might return an OS error code (for instance if the other end has disconnected). Catch these and return the caller either -1 on error or the number of urgent bytes actually written. (None of the callers check this return value currently, though.) Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Samuel Thibault --- slirp/socket.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/slirp/socket.c b/slirp/socket.c index 3b49a69a93..a17caa9fa7 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -345,33 +345,40 @@ sosendoob(struct socket *so) if (sb->sb_rptr < sb->sb_wptr) { /* We can send it directly */ n =3D slirp_send(so, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTW= AIT)); */ - so->so_urgc -=3D n; - - DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n= ", n, so->so_urgc)); } else { /* * Since there's no sendv or sendtov like writev, * we must copy all data to a linear buffer then * send it all */ + uint32_t urgc =3D so->so_urgc; len =3D (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; - if (len > so->so_urgc) len =3D so->so_urgc; + if (len > urgc) { + len =3D urgc; + } memcpy(buff, sb->sb_rptr, len); - so->so_urgc -=3D len; - if (so->so_urgc) { + urgc -=3D len; + if (urgc) { n =3D sb->sb_wptr - sb->sb_data; - if (n > so->so_urgc) n =3D so->so_urgc; + if (n > urgc) { + n =3D urgc; + } memcpy((buff + len), sb->sb_data, n); - so->so_urgc -=3D n; len +=3D n; } n =3D slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ + } + #ifdef DEBUG - if (n !=3D len) - DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n")); + if (n !=3D len) { + DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n")); + } #endif - DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\= n", n, so->so_urgc)); + if (n < 0) { + return n; } + so->so_urgc -=3D n; + DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n= ", n, so->so_urgc)); =20 sb->sb_cc -=3D n; sb->sb_rptr +=3D n; --=20 2.13.2 From nobody Thu Apr 18 00:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500121990144401.80962610769154; Sat, 15 Jul 2017 05:33:10 -0700 (PDT) Received: from localhost ([::1]:42005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMFv-0006I8-0I for importer@patchew.org; Sat, 15 Jul 2017 08:33:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDv-00059u-Vs for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWMDv-00064g-3y for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:03 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:52266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWMDu-00064D-TJ for qemu-devel@nongnu.org; Sat, 15 Jul 2017 08:31:03 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A69D7D725; Sat, 15 Jul 2017 14:31:02 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iuSlyDBOlsRv; Sat, 15 Jul 2017 14:31:02 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 499D5D726; Sat, 15 Jul 2017 14:30:59 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.89) (envelope-from ) id 1dWMDq-0002EQ-HF; Sat, 15 Jul 2017 14:30:58 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sat, 15 Jul 2017 14:30:57 +0200 Message-Id: <20170715123057.8529-5-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> References: <20170715123057.8529-1-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:474::1 Subject: [Qemu-devel] [PULL 4/4] slirp: Handle error returns from sosendoob() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell sosendoob() can return a failure code, but all its callers ignore it. This is OK in sbappend(), as the comment there states -- we will try again later in sowrite(). Add a (void) cast to tell Coverity so. In sowrite() we do need to check the return value -- we should handle a write failure in sosendoob() the same way we handle a write failure for the normal data. Signed-off-by: Peter Maydell Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Samuel Thibault --- slirp/sbuf.c | 2 +- slirp/socket.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/slirp/sbuf.c b/slirp/sbuf.c index 10119d3ad5..912f235f65 100644 --- a/slirp/sbuf.c +++ b/slirp/sbuf.c @@ -91,7 +91,7 @@ sbappend(struct socket *so, struct mbuf *m) if (so->so_urgc) { sbappendsb(&so->so_rcv, m); m_free(m); - sosendoob(so); + (void)sosendoob(so); return; } =20 diff --git a/slirp/socket.c b/slirp/socket.c index a17caa9fa7..ecec0295a9 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -404,7 +404,15 @@ sowrite(struct socket *so) DEBUG_ARG("so =3D %p", so); =20 if (so->so_urgc) { - sosendoob(so); + uint32_t expected =3D so->so_urgc; + if (sosendoob(so) < expected) { + /* Treat a short write as a fatal error too, + * rather than continuing on and sending the urgent + * data as if it were non-urgent and leaving the + * so_urgc count wrong. + */ + goto err_disconnected; + } if (sb->sb_cc =3D=3D 0) return 0; } @@ -448,11 +456,7 @@ sowrite(struct socket *so) return 0; =20 if (nn <=3D 0) { - DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state =3D %x, errno = =3D %d\n", - so->so_state, errno)); - sofcantsendmore(so); - tcp_sockclosed(sototcpcb(so)); - return -1; + goto err_disconnected; } =20 #ifndef HAVE_READV @@ -479,6 +483,13 @@ sowrite(struct socket *so) sofcantsendmore(so); =20 return nn; + +err_disconnected: + DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state =3D %x, errno = =3D %d\n", + so->so_state, errno)); + sofcantsendmore(so); + tcp_sockclosed(sototcpcb(so)); + return -1; } =20 /* --=20 2.13.2