Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1317727pxp; Thu, 17 Mar 2022 07:13:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQojo8wd8qBU5RsGfg4cqhBCPd3JG7meOlrMnkOMKoNBVzVe7BdBXciI4brxTDRVYg/WW2 X-Received: by 2002:a17:90a:a78f:b0:1bc:8042:9330 with SMTP id f15-20020a17090aa78f00b001bc80429330mr15913428pjq.229.1647526388970; Thu, 17 Mar 2022 07:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647526388; cv=none; d=google.com; s=arc-20160816; b=aCQDH0oYT4HQVT++lT0QCG0ylVZW6tF37nzCg5VFRanwkRmYWD5GW4npt4leBzv8hH zcRDyWJ1sivj1NaErftxgLuAUyHimSqattNfZuL0U34gcgDNSV+I7bR4kuwdaLwl3JKL /zkmwBXW2homFpby/KGMDPDpcNWMbtd04uqqvWMylF+pAO+7PoJ4r12ZTQXVsN2XLCo8 WcFU8eWqjBA39mpPD3KEKRnDjkA2JG9EZTt5qxw3GFP3j79SOgCVSxUwtRu0EglU4IbA T1J8zbYrY1YCNmwvsY4lOzb9BHtY6jccUcJ2ZETbgD5tis/GeR8lvKCTZzhmLjVuz8u6 TmpQ== 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=iXKyNGrzMtknJJTXSKj6JV5QzrSQNMsFmTRVtYQP8gc=; b=A8xLxCqg0QZILo9edXf4fYrh6HqmRJmMhBUGr/9Fc/cW+5P4HTxxpFUogTul0yzyL6 eh0t7LBUyEyq0I0F45R0cZCJEpKaS23NOC1ltCT6DTbFt7EGbB2uapxgcklLsIWUU5bo XCXhVSjfi1Ckyycnz5ERvMw3Wu8AAl6aif3Dj5mu2Wnja1FOzwHUPnqVhy/AOYORlny+ NCeSIJveU0w2oid2gdX1Ozma7FLXZB4uKLNvbrYcbyMC433bvzdmz+btznt4oNicH6aC g2yvHSMh1j6mKPIjMqSb6Vy4DT/CF+kex1AXwWhQXiekx5qT0aXzXq7oNXK95zV4UW4e 4gKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sr0hceF5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p30-20020a635b1e000000b003816043eef1si2049148pgb.230.2022.03.17.07.12.49; Thu, 17 Mar 2022 07:13:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sr0hceF5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233844AbiCQMtX (ORCPT + 99 others); Thu, 17 Mar 2022 08:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233694AbiCQMtA (ORCPT ); Thu, 17 Mar 2022 08:49:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98DD312340F; Thu, 17 Mar 2022 05:47:39 -0700 (PDT) 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 25B2261021; Thu, 17 Mar 2022 12:47:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DCCDC340E9; Thu, 17 Mar 2022 12:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647521258; bh=Zz3Y5XTimklXXa3tfL6Wp6yGyA1ZsYTh81ohp7mD/Oc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sr0hceF5USzh1kKGr/TVGNdy/VA99xa5DwSl4TEaEgFy7wZHPC9jUmbrPnw5kT9By Fbe5k0N/HWl9DzwCb2EGxCqJPnkmahVTt4X1uo+d3ywixQPlXJ037FA7WeI16ua6nH X+4NSy6Hc5QYqLC2agr3Wfn3qZw+uYo2XX0vPGKs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yan Yan , Steffen Klassert , Sasha Levin Subject: [PATCH 5.4 26/43] xfrm: Fix xfrm migrate issues when address family changes Date: Thu, 17 Mar 2022 13:45:37 +0100 Message-Id: <20220317124528.401378897@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317124527.672236844@linuxfoundation.org> References: <20220317124527.672236844@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yan Yan [ Upstream commit e03c3bba351f99ad932e8f06baa9da1afc418e02 ] xfrm_migrate cannot handle address family change of an xfrm_state. The symptons are the xfrm_state will be migrated to a wrong address, and sending as well as receiving packets wil be broken. This commit fixes it by breaking the original xfrm_state_clone method into two steps so as to update the props.family before running xfrm_init_state. As the result, xfrm_state's inner mode, outer mode, type and IP header length in xfrm_state_migrate can be updated with the new address family. Tested with additions to Android's kernel unit test suite: https://android-review.googlesource.com/c/kernel/tests/+/1885354 Signed-off-by: Yan Yan Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/xfrm/xfrm_state.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 83ee3d337a60..268bba29bb60 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -1539,9 +1539,6 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, memcpy(&x->mark, &orig->mark, sizeof(x->mark)); memcpy(&x->props.smark, &orig->props.smark, sizeof(x->props.smark)); - if (xfrm_init_state(x) < 0) - goto error; - x->props.flags = orig->props.flags; x->props.extra_flags = orig->props.extra_flags; @@ -1625,6 +1622,11 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x, if (!xc) return NULL; + xc->props.family = m->new_family; + + if (xfrm_init_state(xc) < 0) + goto error; + memcpy(&xc->id.daddr, &m->new_daddr, sizeof(xc->id.daddr)); memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr)); -- 2.34.1