Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3702105pxb; Mon, 24 Jan 2022 15:47:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfWGJOWQ+1G1c/ddMFJUuKh3J5V7G4w9jBuCgSJyuj5gSJyOFIMCFDNuq4Hc3D9v2TibtF X-Received: by 2002:a63:6b81:: with SMTP id g123mr13649491pgc.140.1643067968501; Mon, 24 Jan 2022 15:46:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643067968; cv=none; d=google.com; s=arc-20160816; b=VZe3pso7fc06LEtniXufuSOCeIXyyZe46qprU7Ai5xPMoFGTG5Z4YLv/+S5/uJchGO bhzQIyzn0KnGXh8FK4Hy+1OWuJ9zK49glt3EseVUrJsQ52I0naknPAPaQ4eKOKqsA7IB 8FxpfVL0JPa5tRKtZ0Tc3uhNkcPXF+PxY2jr4S/U4rcWvRSc9UD7yITv+tX4S2xF2Yqx llr36M+janfplW9Huebu1phdtF2DMWOERffNqDXVZPwxAuOQWDR2symIcKc2hEDABKFv rrhs1040vOSxXIk9lJZ+dOO9ZSIUJ6J1959h9fsGDwWY1rqj8BNvyUx+o1IdqWBKp3Sn GiOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LKVt5Ao1L/cel+gpywEecvkBUYrEF5aAmRAbyuXdcaw=; b=t9Aze0b+984Oeb44PrkhGihenVhyFrIj3xEu8y4VGYNt4BYIhsRQysbqhjU+0aBtTD D4MwoGPQ/Wf/zOmJh+zhSpbc14sx9Q8hfz2n78qcntjApRvrP7qRTf/AII7YmNY2MvoT 3EELFK3tAmG29+KDDYZTKarB2/96HWAJzNfhyu7tjImO6WC0stiCSaztABK82NeMduFn M5HUPTmkhGgHLcTl8HUFf3i6T7YFuL37WVGBoFURo4kzvZKrOsTG100RwS9yDoH2QOkk WpBgC47N2yrmuT/dY+fKRSgw7dfhZ2pQc5aSdYvUfH7tYKfd6aWsB1HKZOcivfPaLZtf BrZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0opCvy+W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u193si12132536pfc.334.2022.01.24.15.45.56; Mon, 24 Jan 2022 15:46:08 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=0opCvy+W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2360892AbiAXXi2 (ORCPT + 99 others); Mon, 24 Jan 2022 18:38:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841795AbiAXXAC (ORCPT ); Mon, 24 Jan 2022 18:00:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688DAC09D313; Mon, 24 Jan 2022 13:13:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 05D8E61513; Mon, 24 Jan 2022 21:13:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD993C340E5; Mon, 24 Jan 2022 21:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058816; bh=g5jYcDdJTtAaQIzC6WDSvOuOlk9FXh7FUac05QGiE4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0opCvy+WAXd8BVVnovJKlIXyhX4GKDxcLBZ2g8joOodK1Vch/OebnQKWh2Qxg6Jr1 STm1mz2GD0HLBmnvlRFpi9flihbe6AjW8y90PzuEv66KJBAYn5CCHLFD1CLtY0XV1A CFUkIRt/ARf74Hc3yNwltyhp/rTno3vpPFEnP6z8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Raed Salem , Steffen Klassert , Sasha Levin Subject: [PATCH 5.16 0368/1039] net/xfrm: IPsec tunnel mode fix inner_ipproto setting in sec_path Date: Mon, 24 Jan 2022 19:35:57 +0100 Message-Id: <20220124184137.667754585@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Raed Salem [ Upstream commit 45a98ef4922def8c679ca7c454403d1957fe70e7 ] The inner_ipproto saves the inner IP protocol of the plain text packet. This allows vendor's IPsec feature making offload decision at skb's features_check and configuring hardware at ndo_start_xmit, current code implenetation did not handle the case where IPsec is used in tunnel mode. Fix by handling the case when IPsec is used in tunnel mode by reading the protocol of the plain text packet IP protocol. Fixes: fa4535238fb5 ("net/xfrm: Add inner_ipproto into sec_path") Signed-off-by: Raed Salem Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_output.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c index 229544bc70c21..4dc4a7bbe51cf 100644 --- a/net/xfrm/xfrm_output.c +++ b/net/xfrm/xfrm_output.c @@ -647,10 +647,12 @@ static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skb * This requires hardware to know the inner packet type to calculate * the inner header checksum. Save inner ip protocol here to avoid * traversing the packet in the vendor's xmit code. - * If the encap type is IPIP, just save skb->inner_ipproto. Otherwise, - * get the ip protocol from the IP header. + * For IPsec tunnel mode save the ip protocol from the IP header of the + * plain text packet. Otherwise If the encap type is IPIP, just save + * skb->inner_ipproto in any other case get the ip protocol from the IP + * header. */ -static void xfrm_get_inner_ipproto(struct sk_buff *skb) +static void xfrm_get_inner_ipproto(struct sk_buff *skb, struct xfrm_state *x) { struct xfrm_offload *xo = xfrm_offload(skb); const struct ethhdr *eth; @@ -658,6 +660,25 @@ static void xfrm_get_inner_ipproto(struct sk_buff *skb) if (!xo) return; + if (x->outer_mode.encap == XFRM_MODE_TUNNEL) { + switch (x->outer_mode.family) { + case AF_INET: + xo->inner_ipproto = ip_hdr(skb)->protocol; + break; + case AF_INET6: + xo->inner_ipproto = ipv6_hdr(skb)->nexthdr; + break; + default: + break; + } + + return; + } + + /* non-Tunnel Mode */ + if (!skb->encapsulation) + return; + if (skb->inner_protocol_type == ENCAP_TYPE_IPPROTO) { xo->inner_ipproto = skb->inner_ipproto; return; @@ -712,8 +733,7 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb) sp->xvec[sp->len++] = x; xfrm_state_hold(x); - if (skb->encapsulation) - xfrm_get_inner_ipproto(skb); + xfrm_get_inner_ipproto(skb, x); skb->encapsulation = 1; if (skb_is_gso(skb)) { -- 2.34.1