From patchwork Sun Jun 4 02:16:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9764591 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 3FF906032D for ; Sun, 4 Jun 2017 02:17:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3034E23E64 for ; Sun, 4 Jun 2017 02:17:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24F332582C; Sun, 4 Jun 2017 02:17:24 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 3AC7523E64 for ; Sun, 4 Jun 2017 02:17:23 +0000 (UTC) Received: (qmail 3671 invoked by uid 550); 4 Jun 2017 02:17:04 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 3538 invoked from network); 4 Jun 2017 02:17:02 -0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=lUBc rCW71EVGHlKy9CPApEzL4ec=; b=mIGRk1zLQqeG7DyatIDsJU0ioh20/BqqglpW hp0F16pNTVAAY9DFfGFJMBGVlIJkW/UzXZIjMC0xCAVZpPcRe4WmlmI/7dGFtk4f 4O0ouflZLdIrAL852tIpYhh2mM80e5KG1z+yVorpXv1LoUWh7TksUrrSOi7IvfO4 hXSdlSAiD5K/h4DGn/5O3HPtFupyJ1gVAXi+rmQXGW7rjz2DKO7XRO5Z/U9fL9br 0Flgp2ujImiQuQLnFNy3hu5dTAmZETLB3CExWSp6S0MT6XETO7NUwlQy/ICkdQrw 1VQ6/zjrMi1UZCA7JUMU9h+hQnkEdFudvSvdKQ06DOn8padzYg== From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, kernel-hardening@lists.openwall.com Cc: "Jason A. Donenfeld" , "Michael S. Tsirkin" , Jason Wang Date: Sun, 4 Jun 2017 04:16:26 +0200 Message-Id: <20170604021626.11968-6-Jason@zx2c4.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170604021626.11968-1-Jason@zx2c4.com> References: <20170604021626.11968-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH net-next v10 5/5] virtio_net: check return value of skb_to_sgvec always X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jason A. Donenfeld Reviewed-by: Sergei Shtylyov Cc: "Michael S. Tsirkin" Cc: Jason Wang --- drivers/net/virtio_net.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 3e9246cc49c3..57763d30cabb 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1150,7 +1150,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) struct virtio_net_hdr_mrg_rxbuf *hdr; const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; struct virtnet_info *vi = sq->vq->vdev->priv; - unsigned num_sg; + int num_sg; unsigned hdr_len = vi->hdr_len; bool can_push; @@ -1177,11 +1177,16 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) if (can_push) { __skb_push(skb, hdr_len); num_sg = skb_to_sgvec(skb, sq->sg, 0, skb->len); + if (unlikely(num_sg < 0)) + return num_sg; /* Pull header back to avoid skew in tx bytes calculations. */ __skb_pull(skb, hdr_len); } else { sg_set_buf(sq->sg, hdr, hdr_len); - num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len) + 1; + num_sg = skb_to_sgvec(skb, sq->sg + 1, 0, skb->len); + if (unlikely(num_sg < 0)) + return num_sg; + num_sg++; } return virtqueue_add_outbuf(sq->vq, sq->sg, num_sg, skb, GFP_ATOMIC); }