From nobody Fri Nov 7 09:10:10 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536910087282682.9535073032309; Fri, 14 Sep 2018 00:28:07 -0700 (PDT) Received: from localhost ([::1]:49248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0iWG-00009V-MR for importer@patchew.org; Fri, 14 Sep 2018 03:28:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0iUo-0007pQ-OH for qemu-devel@nongnu.org; Fri, 14 Sep 2018 03:26:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0iUm-0000P0-Ka for qemu-devel@nongnu.org; Fri, 14 Sep 2018 03:26:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0iUk-0000KV-MV for qemu-devel@nongnu.org; Fri, 14 Sep 2018 03:26:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C3BC3084218; Fri, 14 Sep 2018 07:26:24 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-180.pek2.redhat.com [10.72.12.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51E185FC0A; Fri, 14 Sep 2018 07:26:23 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 14 Sep 2018 15:26:15 +0800 Message-Id: <20180914072616.17771-2-famz@redhat.com> In-Reply-To: <20180914072616.17771-1-famz@redhat.com> References: <20180914072616.17771-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 14 Sep 2018 07:26:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/2] slirp: Add sanity check for str option length 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: Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When user provides a long domainname or hostname that doesn't fit in the DHCP packet, we mustn't overflow the response packet buffer. Instead, report errors, following the g_warning() in the slirp->vdnssearch branch. Also check the strlen against 256 when initializing slirp, which limit is also from the protocol where one byte represents the string length. This gives an early error before the warning which is harder to notice or diagnose. Reported-by: Thomas Huth Reviewed-by: Thomas Huth Cc: qemu-stable@nongnu.org Signed-off-by: Fam Zheng Tested-by: Gerd Hoffmann --- net/slirp.c | 9 +++++++++ slirp/bootp.c | 32 ++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 1e14318b4d..fd21dc728c 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -365,6 +365,15 @@ static int net_slirp_init(NetClientState *peer, const = char *model, return -1; } =20 + if (vdomainname && strlen(vdomainname) > 255) { + error_setg(errp, "'domainname' parameter cannot exceed 255 bytes"); + return -1; + } + + if (vhostname && strlen(vhostname) > 255) { + error_setg(errp, "'vhostname' parameter cannot exceed 255 bytes"); + return -1; + } =20 nc =3D qemu_new_net_client(&net_slirp_info, peer, model, name); =20 diff --git a/slirp/bootp.c b/slirp/bootp.c index 9e7b53ba94..1e8185f0ec 100644 --- a/slirp/bootp.c +++ b/slirp/bootp.c @@ -159,6 +159,7 @@ static void bootp_reply(Slirp *slirp, const struct boot= p_t *bp) struct in_addr preq_addr; int dhcp_msg_type, val; uint8_t *q; + uint8_t *end; uint8_t client_ethaddr[ETH_ALEN]; =20 /* extract exact DHCP msg type */ @@ -240,6 +241,7 @@ static void bootp_reply(Slirp *slirp, const struct boot= p_t *bp) rbp->bp_siaddr =3D saddr.sin_addr; /* Server IP address */ =20 q =3D rbp->bp_vend; + end =3D (uint8_t *)&rbp[1]; memcpy(q, rfc1533_cookie, 4); q +=3D 4; =20 @@ -292,24 +294,33 @@ static void bootp_reply(Slirp *slirp, const struct bo= otp_t *bp) =20 if (*slirp->client_hostname) { val =3D strlen(slirp->client_hostname); - *q++ =3D RFC1533_HOSTNAME; - *q++ =3D val; - memcpy(q, slirp->client_hostname, val); - q +=3D val; + if (q + val + 2 >=3D end) { + g_warning("DHCP packet size exceeded, " + "omitting host name option."); + } else { + *q++ =3D RFC1533_HOSTNAME; + *q++ =3D val; + memcpy(q, slirp->client_hostname, val); + q +=3D val; + } } =20 if (slirp->vdomainname) { val =3D strlen(slirp->vdomainname); - *q++ =3D RFC1533_DOMAINNAME; - *q++ =3D val; - memcpy(q, slirp->vdomainname, val); - q +=3D val; + if (q + val + 2 >=3D end) { + g_warning("DHCP packet size exceeded, " + "omitting domain name option."); + } else { + *q++ =3D RFC1533_DOMAINNAME; + *q++ =3D val; + memcpy(q, slirp->vdomainname, val); + q +=3D val; + } } =20 if (slirp->vdnssearch) { - size_t spaceleft =3D sizeof(rbp->bp_vend) - (q - rbp->bp_vend); val =3D slirp->vdnssearch_len; - if (val + 1 > spaceleft) { + if (q + val >=3D end) { g_warning("DHCP packet size exceeded, " "omitting domain-search option."); } else { @@ -331,6 +342,7 @@ static void bootp_reply(Slirp *slirp, const struct boot= p_t *bp) memcpy(q, nak_msg, sizeof(nak_msg) - 1); q +=3D sizeof(nak_msg) - 1; } + assert(q < end); *q =3D RFC1533_END; =20 daddr.sin_addr.s_addr =3D 0xffffffffu; --=20 2.17.1