netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: <avivh@mellanox.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Boris Pismenny <borisp@mellanox.com>,
	Yossi Kuperman <yossiku@mellanox.com>,
	"Yevgeny Kliteynik" <kliteyn@mellanox.com>,
	<netdev@vger.kernel.org>
Subject: Re: [PATCH net-next 2/3] xfrm: Fix offload dev state addition to occur after insertion
Date: Wed, 25 Oct 2017 09:22:14 +0200	[thread overview]
Message-ID: <20171025072214.GP3323@secunet.com> (raw)
In-Reply-To: <1508857831-55824-2-git-send-email-avivh@mellanox.com>

On Tue, Oct 24, 2017 at 06:10:30PM +0300, avivh@mellanox.com wrote:
> From: Aviv Heller <avivh@mellanox.com>
> 
> Adding the state to the offload device prior to replay init in
> xfrm_state_construct() will result in NULL dereference if a matching
> ESP packet is received in between.
> 
> Adding it after insertion also has the benefit of the driver not having
> to check whether a state with the same match criteria already exists,
> but forces us to use an atomic type for the offload_handle, to make
> certain a stack-read/driver-write race won't result in reading corrupt
> data.

No, this will add multiple atomic operations to the packet path,
even in the non offloaded case.

I think the problem is that we set XFRM_STATE_VALID to early.
This was not a problem before we had offloading because
it was not possible to lookup this state before we inserted
it into the SADB. Now that the driver holds a subset of states
too, we need to make sure the state is fully initialized
before we mark it as valid.

The patch below should do it, in combination with your patch 1/3.

Could you please test this?

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index b997f13..96eb263 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -587,10 +587,6 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 	if (attrs[XFRMA_OUTPUT_MARK])
 		x->props.output_mark = nla_get_u32(attrs[XFRMA_OUTPUT_MARK]);
 
-	err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]);
-	if (err)
-		goto error;
-
 	if (attrs[XFRMA_SEC_CTX]) {
 		err = security_xfrm_state_alloc(x,
 						nla_data(attrs[XFRMA_SEC_CTX]));
@@ -620,6 +616,10 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 	/* override default values from above */
 	xfrm_update_ae_params(x, attrs, 0);
 
+	err = __xfrm_init_state(x, false, attrs[XFRMA_OFFLOAD_DEV]);
+	if (err)
+		goto error;
+
 	return x;
 
 error:

  reply	other threads:[~2017-10-25  7:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-24 15:10 [PATCH net-next 1/3] xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0) avivh
2017-10-24 15:10 ` [PATCH net-next 2/3] xfrm: Fix offload dev state addition to occur after insertion avivh
2017-10-25  7:22   ` Steffen Klassert [this message]
2017-10-25 13:09     ` Aviv Heller
2017-10-26  6:16       ` Steffen Klassert
2017-10-26 14:55         ` Aviv Heller
     [not found]         ` <mail.59f1f759.3bc0.5118b0751bd8f084@storage.wm.amazon.com>
2017-10-26 15:47           ` Aviv Heller
2017-10-26  0:27   ` kbuild test robot
2017-10-24 15:10 ` [PATCH net-next 3/3] xfrm: Remove redundant state assignment in xfrm_input() avivh

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=20171025072214.GP3323@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=avivh@mellanox.com \
    --cc=borisp@mellanox.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=kliteyn@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=yossiku@mellanox.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).