Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3367816ybp; Sun, 6 Oct 2019 10:23:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnjkcVewK2OgxUvPrVVsVAXYLWeQpcopoTHBPUhZOmtwexT+YpBOl2LDG6zYB3cFmFnrfA X-Received: by 2002:a50:9fce:: with SMTP id c72mr25905292edf.166.1570382602245; Sun, 06 Oct 2019 10:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570382602; cv=none; d=google.com; s=arc-20160816; b=o4GgmL9PqF/TOoNMbRqQbQFP+tgq64JrKZP6pDA4+BjOQcZlVJC1mfRpQJ1FVS1MQ8 rB+5ztHCwuMdyOH8PN4FE3qbAaZqsGmQyg62Iaf7Xo+FLeDu+S/juuuHr1YW7yamiuJp T/kDcfSBBSkd1ljQtUu6B5Cmx4+FERtTBSALrD0FktDQTyTN1c/xKw7bZrYTUftbQ/ZR JkCCAQPW/IVzDef/g94IAStxQCwgRrzFPwuWfhdFPvYuYaS6FJQRHru5/j8M46RHkr59 WNdkk+XTfSzU0U3X7U+yC24W/skhPGN+/3CNlxvRIAQ4AUW4JXS877F0Fk/sX6ZSuKlN zvMw== 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=/L7J5hZUzF0cue4ZMK6cCXOC8o2nznt7TUb+xnQzm0I=; b=EulNFe9AsDuMiWjq1mR+a5EDdalqDGGQvI7tyM4Vm1UwcJALyhJwplrbhcUR4MdCQb LkHTZQeLAbtxc6jeas92UNn7RyfPlAqyqpCOFnW1gZpq8qwW5iUNxV7KnzYeHNDaE4ug KiFwO/40gHym3v/O/SXhyWOMfvfx2sAO1on+2U+9kX6l5A4JtOWNmuCJTKEqyfTS1b6k QfJOS2v//foqXIWkWPvT+QreHsAoSBGOjf1m1Ets2Afmy/ixwf+Cq3TRYTmCcZaJTnMs TIc/BgOaIg2HHhJysbsIKfLU0V3XousQRegDL63zDMwAUUgyd5L8NS16eL8EiaiR8qLF LOtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q8OTqDO+; 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 90si8451358edj.72.2019.10.06.10.22.58; Sun, 06 Oct 2019 10:23:22 -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=Q8OTqDO+; 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 S1727311AbfJFRUo (ORCPT + 99 others); Sun, 6 Oct 2019 13:20:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:45746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727300AbfJFRUm (ORCPT ); Sun, 6 Oct 2019 13:20:42 -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 3002B20862; Sun, 6 Oct 2019 17:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570382441; bh=J+cyFnyKLWK0/kJ1+ufnTyqwGSkc7/zvvSzD47UPj4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q8OTqDO+LQ6NOYe8ISJuDMNSlPQqLPEnIOzKXWWAv3+vXn31MRtO0sFDaEMyMXOKr tV5z785eYePgfrhx+owsQdTcs6ey+CFhzk5ykz7W4AcBRzlQhnF1xH4XdbXrVFscsf YaPn/EdoZsDkoCa5+BAvCpO9wtD2Bn8+kfUhFzN0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongli Zhang , Juergen Gross , "David S. Miller" Subject: [PATCH 4.4 31/36] xen-netfront: do not use ~0U as error return value for xennet_fill_frags() Date: Sun, 6 Oct 2019 19:19:13 +0200 Message-Id: <20191006171059.679886068@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171038.266461022@linuxfoundation.org> References: <20191006171038.266461022@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 a761129e3625688310aecf26e1be9e98e85f8eb5 ] xennet_fill_frags() uses ~0U as return value when the sk_buff is not able to cache extra fragments. This is incorrect because the return type of xennet_fill_frags() is RING_IDX and 0xffffffff is an expected value for ring buffer index. In the situation when the rsp_cons is approaching 0xffffffff, the return value of xennet_fill_frags() may become 0xffffffff which xennet_poll() (the caller) would regard as error. As a result, queue->rx.rsp_cons is set incorrectly because it is updated only when there is error. If there is no error, xennet_poll() would be responsible to update queue->rx.rsp_cons. Finally, 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. The symptom is similar to the one fixed in commit 00b368502d18 ("xen-netfront: do not assume sk_buff_head list is empty in error handling"). This patch changes the return type of xennet_fill_frags() to indicate whether it is successful or failed. The queue->rx.rsp_cons will be always updated inside this function. Fixes: ad4f15dc2c70 ("xen/netfront: don't bug in case of too many frags") Signed-off-by: Dongli Zhang Reviewed-by: Juergen Gross Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/xen-netfront.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -874,9 +874,9 @@ static int xennet_set_skb_gso(struct sk_ return 0; } -static RING_IDX xennet_fill_frags(struct netfront_queue *queue, - struct sk_buff *skb, - struct sk_buff_head *list) +static int xennet_fill_frags(struct netfront_queue *queue, + struct sk_buff *skb, + struct sk_buff_head *list) { RING_IDX cons = queue->rx.rsp_cons; struct sk_buff *nskb; @@ -895,7 +895,7 @@ static RING_IDX xennet_fill_frags(struct if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { queue->rx.rsp_cons = ++cons + skb_queue_len(list); kfree_skb(nskb); - return ~0U; + return -ENOENT; } skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, @@ -906,7 +906,9 @@ static RING_IDX xennet_fill_frags(struct kfree_skb(nskb); } - return cons; + queue->rx.rsp_cons = cons; + + return 0; } static int checksum_setup(struct net_device *dev, struct sk_buff *skb) @@ -1032,8 +1034,7 @@ err: skb->data_len = rx->status; skb->len += rx->status; - i = xennet_fill_frags(queue, skb, &tmpq); - if (unlikely(i == ~0U)) + if (unlikely(xennet_fill_frags(queue, skb, &tmpq))) goto err; if (rx->flags & XEN_NETRXF_csum_blank) @@ -1043,7 +1044,7 @@ err: __skb_queue_tail(&rxq, skb); - queue->rx.rsp_cons = ++i; + i = ++queue->rx.rsp_cons; work_done++; }