All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Antonio Quartulli <antonio@openvpn.net>
Cc: netdev@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Donald Hunter <donald.hunter@gmail.com>,
	Shuah Khan <shuah@kernel.org>,
	ryazanov.s.a@gmail.com, Andrew Lunn <andrew+netdev@lunn.ch>,
	Simon Horman <horms@kernel.org>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Xiao Liang <shaw.leon@gmail.com>
Subject: Re: [PATCH net-next v15 09/22] ovpn: implement packet processing
Date: Mon, 16 Dec 2024 15:58:32 +0100	[thread overview]
Message-ID: <Z2BAGHX2Dd8Gjagz@hog> (raw)
In-Reply-To: <20241211-b4-ovpn-v15-9-314e2cad0618@openvpn.net>

(just a few nits here)

2024-12-11, 22:15:13 +0100, Antonio Quartulli wrote:
> +static inline struct ovpn_crypto_key_slot *
> +ovpn_crypto_key_id_to_slot(const struct ovpn_crypto_state *cs, u8 key_id)
> +{
> +	struct ovpn_crypto_key_slot *ks;
> +	u8 idx;
> +
> +	if (unlikely(!cs))
> +		return NULL;
> +
> +	rcu_read_lock();
> +	idx = cs->primary_idx;
> +	ks = rcu_dereference(cs->slots[idx]);
> +	if (ks && ks->key_id == key_id) {
> +		if (unlikely(!ovpn_crypto_key_slot_hold(ks)))
> +			ks = NULL;
> +		goto out;
> +	}
> +
> +	ks = rcu_dereference(cs->slots[idx ^ 1]);

nit: for consistency with the other uses of the secondary slot, I'd
switch that to cs->slots[!idx]

[...]
> +int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,
> +		      struct sk_buff *skb)
> +{
[...]
> +	/* add packet op as head of additional data */
> +	op = ovpn_opcode_compose(OVPN_DATA_V2, ks->key_id, peer->id);
> +	__skb_push(skb, OVPN_OPCODE_SIZE);
> +	BUILD_BUG_ON(sizeof(op) != OVPN_OPCODE_SIZE);
> +	*((__force __be32 *)skb->data) = htonl(op);
> +
> +	/* AEAD Additional data */
> +	sg_set_buf(sg, skb->data, OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE);

You could add

#define OVPN_AAD_SIZE (OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE)

and then use it in a few places in ovpn_aead_encrypt and
ovpn_aead_decrypt.


[...]
> +int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,
> +		      struct sk_buff *skb)
> +{
> +	const unsigned int tag_size = crypto_aead_authsize(ks->decrypt);
> +	int ret, payload_len, nfrags;
> +	unsigned int payload_offset;
> +	struct aead_request *req;
> +	struct sk_buff *trailer;
> +	struct scatterlist *sg;
> +	u8 iv[OVPN_NONCE_SIZE];
> +	unsigned int sg_len;
> +
> +	payload_offset = OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE + tag_size;

OVPN_AAD_SIZE + tag_size


[...]
> +	sg_init_table(sg, nfrags + 2);
> +
> +	/* packet op is head of additional data */
> +	sg_len = OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE;

This variable can probably be dropped if you add OVPN_AAD_SIZE.

[...]
> +	/* setup async crypto operation */
> +	aead_request_set_tfm(req, ks->decrypt);
> +	aead_request_set_callback(req, 0, ovpn_decrypt_post, skb);
> +	aead_request_set_crypt(req, sg, sg, payload_len + tag_size, iv);
> +
> +	aead_request_set_ad(req, OVPN_NONCE_WIRE_SIZE + OVPN_OPCODE_SIZE);

and this op is flipped but it's still OVPN_AAD_SIZE.

> +
> +	/* decrypt it */
> +	return crypto_aead_decrypt(req);
> +free_sg:
> +	kfree(ovpn_skb_cb(skb)->sg);
> +	ovpn_skb_cb(skb)->sg = NULL;
> +	return ret;
> +}
> +

[...]
> @@ -80,7 +83,10 @@ static void ovpn_peer_release_rcu(struct rcu_head *head)
>   */
>  static void ovpn_peer_release(struct ovpn_peer *peer)
>  {
> +	ovpn_crypto_state_release(&peer->crypto);
> +	spin_lock_bh(&peer->lock);
>  	ovpn_bind_reset(peer, NULL);

At this point in the series, ovpn_bind_reset also tries to take
peer->lock (gets fixed in the "peer floating" patch).

(but if you're tired of moving chunks around, I can live with it)

> +	spin_unlock_bh(&peer->lock);
>  	netdev_put(peer->ovpn->dev, &peer->ovpn->dev_tracker);
>  	call_rcu(&peer->rcu, ovpn_peer_release_rcu);
>  }

-- 
Sabrina

  reply	other threads:[~2024-12-16 14:58 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11 21:15 [PATCH net-next v15 00/22] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 01/22] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 02/22] ovpn: add basic netlink support Antonio Quartulli
2024-12-13 16:45   ` Donald Hunter
2024-12-13 17:00     ` Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 03/22] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2024-12-13 12:32   ` Donald Hunter
2024-12-13 12:37     ` Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 04/22] ovpn: keep carrier always on for MP interfaces Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 05/22] ovpn: introduce the ovpn_peer object Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 06/22] ovpn: introduce the ovpn_socket object Antonio Quartulli
2024-12-12 16:19   ` Sabrina Dubroca
2024-12-12 22:46     ` Antonio Quartulli
2024-12-16 11:09       ` Sabrina Dubroca
2024-12-16 11:50         ` Antonio Quartulli
2024-12-17  0:40           ` Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 07/22] ovpn: implement basic TX path (UDP) Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 08/22] ovpn: implement basic RX " Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 09/22] ovpn: implement packet processing Antonio Quartulli
2024-12-16 14:58   ` Sabrina Dubroca [this message]
2024-12-11 21:15 ` [PATCH net-next v15 10/22] ovpn: store tunnel and transport statistics Antonio Quartulli
2024-12-16 14:20   ` Sabrina Dubroca
2024-12-11 21:15 ` [PATCH net-next v15 11/22] ovpn: implement TCP transport Antonio Quartulli
2024-12-16 13:59   ` Sabrina Dubroca
2024-12-16 14:09     ` Antonio Quartulli
2024-12-16 14:19       ` Sabrina Dubroca
2024-12-11 21:15 ` [PATCH net-next v15 12/22] ovpn: implement multi-peer support Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 13/22] ovpn: implement peer lookup logic Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 14/22] ovpn: implement keepalive mechanism Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 15/22] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 16/22] ovpn: add support for peer floating Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 17/22] ovpn: implement peer add/get/dump/delete via netlink Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 18/22] ovpn: implement key add/get/del/swap " Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 19/22] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 20/22] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 21/22] ovpn: add basic ethtool support Antonio Quartulli
2024-12-11 21:15 ` [PATCH net-next v15 22/22] testing/selftests: 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=Z2BAGHX2Dd8Gjagz@hog \
    --to=sd@queasysnail.net \
    --cc=andrew+netdev@lunn.ch \
    --cc=antonio@openvpn.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=shaw.leon@gmail.com \
    --cc=shuah@kernel.org \
    /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.