From: Yan Yan <evitayan@google.com>
To: steffen.klassert@secunet.com
Cc: herbert@gondor.apana.org.au, davem@davemloft.net,
netdev@vger.kernel.org, nharold@google.com,
benedictwong@google.com, maze@google.com, lorenzo@google.com,
Yan Yan <evitayan@google.com>
Subject: [PATCH v1 2/2] xfrm: Fix xfrm migrate issues when address family changes
Date: Wed, 22 Dec 2021 16:45:55 -0800 [thread overview]
Message-ID: <20211223004555.1284666-3-evitayan@google.com> (raw)
In-Reply-To: <20211223004555.1284666-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 | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 74d4283ed282..56a3530f1b67 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1503,7 +1503,7 @@ 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,
+static struct xfrm_state *xfrm_state_clone1(struct xfrm_state *orig,
struct xfrm_encap_tmpl *encap)
{
struct net *net = xs_net(orig);
@@ -1578,8 +1578,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;
@@ -1594,12 +1606,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,
@@ -1660,10 +1667,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.307.g9b7440fafd-goog
next prev parent reply other threads:[~2021-12-23 0:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-23 0:45 [PATCH v1 0/2] Fix issues in xfrm_migrate Yan Yan
2021-12-23 0:45 ` [PATCH v1 1/2] xfrm: Check if_id " Yan Yan
2021-12-25 18:30 ` kernel test robot
2021-12-23 0:45 ` Yan Yan [this message]
2021-12-26 2:18 ` [PATCH v1 2/2] xfrm: Fix xfrm migrate issues when address family changes kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2022-01-06 0:52 [PATCH v1 0/2] Fix issues in xfrm_migrate Yan Yan
2022-01-06 0:52 ` [PATCH v1 2/2] xfrm: Fix xfrm migrate issues when address family changes Yan Yan
2022-01-12 7:57 ` Steffen Klassert
2022-01-19 0:03 ` Yan Yan
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=20211223004555.1284666-3-evitayan@google.com \
--to=evitayan@google.com \
--cc=benedictwong@google.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=lorenzo@google.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=nharold@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).