From patchwork Thu Sep 6 05:43:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10589885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC8CF6CB for ; Thu, 6 Sep 2018 05:51:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B07F2A382 for ; Thu, 6 Sep 2018 05:51:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CAD72A55B; Thu, 6 Sep 2018 05:51:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1FF3B2A382 for ; Thu, 6 Sep 2018 05:51:34 +0000 (UTC) Received: from localhost ([::1]:59484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxnCX-0003WZ-GW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Sep 2018 01:51:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxn8I-00087u-In for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:47:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxn5H-0007xl-0K for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53688 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxn5G-0007ua-Qi for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EFFE40241C0; Thu, 6 Sep 2018 05:44:02 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-55.pek2.redhat.com [10.72.12.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6B1D2022EEE; Thu, 6 Sep 2018 05:43:56 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 13:43:37 +0800 Message-Id: <20180906054340.28988-2-famz@redhat.com> In-Reply-To: <20180906054340.28988-1-famz@redhat.com> References: <20180906054340.28988-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 06 Sep 2018 05:44:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 06 Sep 2018 05:44:02 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 1/4] virtio: update MemoryRegionCaches when guest negotiates features 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 , Thomas Huth , Fam Zheng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Samuel Thibault , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Brad Smith Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini Because the cache is sized to include the rings and the event indices, negotiating the VIRTIO_RING_F_EVENT_IDX feature will result in the size of the cache changing. And because MemoryRegionCache accesses are range-checked, if we skip this we end up with an assertion failure. This happens with OpenBSD 6.3. Reported-by: Fam Zheng Fixes: 97cd965c070152bc626c7507df9fb356bbe1cd81 Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini Signed-off-by: Fam Zheng --- hw/virtio/virtio.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index d4e4d98b59..f6a588ab57 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2006,14 +2006,25 @@ static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val) int virtio_set_features(VirtIODevice *vdev, uint64_t val) { - /* + int ret; + /* * The driver must not attempt to set features after feature negotiation * has finished. */ if (vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) { return -EINVAL; } - return virtio_set_features_nocheck(vdev, val); + ret = virtio_set_features_nocheck(vdev, val); + if (!ret && virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { + /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ + int i; + for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { + if (vdev->vq[i].vring.num != 0) { + virtio_init_region_cache(vdev, i); + } + } + } + return ret; } int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) From patchwork Thu Sep 6 05:43:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10589883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FD686CB for ; Thu, 6 Sep 2018 05:50:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FA742A547 for ; Thu, 6 Sep 2018 05:50:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 043152A55B; Thu, 6 Sep 2018 05:50:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 986E32A547 for ; Thu, 6 Sep 2018 05:50:19 +0000 (UTC) Received: from localhost ([::1]:59481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxnBL-0002wP-18 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Sep 2018 01:50:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxn8H-00087u-8Q for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:47:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxn5N-0008WA-Vv for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50558 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxn5N-0008Um-NZ for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54CB2402332F; Thu, 6 Sep 2018 05:44:09 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-55.pek2.redhat.com [10.72.12.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7CE6202322A; Thu, 6 Sep 2018 05:44:02 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 13:43:38 +0800 Message-Id: <20180906054340.28988-3-famz@redhat.com> In-Reply-To: <20180906054340.28988-1-famz@redhat.com> References: <20180906054340.28988-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 06 Sep 2018 05:44:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 06 Sep 2018 05:44:09 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/4] 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: Peter Maydell , Thomas Huth , Fam Zheng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Samuel Thibault , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Brad Smith Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Fam Zheng Reviewed-by: Thomas Huth --- 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; } + 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; + } nc = qemu_new_net_client(&net_slirp_info, peer, model, name); 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 bootp_t *bp) struct in_addr preq_addr; int dhcp_msg_type, val; uint8_t *q; + uint8_t *end; uint8_t client_ethaddr[ETH_ALEN]; /* extract exact DHCP msg type */ @@ -240,6 +241,7 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp) rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */ q = rbp->bp_vend; + end = (uint8_t *)&rbp[1]; memcpy(q, rfc1533_cookie, 4); q += 4; @@ -292,24 +294,33 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp) if (*slirp->client_hostname) { val = strlen(slirp->client_hostname); - *q++ = RFC1533_HOSTNAME; - *q++ = val; - memcpy(q, slirp->client_hostname, val); - q += val; + if (q + val + 2 >= end) { + g_warning("DHCP packet size exceeded, " + "omitting host name option."); + } else { + *q++ = RFC1533_HOSTNAME; + *q++ = val; + memcpy(q, slirp->client_hostname, val); + q += val; + } } if (slirp->vdomainname) { val = strlen(slirp->vdomainname); - *q++ = RFC1533_DOMAINNAME; - *q++ = val; - memcpy(q, slirp->vdomainname, val); - q += val; + if (q + val + 2 >= end) { + g_warning("DHCP packet size exceeded, " + "omitting domain name option."); + } else { + *q++ = RFC1533_DOMAINNAME; + *q++ = val; + memcpy(q, slirp->vdomainname, val); + q += val; + } } if (slirp->vdnssearch) { - size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend); val = slirp->vdnssearch_len; - if (val + 1 > spaceleft) { + if (q + val >= end) { g_warning("DHCP packet size exceeded, " "omitting domain-search option."); } else { @@ -331,6 +342,7 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp) memcpy(q, nak_msg, sizeof(nak_msg) - 1); q += sizeof(nak_msg) - 1; } + assert(q < end); *q = RFC1533_END; daddr.sin_addr.s_addr = 0xffffffffu; From patchwork Thu Sep 6 05:43:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10589881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 210091669 for ; Thu, 6 Sep 2018 05:48:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10ABF2A52A for ; Thu, 6 Sep 2018 05:48:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 048022A547; Thu, 6 Sep 2018 05:48:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 620662A53B for ; Thu, 6 Sep 2018 05:48:31 +0000 (UTC) Received: from localhost ([::1]:59465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxn9a-0001jB-M5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Sep 2018 01:48:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxn8H-00087v-7W for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:47:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxn5V-0000VM-55 for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55096 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxn5U-0000SQ-Q5 for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62469804B4DB; Thu, 6 Sep 2018 05:44:16 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-55.pek2.redhat.com [10.72.12.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id E99E62022EEE; Thu, 6 Sep 2018 05:44:09 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 13:43:39 +0800 Message-Id: <20180906054340.28988-4-famz@redhat.com> In-Reply-To: <20180906054340.28988-1-famz@redhat.com> References: <20180906054340.28988-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 06 Sep 2018 05:44:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 06 Sep 2018 05:44:16 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/4] slirp: Implement RFC2132 TFTP server name 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 , Thomas Huth , Fam Zheng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Samuel Thibault , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Brad Smith Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This new usernet option can be used to add data for option 66 (tftp server name) in the BOOTP reply, which is useful in PXE based automatic OS install such as OpenBSD. Signed-off-by: Fam Zheng Reviewed-by: Thomas Huth --- net/slirp.c | 12 ++++++++++-- qapi/net.json | 5 ++++- qemu-options.hx | 7 ++++++- slirp/bootp.c | 13 +++++++++++++ slirp/bootp.h | 1 + slirp/libslirp.h | 1 + slirp/slirp.c | 2 ++ slirp/slirp.h | 1 + 8 files changed, 38 insertions(+), 4 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index fd21dc728c..53f7b89696 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -158,6 +158,7 @@ static int net_slirp_init(NetClientState *peer, const char *model, const char *vnameserver, const char *vnameserver6, const char *smb_export, const char *vsmbserver, const char **dnssearch, const char *vdomainname, + const char *tftp_server_name, Error **errp) { /* default settings according to historic slirp */ @@ -375,6 +376,11 @@ static int net_slirp_init(NetClientState *peer, const char *model, return -1; } + if (tftp_server_name && strlen(tftp_server_name) > 255) { + error_setg(errp, "'tftp-server-name' parameter cannot exceed 255 bytes"); + return -1; + } + nc = qemu_new_net_client(&net_slirp_info, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), @@ -385,7 +391,8 @@ static int net_slirp_init(NetClientState *peer, const char *model, s->slirp = slirp_init(restricted, ipv4, net, mask, host, ipv6, ip6_prefix, vprefix6_len, ip6_host, - vhostname, tftp_export, bootfile, dhcp, + vhostname, tftp_server_name, + tftp_export, bootfile, dhcp, dns, ip6_dns, dnssearch, vdomainname, s); QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry); @@ -975,7 +982,8 @@ int net_init_slirp(const Netdev *netdev, const char *name, user->ipv6_host, user->hostname, user->tftp, user->bootfile, user->dhcpstart, user->dns, user->ipv6_dns, user->smb, - user->smbserver, dnssearch, user->domainname, errp); + user->smbserver, dnssearch, user->domainname, + user->tftp_server_name, errp); while (slirp_configs) { config = slirp_configs; diff --git a/qapi/net.json b/qapi/net.json index c86f351161..8f99fd911d 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -174,6 +174,8 @@ # # @guestfwd: forward guest TCP connections # +# @tftp-server-name: RFC2132 "TFTP server name" string (Since 3.1) +# # Since: 1.2 ## { 'struct': 'NetdevUserOptions', @@ -198,7 +200,8 @@ '*smb': 'str', '*smbserver': 'str', '*hostfwd': ['String'], - '*guestfwd': ['String'] } } + '*guestfwd': ['String'], + '*tftp-server-name': 'str' } } ## # @NetdevTapOptions: diff --git a/qemu-options.hx b/qemu-options.hx index 654ef484d9..2c2acbb14b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1842,7 +1842,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " [,ipv6[=on|off]][,ipv6-net=addr[/int]][,ipv6-host=addr]\n" " [,restrict=on|off][,hostname=host][,dhcpstart=addr]\n" " [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,domainname=domain]\n" - " [,tftp=dir][,bootfile=f][,hostfwd=rule][,guestfwd=rule]" + " [,tftp=dir][,tftp-server-name=name][,bootfile=f][,hostfwd=rule][,guestfwd=rule]" #ifndef _WIN32 "[,smb=dir[,smbserver=addr]]\n" #endif @@ -2079,6 +2079,11 @@ server. The files in @var{dir} will be exposed as the root of a TFTP server. The TFTP client on the guest must be configured in binary mode (use the command @code{bin} of the Unix TFTP client). +@item tftp-server-name=@var{name} +In BOOTP reply, broadcast @var{name} as the "TFTP server name" (RFC2132 option +66). This can be used to advise the guest to load boot files or configurations +from a different server than the host address. + @item bootfile=@var{file} When using the user mode network stack, broadcast @var{file} as the BOOTP filename. In conjunction with @option{tftp}, this can be used to network boot diff --git a/slirp/bootp.c b/slirp/bootp.c index 1e8185f0ec..7b1af73c95 100644 --- a/slirp/bootp.c +++ b/slirp/bootp.c @@ -318,6 +318,19 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp) } } + if (slirp->tftp_server_name) { + val = strlen(slirp->tftp_server_name); + if (q + val + 2 >= end) { + g_warning("DHCP packet size exceeded, " + "omitting tftp-server-name option."); + } else { + *q++ = RFC2132_TFTP_SERVER_NAME; + *q++ = val; + memcpy(q, slirp->tftp_server_name, val); + q += val; + } + } + if (slirp->vdnssearch) { val = slirp->vdnssearch_len; if (q + val >= end) { diff --git a/slirp/bootp.h b/slirp/bootp.h index 394525733e..4043489835 100644 --- a/slirp/bootp.h +++ b/slirp/bootp.h @@ -70,6 +70,7 @@ #define RFC2132_MAX_SIZE 57 #define RFC2132_RENEWAL_TIME 58 #define RFC2132_REBIND_TIME 59 +#define RFC2132_TFTP_SERVER_NAME 66 #define DHCPDISCOVER 1 #define DHCPOFFER 2 diff --git a/slirp/libslirp.h b/slirp/libslirp.h index 740408a96e..42e42e9a2a 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -13,6 +13,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, bool in6_enabled, struct in6_addr vprefix_addr6, uint8_t vprefix_len, struct in6_addr vhost6, const char *vhostname, + const char *tftp_server_name, const char *tftp_path, const char *bootfile, struct in_addr vdhcp_start, struct in_addr vnameserver, struct in6_addr vnameserver6, const char **vdnssearch, diff --git a/slirp/slirp.c b/slirp/slirp.c index 5c3bd6163f..51de41fc02 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -283,6 +283,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, bool in6_enabled, struct in6_addr vprefix_addr6, uint8_t vprefix_len, struct in6_addr vhost6, const char *vhostname, + const char *tftp_server_name, const char *tftp_path, const char *bootfile, struct in_addr vdhcp_start, struct in_addr vnameserver, struct in6_addr vnameserver6, const char **vdnssearch, @@ -321,6 +322,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, slirp->vdhcp_startaddr = vdhcp_start; slirp->vnameserver_addr = vnameserver; slirp->vnameserver_addr6 = vnameserver6; + slirp->tftp_server_name = g_strdup(tftp_server_name); if (vdnssearch) { translate_dnssearch(slirp, vdnssearch); diff --git a/slirp/slirp.h b/slirp/slirp.h index 10b410898a..b80725a0d6 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -212,6 +212,7 @@ struct Slirp { /* tftp states */ char *tftp_prefix; struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX]; + char *tftp_server_name; ArpTable arp_table; NdpTable ndp_table; From patchwork Thu Sep 6 05:43:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10589877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1954B6CB for ; Thu, 6 Sep 2018 05:48:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07D842A52A for ; Thu, 6 Sep 2018 05:48:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE6672A547; Thu, 6 Sep 2018 05:48:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 55DAB2A52A for ; Thu, 6 Sep 2018 05:48:26 +0000 (UTC) Received: from localhost ([::1]:59464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxn9U-0001eU-Ic for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Sep 2018 01:48:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxn8C-00087v-MY for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:47:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxn5a-0000qK-7k for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53698 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxn5a-0000na-0C for qemu-devel@nongnu.org; Thu, 06 Sep 2018 01:44:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9820840241C0; Thu, 6 Sep 2018 05:44:21 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-55.pek2.redhat.com [10.72.12.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07FDB2022EEE; Thu, 6 Sep 2018 05:44:16 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 13:43:40 +0800 Message-Id: <20180906054340.28988-5-famz@redhat.com> In-Reply-To: <20180906054340.28988-1-famz@redhat.com> References: <20180906054340.28988-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 06 Sep 2018 05:44:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 06 Sep 2018 05:44:21 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 4/4] tests: vm: auto_install OpenBSD 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 , Thomas Huth , Fam Zheng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Samuel Thibault , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Brad Smith Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Upgrade OpenBSD to 6.3 using auto_install. Especially, drop SDL1, include SDL2. Signed-off-by: Fam Zheng --- tests/vm/basevm.py | 6 ++-- tests/vm/openbsd | 81 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py index 7e58d9e0ca..3f5e9e48cb 100755 --- a/tests/vm/basevm.py +++ b/tests/vm/basevm.py @@ -65,8 +65,6 @@ class BaseVM(object): self._stdout = self._devnull self._args = [ \ "-nodefaults", "-m", "4G", - "-netdev", "user,id=vnet,hostfwd=:127.0.0.1:0-:22", - "-device", "virtio-net-pci,netdev=vnet", "-vnc", "127.0.0.1:0,to=20", "-serial", "file:%s" % os.path.join(self._tmpdir, "serial.out")] if vcpus: @@ -145,8 +143,10 @@ class BaseVM(object): "-device", "virtio-blk,drive=%s,serial=%s,bootindex=1" % (name, name)] - def boot(self, img, extra_args=[]): + def boot(self, img, extra_args=[], extra_usernet_args=""): args = self._args + [ + "-netdev", "user,id=vnet,hostfwd=:127.0.0.1:0-:22" + extra_usernet_args, + "-device", "virtio-net-pci,netdev=vnet", "-device", "VGA", "-drive", "file=%s,if=none,id=drive0,cache=writeback" % img, "-device", "virtio-blk,drive=drive0,bootindex=0"] diff --git a/tests/vm/openbsd b/tests/vm/openbsd index 52500ee52b..629a219ffb 100755 --- a/tests/vm/openbsd +++ b/tests/vm/openbsd @@ -14,6 +14,9 @@ import os import sys import subprocess +import time +import atexit +import tempfile import basevm class OpenBSDVM(basevm.BaseVM): @@ -23,22 +26,80 @@ class OpenBSDVM(basevm.BaseVM): rm -rf /var/tmp/qemu-test.* cd $(mktemp -d /var/tmp/qemu-test.XXXXXX); tar -xf /dev/rsd1c; - ./configure --cc=x86_64-unknown-openbsd6.1-gcc-4.9.4 --python=python2.7 {configure_opts}; + ./configure {configure_opts}; gmake --output-sync -j{jobs} {verbose}; # XXX: "gmake check" seems to always hang or fail #gmake --output-sync -j{jobs} check {verbose}; """ + def _install_os(self, img): + tmpdir = tempfile.mkdtemp() + pxeboot = self._download_with_cache("https://fastly.cdn.openbsd.org/pub/OpenBSD/6.3/amd64/pxeboot", + sha256sum="60029919798f48ea40ecb123adfed6217f099d5ed9cd1a6c7de5b544d7b7b0f6") + bsd_rd = self._download_with_cache("https://fastly.cdn.openbsd.org/pub/OpenBSD/6.3/amd64/bsd.rd", + sha256sum="1c0adb43a02ae3aee512bcf0829dac0ccb2e4d614b161049af7ce530e5da2dfc") + install = self._download_with_cache("https://fastly.cdn.openbsd.org/pub/OpenBSD/6.3/amd64/install63.iso", + sha256sum='ee775405dd7926975befbc3fef23de8c4b5a726c3b5075e4848fcd3a2a712ea8') + subprocess.check_call(["qemu-img", "create", img, "32G"]) + subprocess.check_call(["cp", pxeboot, os.path.join(tmpdir, "auto_install")]) + subprocess.check_call(["cp", bsd_rd, os.path.join(tmpdir, "bsd")]) + + self._gen_install_conf(tmpdir) + # BOOTP filename being auto_install makes sure OpenBSD installer + # not prompt for "auto install mode" + usernet_args = ",tftp=%s,bootfile=/auto_install" % tmpdir + usernet_args += ",tftp-server-name=10.0.2.4" + usernet_args += ",guestfwd=tcp:10.0.2.4:80-cmd:cat %s" % \ + os.path.join(tmpdir, "install.conf") + self.boot(img, + extra_args=["-boot", "once=n", "-no-reboot", + "-cdrom", install], + extra_usernet_args=usernet_args) + self.wait() + + def _gen_install_conf(self, tmpdir): + contents = """\ +HTTP/1.0 200 OK + +System hostname = qemu-openbsd +Password for root = qemupass +Public ssh key for root = {pub_key} +Allow root ssh login = yes +Network interfaces = vio0 +IPv4 address for vio0 = dhcp +Setup a user = qemu +Password for user = qemupass +Public ssh key for user = {pub_key} +What timezone are you in = US/Eastern +Server = fastly.cdn.openbsd.org +Use http = yes +Default IPv4 route = 10.0.2.2 +Location of sets = cd0 +Set name(s) = all +Continue without verification = yes +""".format(pub_key=basevm.SSH_PUB_KEY) + with open(os.path.join(tmpdir, "install.conf"), "w") as f: + f.write(contents) + def build_image(self, img): - cimg = self._download_with_cache("http://download.patchew.org/openbsd-6.1-amd64.img.xz", - sha256sum='8c6cedc483e602cfee5e04f0406c64eb99138495e8ca580bc0293bcf0640c1bf') - img_tmp_xz = img + ".tmp.xz" - img_tmp = img + ".tmp" - subprocess.check_call(["cp", "-f", cimg, img_tmp_xz]) - subprocess.check_call(["xz", "-df", img_tmp_xz]) - if os.path.exists(img): - os.remove(img) - os.rename(img_tmp, img) + + self._install_os(img + ".tmp") + + self.boot(img + ".tmp") + self.wait_ssh() + + self.ssh_root("usermod -G operator qemu") + self.ssh_root("echo https://fastly.cdn.openbsd.org/pub/OpenBSD > /etc/installurl") + for pkg in ["git", "gmake", "glib2", "bison", "sdl2"]: + self.ssh_root("pkg_add " + pkg) + self.ssh_root("ln -sf /usr/local/bin/python2.7 /usr/local/bin/python") + self.ssh_root("ln -sf /usr/local/bin/python2.7-2to3 /usr/local/bin/2to3") + self.ssh_root("ln -sf /usr/local/bin/python2.7-config /usr/local/bin/python-config") + self.ssh_root("ln -sf /usr/local/bin/pydoc2.7 /usr/local/bin/pydoc") + self.ssh_root("shutdown -p now") + self.wait() + + subprocess.check_call(["mv", img + ".tmp", img]) if __name__ == "__main__": sys.exit(basevm.main(OpenBSDVM))