netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Antonio Quartulli <antonio@openvpn.net>
Cc: netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
	ryazanov.s.a@gmail.com, edumazet@google.com, andrew@lunn.ch
Subject: Re: [PATCH net-next v6 12/25] ovpn: implement packet processing
Date: Wed, 4 Sep 2024 17:01:34 +0200	[thread overview]
Message-ID: <Zth2Trqbn73QDnLn@hog> (raw)
In-Reply-To: <ae23ac0f-2ff9-4396-9033-617dc60221eb@openvpn.net>

2024-09-04, 14:07:23 +0200, Antonio Quartulli wrote:
> Hi,
> 
> On 02/09/2024 16:42, Sabrina Dubroca wrote:
> > 2024-08-27, 14:07:52 +0200, Antonio Quartulli wrote:
> > > +/* this swap is not atomic, but there will be a very short time frame where the
> > 
> > Since we're under a mutex, I think we might get put to sleep for a
> > not-so-short time frame.
> > 
> > > + * old_secondary key won't be available. This should not be a big deal as most
> > 
> > I could be misreading the code, but isn't it old_primary that's
> > unavailable during the swap? rcu_replace_pointer overwrites
> > cs->primary, so before the final assign, both slots contain
> > old_secondary?
> 
> Right. The comment is not correct.
> 
> cs->secondary (old_secondary, that is the newest key) is what is probably
> being used by the other peer for sending traffic.

Right, thanks. I was getting confused about the key slots and which
key was the newest.

If the peer has already started sending with the newest key, no
problem. If we're swapping keys before our peer (or we're on a slow
network and the peer's packets get delayed), we'll still be receiving
packets encrypted with the old key.


> Therefore old_secondary is what is likely to be needed.
> 
> However, this is pure speculation and may not be accurate.

I can think of a few possibilities if this causes too many unwanted
drops:

 - use a linked list of keys, set the primary instead of swapping, and
   let delete remove the unused key(s) by ID instead of slot

 - decouple the TX and RX keys, which also means you don't really need
   to swap keys (swap for the TX key becomes "set primary", swap on RX
   can become a noop since you check both slots for the correct keyid)
   -- and here too delete becomes based on key ID

 - if cs->mutex becomes a spinlock, take it in the datapath when
   looking up keys. this will make sure we get a consistent view of
   the keys state.

 - come up with a scheme to let the datapath retry the key lookup if
   it didn't find the key it wanted (maybe something like a seqcount,
   or maybe taking the lock and retrying if the lookup failed)

I don't know if options 1 and 2 are possible based on how openvpn (the
protocol and the userspace application) models keys, but they seem a
bit "cleaner" on the datapath side (no locking, no retry). But they
require a different API.

Do you have the same problem in the current userspace implementation?


> The fact that we could sleep before having completed the swap sounds like
> something we want to avoid.
> Maybe I should convert this mutex to a spinlock. Its usage is fairly
> contained anyway.

I think it would make sense. It's only being held for very short
periods, just to set/swap a few pointers.


> FTR: this restructuring is the result of having tested encryption/decryption
> with pcrypt: sg, that is passed to the crypto code, was initially allocated
> on the stack, which was obviously not working for async crypto.
> The solution was to make it part of the skb CB area, so that it can be
> carried around until crypto is done.

I see. I thought this patch looked less familiar than the others :)

An alternative to using the CB is what IPsec does: allocate a chunk of
memory for all its temporary needs (crypto req, sg, iv, anything else
it needs during async crypto) and carve the pointers/small chunks out
of it. See esp_alloc_tmp in net/ipv4/esp4.c.  (I'm just mentioning
that for reference/curiosity, not asking that you change ovpn)


> This patch was basically re-written after realizing that the async crypto
> path was not working as expected, therefore sorry if there were some "kinda
> obvious" mistakes.

And I completely missed some of those issues in previous reviews.

> Thanks a lot for your review.

Cheers, and thanks for your patience.

-- 
Sabrina


  reply	other threads:[~2024-09-04 15:02 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27 12:07 [PATCH net-next v6 00/25] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 01/25] netlink: add NLA_POLICY_MAX_LEN macro Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 02/25] rtnetlink: don't crash on unregister if no dellink exists Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 03/25] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2024-09-05 14:38   ` Sabrina Dubroca
2024-09-06 12:26     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 04/25] ovpn: add basic netlink support Antonio Quartulli
2024-09-06 19:26   ` Simon Horman
2024-09-09  8:35     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 05/25] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 06/25] ovpn: implement interface creation/destruction via netlink Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 07/25] ovpn: keep carrier always on Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 08/25] ovpn: introduce the ovpn_peer object Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 09/25] ovpn: introduce the ovpn_socket object Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 10/25] ovpn: implement basic TX path (UDP) Antonio Quartulli
2024-08-30 17:02   ` Sabrina Dubroca
2024-09-02 12:03     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 11/25] ovpn: implement basic RX " Antonio Quartulli
2024-09-02 11:22   ` Sabrina Dubroca
2024-09-02 12:24     ` Antonio Quartulli
2024-09-06 19:18   ` Simon Horman
2024-09-09  8:37     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 12/25] ovpn: implement packet processing Antonio Quartulli
2024-09-02 14:42   ` Sabrina Dubroca
2024-09-04 12:07     ` Antonio Quartulli
2024-09-04 15:01       ` Sabrina Dubroca [this message]
2024-09-06 13:19         ` Antonio Quartulli
2024-09-10 13:04           ` Sabrina Dubroca
2024-09-11 12:52             ` Antonio Quartulli
2024-09-11 13:30               ` Sabrina Dubroca
2024-09-12  8:33                 ` Antonio Quartulli
2024-09-22 19:51                   ` Sergey Ryazanov
2024-09-23 12:48                     ` Antonio Quartulli
2024-09-06 19:29   ` Simon Horman
2024-09-09  8:38     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 13/25] ovpn: store tunnel and transport statistics Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 14/25] ovpn: implement TCP transport Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 15/25] ovpn: implement multi-peer support Antonio Quartulli
2024-09-03 14:40   ` Sabrina Dubroca
2024-09-04 10:10     ` Sabrina Dubroca
2024-09-06 13:26       ` Antonio Quartulli
2024-09-05  8:02     ` Antonio Quartulli
2024-09-05 10:47       ` Sabrina Dubroca
2024-09-09  9:12         ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 16/25] ovpn: implement peer lookup logic Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 17/25] ovpn: implement keepalive mechanism Antonio Quartulli
2024-09-03 15:17   ` Sabrina Dubroca
2024-09-09  9:17     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 18/25] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 19/25] ovpn: add support for peer floating Antonio Quartulli
2024-09-05  9:55   ` Sabrina Dubroca
2024-09-09  8:52     ` Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 20/25] ovpn: implement peer add/dump/delete via netlink Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 21/25] ovpn: implement key add/del/swap " Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 22/25] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 23/25] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 24/25] ovpn: add basic ethtool support Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 25/25] testing/selftest: add test tool and scripts for ovpn module Antonio Quartulli

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=Zth2Trqbn73QDnLn@hog \
    --to=sd@queasysnail.net \
    --cc=andrew@lunn.ch \
    --cc=antonio@openvpn.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.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).