Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1656476ybj; Fri, 20 Sep 2019 14:14:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjZGYyPl51bkrI0VOmH9cRGKJWsuGnPZy79M7jcXHpb5r+SNE3MfzkeePasioo6dBGZ4w5 X-Received: by 2002:a50:ea8c:: with SMTP id d12mr10786005edo.87.1569014053470; Fri, 20 Sep 2019 14:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569014053; cv=none; d=google.com; s=arc-20160816; b=YOTB737/gGvxXD4IJUPXm8GHDVmMUozAsvAAiahZ7DMRmWCcFeRSTZTV/dzsQTb7Jh f6cvu0FjnV/xWqWTkPe0PBPt+7fCrQrp+StFlWxSfSXPA+ZagMI9d7uakXVPN6inBc/g D//YipHtybT89wPhrKfb6Y8LH5sj0u+314H4qNn4vMCafOzSGUoJ2z7+u8EI0Oz+frIh eGO5RhBe9j2PlLrTkJ94pOrA6tNdI3RUCTvAnFQdm4X5PRp72NpLiK6RV6nWFbr8HFbN 3gudCc/Hmudir/zA5ECLDRaQoaMAYzCGoZzq84oCm5e6USgKwjNSMmEHOBzUaYiXQzJw DXXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5ztxLI8HTAmoq1JKTK8y+rT+PkQ0KuhQoVrAW7Xh9aA=; b=LNT6zbcwheW+Rw1y7UAo90eCBS4/fnaKJnGA01K9sqigJiQrplWJJ40BxyOS32tHe5 5riNc71vF173SOghzD/97OrF96KrI+q0gO1v47DIA+jcut5wL6414NqQsBK2xG0jLji5 RzYW2vuefoC7QjAtf2jkyGmUDTsOIZyTHJOgGUKqBWlZSQyLV+ihTK2qy8T7Xl7dyE9J V6WGu2evOA+E4Q8eJtNB2hCkZWdm12C6PZTLcKrnvO2VpBrHIZPY2Cye4yAQDmxaqjh1 9b2hr+QpxYvgoZxzK9h27SdwyQoOyxi9oja6elXA/S7UDQArdMiNl5D5B27LydHCyMrj ZVTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TKBIDNKZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si2020496edv.393.2019.09.20.14.13.48; Fri, 20 Sep 2019 14:14:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TKBIDNKZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406863AbfISWgr (ORCPT + 99 others); Thu, 19 Sep 2019 18:36:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:43432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405105AbfISWGF (ORCPT ); Thu, 19 Sep 2019 18:06:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BF4C621927; Thu, 19 Sep 2019 22:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568930765; bh=slnhpFEp5xIh7mPkMPWgPhf7Q9Yh1FvqHssoFJ05Vfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TKBIDNKZMiuXVCSC4GNzt0pm05hysQtgAbx9+M0A+SqOkOMymTHq+5nQS2viuSehu NGtupbLK9z9Led/NJex53Hj4pKXtzmrpb5T/OwFuiKnji56Q/tyJuFNp8WZ26t+G7Q xFCr3eLY4WZ/acF9EPNsy30Z1IyIE/3tzKnzXNA8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongli Zhang , "David S. Miller" Subject: [PATCH 5.3 08/21] xen-netfront: do not assume sk_buff_head list is empty in error handling Date: Fri, 20 Sep 2019 00:03:09 +0200 Message-Id: <20190919214702.452008775@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919214657.842130855@linuxfoundation.org> References: <20190919214657.842130855@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongli Zhang [ Upstream commit 00b368502d18f790ab715e055869fd4bb7484a9b ] When skb_shinfo(skb) is not able to cache extra fragment (that is, skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS), xennet_fill_frags() assumes the sk_buff_head list is already empty. As a result, cons is increased only by 1 and returns to error handling path in xennet_poll(). However, if the sk_buff_head list is not empty, queue->rx.rsp_cons may be set incorrectly. That is, queue->rx.rsp_cons would point to the rx ring buffer entries whose queue->rx_skbs[i] and queue->grant_rx_ref[i] are already cleared to NULL. This leads to NULL pointer access in the next iteration to process rx ring buffer entries. Below is how xennet_poll() does error handling. All remaining entries in tmpq are accounted to queue->rx.rsp_cons without assuming how many outstanding skbs are remained in the list. 985 static int xennet_poll(struct napi_struct *napi, int budget) ... ... 1032 if (unlikely(xennet_set_skb_gso(skb, gso))) { 1033 __skb_queue_head(&tmpq, skb); 1034 queue->rx.rsp_cons += skb_queue_len(&tmpq); 1035 goto err; 1036 } It is better to always have the error handling in the same way. Fixes: ad4f15dc2c70 ("xen/netfront: don't bug in case of too many frags") Signed-off-by: Dongli Zhang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/xen-netfront.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -906,7 +906,7 @@ static RING_IDX xennet_fill_frags(struct __pskb_pull_tail(skb, pull_to - skb_headlen(skb)); } if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { - queue->rx.rsp_cons = ++cons; + queue->rx.rsp_cons = ++cons + skb_queue_len(list); kfree_skb(nskb); return ~0U; }