Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp693628ybg; Mon, 1 Jun 2020 11:51:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeMHdk3awAJIclnFNnf4xC+BBzpUxPAehh+el2qEeeA6Yc0vXgtWWuPF11dfiPtWEMssga X-Received: by 2002:a17:906:28da:: with SMTP id p26mr19645498ejd.551.1591037514774; Mon, 01 Jun 2020 11:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591037514; cv=none; d=google.com; s=arc-20160816; b=yv66oed0iDzlaCyybHW1xC9bE5PUVt+s5HqegrIvwkFAzrPEKHs04rtg6fd4/b2Zjm HGJcHsbgBRaSaHMVP7Vw9Xtduw6pvwOVjeOfJ+TgVdAmCTQUnhmIVQWfs4rAViQHG6H2 nx7ABdo4hEWglVJEYciRWy8Oaf3S9wLiaZyXnGFFrVw4oIgWwXvhD5n1NSLPQdIncerh jrkiHSW4qkN5RrNl3Z3cKKcQZfngm6lV1kH8fRimd7rHWclhiBKRqe2vyJatif625DyG RvYIozMaR1cdIl5vJ21+zuu/svfGntwJRytPrIRyRxaxAiC6+B06lMBIZTxAcZqAWnUK ALvg== 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=fTytP+ttUfkZssg6i4pDPiAhZZg26ZNL31V5r4kzUOA=; b=Dm/R6ipmfR3CvEDo/3ZZYuGjkqfyP2Aefxm3eKWCCC1j9adqH+NQRAvoW4/7Ql1dgE W9PrN+sa+o+SWm9OAx8JlNGMp3ala6Nl+IJWMZ6eJ2wF+WyFGTClsDSlGUywdv1mS/DU zv4Md3WFRXeb2yA73bNFhiTXWrKQy4x2iuWV0neAGJUnlxxs8+iiMwrAjd8haN//4kX+ jr/Ab94FKrp3CX1Wxy1p8kddNvgi78sGRDmSV+yANfpGrYIywF6j4m68ncmSSp9jfG4q ewU3WZJQw18XnPHb1kHxo597rxjuPKTcJtKyAr2ZbnkcE6LuUq/x6vXqd2ksHBxLKrbd cODQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1zNkROCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si123666edx.506.2020.06.01.11.51.31; Mon, 01 Jun 2020 11:51:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1zNkROCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729116AbgFAStt (ORCPT + 99 others); Mon, 1 Jun 2020 14:49:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:52394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730482AbgFASGm (ORCPT ); Mon, 1 Jun 2020 14:06: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 90DD2207D0; Mon, 1 Jun 2020 18:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034802; bh=5PdVzUgIIVWPSy0wNPz7EaDxgWyXOWdWg0/IFX5111o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1zNkROCe+a4zSe/57DkmTbmdrbtCqBoL4VoIy0Ez9IzKu4m87Hy8FE/Yp0izUklCq Vyxvsh2YkXZRFBm+k60kXPMoNMRx7yfeUl2fQqmovZHsWnHnmRvVodrCI1LgeGo7NP iEal9Yh53eL/Aq7NMXZ/EJa6/UrXSA7IlByTdPX0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boris Sukholitko , Edward Cree , "David S. Miller" Subject: [PATCH 5.4 006/142] __netif_receive_skb_core: pass skb by reference Date: Mon, 1 Jun 2020 19:52:44 +0200 Message-Id: <20200601174038.705010673@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@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: Boris Sukholitko [ Upstream commit c0bbbdc32febd4f034ecbf3ea17865785b2c0652 ] __netif_receive_skb_core may change the skb pointer passed into it (e.g. in rx_handler). The original skb may be freed as a result of this operation. The callers of __netif_receive_skb_core may further process original skb by using pt_prev pointer returned by __netif_receive_skb_core thus leading to unpleasant effects. The solution is to pass skb by reference into __netif_receive_skb_core. v2: Added Fixes tag and comment regarding ppt_prev and skb invariant. Fixes: 88eb1944e18c ("net: core: propagate SKB lists through packet_type lookup") Signed-off-by: Boris Sukholitko Acked-by: Edward Cree Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4713,11 +4713,12 @@ static inline int nf_ingress(struct sk_b return 0; } -static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc, +static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, struct packet_type **ppt_prev) { struct packet_type *ptype, *pt_prev; rx_handler_func_t *rx_handler; + struct sk_buff *skb = *pskb; struct net_device *orig_dev; bool deliver_exact = false; int ret = NET_RX_DROP; @@ -4748,8 +4749,10 @@ another_round: ret2 = do_xdp_generic(rcu_dereference(skb->dev->xdp_prog), skb); preempt_enable(); - if (ret2 != XDP_PASS) - return NET_RX_DROP; + if (ret2 != XDP_PASS) { + ret = NET_RX_DROP; + goto out; + } skb_reset_mac_len(skb); } @@ -4899,6 +4902,13 @@ drop: } out: + /* The invariant here is that if *ppt_prev is not NULL + * then skb should also be non-NULL. + * + * Apparently *ppt_prev assignment above holds this invariant due to + * skb dereferencing near it. + */ + *pskb = skb; return ret; } @@ -4908,7 +4918,7 @@ static int __netif_receive_skb_one_core( struct packet_type *pt_prev = NULL; int ret; - ret = __netif_receive_skb_core(skb, pfmemalloc, &pt_prev); + ret = __netif_receive_skb_core(&skb, pfmemalloc, &pt_prev); if (pt_prev) ret = INDIRECT_CALL_INET(pt_prev->func, ipv6_rcv, ip_rcv, skb, skb->dev, pt_prev, orig_dev); @@ -4986,7 +4996,7 @@ static void __netif_receive_skb_list_cor struct packet_type *pt_prev = NULL; skb_list_del_init(skb); - __netif_receive_skb_core(skb, pfmemalloc, &pt_prev); + __netif_receive_skb_core(&skb, pfmemalloc, &pt_prev); if (!pt_prev) continue; if (pt_curr != pt_prev || od_curr != orig_dev) {