From: Yan Yan <evitayan@google.com>
To: Steffen Klassert <steffen.klassert@secunet.com>
Cc: netdev@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
lorenzo@google.com, maze@google.com, nharold@googlel.com,
benedictwong@googlel.com, Yan Yan <evitayan@google.com>
Subject: [PATCH v1 2/2] xfrm: Fix xfrm migrate issues when address family changes
Date: Wed, 5 Jan 2022 16:52:51 -0800 [thread overview]
Message-ID: <20220106005251.2833941-3-evitayan@google.com> (raw)
In-Reply-To: <20220106005251.2833941-1-evitayan@google.com>
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 <evitayan@google.com>
---
net/xfrm/xfrm_state.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index f52767685b13..cac212039bf9 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1504,8 +1504,8 @@ static inline int clone_security(struct xfrm_state *x, struct xfrm_sec_ctx *secu
return 0;
}
-static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
- struct xfrm_encap_tmpl *encap)
+static struct xfrm_state *xfrm_state_clone1(struct xfrm_state *orig,
+ struct xfrm_encap_tmpl *encap)
{
struct net *net = xs_net(orig);
struct xfrm_state *x = xfrm_state_alloc(net);
@@ -1579,8 +1579,20 @@ 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;
+ return x;
+
+ error:
+ xfrm_state_put(x);
+out:
+ return NULL;
+}
+
+static int xfrm_state_clone2(struct xfrm_state *orig, struct xfrm_state *x)
+{
+ int err = xfrm_init_state(x);
+
+ if (err < 0)
+ return err;
x->props.flags = orig->props.flags;
x->props.extra_flags = orig->props.extra_flags;
@@ -1595,12 +1607,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
x->replay = orig->replay;
x->preplay = orig->preplay;
- return x;
-
- error:
- xfrm_state_put(x);
-out:
- return NULL;
+ return 0;
}
struct xfrm_state *xfrm_migrate_state_find(struct xfrm_migrate *m, struct net *net,
@@ -1661,10 +1668,14 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
{
struct xfrm_state *xc;
- xc = xfrm_state_clone(x, encap);
+ xc = xfrm_state_clone1(x, encap);
if (!xc)
return NULL;
+ xc->props.family = m->new_family;
+ if (xfrm_state_clone2(x, 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.448.ga2b2bfdf31-goog
next prev parent reply other threads:[~2022-01-06 0:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 0:52 [PATCH v1 0/2] Fix issues in xfrm_migrate Yan Yan
2022-01-06 0:52 ` [PATCH v1 1/2] xfrm: Check if_id " Yan Yan
2022-01-06 12:22 ` kernel test robot
2022-01-06 15:55 ` kernel test robot
2022-01-06 15:55 ` kernel test robot
2022-01-06 0:52 ` Yan Yan [this message]
2022-01-12 7:57 ` [PATCH v1 2/2] xfrm: Fix xfrm migrate issues when address family changes Steffen Klassert
2022-01-19 0:03 ` Yan Yan
-- strict thread matches above, loose matches on Subject: below --
2021-12-23 0:45 [PATCH v1 0/2] Fix issues in xfrm_migrate Yan Yan
2021-12-23 0:45 ` [PATCH v1 2/2] xfrm: Fix xfrm migrate issues when address family changes Yan Yan
2021-12-26 2:18 ` kernel test robot
2021-12-26 2:18 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220106005251.2833941-3-evitayan@google.com \
--to=evitayan@google.com \
--cc=benedictwong@googlel.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=lorenzo@google.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=nharold@googlel.com \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.