From patchwork Thu Jun 30 09:49:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 9207149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC21B6075A for ; Thu, 30 Jun 2016 09:50:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC9B6285C7 for ; Thu, 30 Jun 2016 09:50:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0DBF28673; Thu, 30 Jun 2016 09:50:22 +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=-6.9 required=2.0 tests=BAYES_00,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 CEAFB285C7 for ; Thu, 30 Jun 2016 09:50:21 +0000 (UTC) Received: from localhost ([::1]:48120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIYbz-0001nA-WF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 30 Jun 2016 05:50:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIYbf-0001mw-AM for qemu-devel@nongnu.org; Thu, 30 Jun 2016 05:50:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIYbZ-0003yc-DD for qemu-devel@nongnu.org; Thu, 30 Jun 2016 05:49:58 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:58777 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIYbZ-0003yN-2n for qemu-devel@nongnu.org; Thu, 30 Jun 2016 05:49:53 -0400 Received: (qmail 30760 invoked by uid 89); 30 Jun 2016 09:49:50 -0000 Received: from [195.62.97.28] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.99.2/21816. hbedv: 8.3.40.44/7.12.99.34. avast: 1.2.2/16062901. spamassassin: 3.4.1. Clear:RC:1(195.62.97.28):. Processed in 0.054736 secs); 30 Jun 2016 09:49:50 -0000 Received: from smtp.kamp.de (HELO submission.kamp.de) ([195.62.97.28]) by mx01.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted); 30 Jun 2016 09:49:50 -0000 X-GL_Whitelist: yes Received: (qmail 6382 invoked from network); 30 Jun 2016 09:49:50 -0000 Received: from lieven-pc.kamp-intra.net (HELO lieven-pc) (relay@kamp.de@::ffff:172.21.12.60) by submission.kamp.de with ESMTPS (DHE-RSA-AES256-GCM-SHA384 encrypted) ESMTPA; 30 Jun 2016 09:49:50 -0000 Received: by lieven-pc (Postfix, from userid 1000) id C764A20834; Thu, 30 Jun 2016 11:49:45 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Thu, 30 Jun 2016 11:49:40 +0200 Message-Id: <1467280180-9234-1-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:248:0:51::16 Subject: [Qemu-devel] [PATCH] net: limit allocation in nc_sendv_compat 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: jasowang@redhat.com, Peter Lieven , dhannawatpooja1@gmail.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP we only need to allocate enough memory to hold the packet. This might be less than NET_BUFSIZE. Additionally fail early if the packet is larger than NET_BUFSIZE. Signed-off-by: Peter Lieven Reviewed-by: Stefan Hajnoczi --- net/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/net.c b/net/net.c index 5f3e5a9..54a578d 100644 --- a/net/net.c +++ b/net/net.c @@ -690,9 +690,13 @@ static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov, buffer = iov[0].iov_base; offset = iov[0].iov_len; } else { - buf = g_new(uint8_t, NET_BUFSIZE); + offset = iov_size(iov, iovcnt); + if (offset > NET_BUFSIZE) { + return -1; + } + buf = g_malloc(offset); buffer = buf; - offset = iov_to_buf(iov, iovcnt, 0, buf, NET_BUFSIZE); + offset = iov_to_buf(iov, iovcnt, 0, buf, offset); } if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {