Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1611750pxp; Thu, 17 Mar 2022 12:41:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyuoGcTBWgyEdMorUApRIra3hrsaV5X+gPA8PSy0tjEyalmnIBY9ptd8JxHi/V1r+6Xpz5 X-Received: by 2002:a63:7d49:0:b0:378:907d:1fc7 with SMTP id m9-20020a637d49000000b00378907d1fc7mr4967419pgn.252.1647546093779; Thu, 17 Mar 2022 12:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647546093; cv=none; d=google.com; s=arc-20160816; b=wtatLWxKDstUXssneYcl9z79HJ1cx3tsvKnVeWlCV9bbfpU/krTKeD8ATXYREbXCVv XFs2kR17j/HgyI48mJkoc92AUCzIn0AvkIie+3VxnD916OKPewzgVu9NThBJoSMdsg3O 9O/KT3JjhQmhQf/lMAHpO/Ow2W8UrmO02+XWkkdIA5RxhLO+b0Xvy/Lbqnce1E/PaO09 zZqT81H5MRTogoaDi5e7ei9iSqvzf/9cjPIooU7PMO2P31OUr+ilXb35JFl3LzgNV3ol al/ueoKK4hchYH0Cj+j6JTxOWHOhOlnAp07kSzELHNWT7ebBbuGRpiMxjDxVWhWTOnRB RHcw== 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=biijCS7ICnuTYfXdVPN+Qkz55GFv6R0Undv6oY3D6tM=; b=TvM9/3y0+fzFPNKZyQwFysnxfw2MagK+/Cz6mWEs6IYbzvPLmxagLyHSXha10//4PP JZQWgJg7qjV+Yj198GoCjMk18JAI2GHhaArGCKzPi2gWoPA7BONDZyiUicABT0B+1NAm 5aOLJ6zYl2Z8ENbOv7OdOXVd0G1i0wePl1z6CZNzTKVDXqi2ujP1O7iggpGdPpiHb8tb uRJ36G90cNmcxOHN2hYy7oIiZPy8bXoPgRiKOD/RVzVpgWntTrSn+lNx8u0rskr1k+iu OoUpjHwWwJdEKyU879uef7E2OtIKxyEbGxT2uQHLjAlkgpzVGmj6ymLwv7/Aw+vPwnLb eVuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=afY+Dh0V; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a11-20020a056a000c8b00b004f7a02d2707si6027627pfv.349.2022.03.17.12.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 12:41:33 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=afY+Dh0V; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ABC2622F3C9; Thu, 17 Mar 2022 12:41:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234425AbiCQM7R (ORCPT + 99 others); Thu, 17 Mar 2022 08:59:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234291AbiCQMzu (ORCPT ); Thu, 17 Mar 2022 08:55:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E690F89CD4; Thu, 17 Mar 2022 05:54:01 -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 845536157E; Thu, 17 Mar 2022 12:54:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F616C340E9; Thu, 17 Mar 2022 12:54:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647521641; bh=UqwiPp2qBmb+7tKFdE0+ShqjTMU9taITEwrPGtd63H8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=afY+Dh0VsuyHlfu8zLpRaa6buSPry/Vcw2cOpRe/wlx24HicJOv7+L+JjjZz8k16C WQ3hYlrf21CCuCzdrRqPp8NGkTyOdr8E1BLfrFYRv2Od9dpil0aT25RoV8gLjhEc45 dRH9VULtzdxcFLKeAyo1aJBw2sNe+jgBvwpNRCFI= 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.16 05/28] xfrm: Fix xfrm migrate issues when address family changes Date: Thu, 17 Mar 2022 13:45:56 +0100 Message-Id: <20220317124526.925337900@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220317124526.768423926@linuxfoundation.org> References: <20220317124526.768423926@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=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 291236d7676f..f7bfa1916968 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -1578,9 +1578,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; @@ -1667,6 +1664,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