linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qingfang Deng <dqfext@gmail.com>
To: Antonio Quartulli <antonio@openvpn.net>
Cc: Simon Horman <horms@kernel.org>,
	linux-kernel@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	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>,
	sd@queasysnail.net,  ryazanov.s.a@gmail.com,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	 Xiao Liang <shaw.leon@gmail.com>
Subject: Re: [PATCH net-next v24 09/23] ovpn: implement packet processing
Date: Wed, 26 Mar 2025 18:03:18 +0800	[thread overview]
Message-ID: <CALW65jZ=Jngf0THLTuWHuhpQb0NDM=4x4HN_Xj922nmq71EMUQ@mail.gmail.com> (raw)
In-Reply-To: <58712444-1de7-4076-b850-4c6035792931@openvpn.net>

Hi Antonio,

On Wed, Mar 26, 2025 at 5:41 PM Antonio Quartulli <antonio@openvpn.net> wrote:
> >> +/* Get the next packet ID for xmit */
> >> +static inline int ovpn_pktid_xmit_next(struct ovpn_pktid_xmit *pid, u32 *pktid)
> >> +{
> >> +    const s64 seq_num = atomic64_fetch_add_unless(&pid->seq_num, 1,
> >> +                                                  0x100000000LL);
> >> +    /* when the 32bit space is over, we return an error because the packet
> >> +     * ID is used to create the cipher IV and we do not want to reuse the
> >> +     * same value more than once
> >> +     */
> >> +    if (unlikely(seq_num == 0x100000000LL))
> >> +            return -ERANGE;
> >
> > You may use a 32-bit atomic_t, instead of checking if it equals
> > 0x1_00000000, check if it wraparounds to zero.
> > Additionally, you don't need full memory ordering as you just want an
> > incrementing value:
> >
> > int seq_num = atomic_fetch_inc_relaxed(&pid->seq_num);
> >
> > if (unlikely(!seq_num))
> >       ...
>
> But then if we have concurrent invocations of ovpn_pktid_xmit_next()
> only the first one will error out on wrap-around, while the others will
> return no error (seq_num becomes > 0) and will allow the packets to go
> through.
>
> This is not what we want.

Got it. You could replace it with
atomic_fetch_add_unless(&pid->seq_num, 1, 0) and check if it wraps
around to zero.

However, what about the opposite scenario? If multiple threads
concurrently invoke ovpn_pktid_xmit_next() and all detect the
wraparound condition, could this lead to simultaneous calls to
ovpn_crypto_kill_key() and ovpn_nl_key_swap_notify()?

>
> >
> >> +
> >> +    *pktid = (u32)seq_num;
> >> +
> >> +    return 0;
> >> +}
> >> +
> >> +/* Write 12-byte AEAD IV to dest */
> >> +static inline void ovpn_pktid_aead_write(const u32 pktid,
> >> +                                     const u8 nt[],
> >> +                                     unsigned char *dest)
> >> +{
> >> +    *(__force __be32 *)(dest) = htonl(pktid);
> >> +    BUILD_BUG_ON(4 + OVPN_NONCE_TAIL_SIZE != OVPN_NONCE_SIZE);
> >> +    memcpy(dest + 4, nt, OVPN_NONCE_TAIL_SIZE);
> >> +}
> >> +
>
> Qingfang, may I ask you to remove from your reply non-relevant code
> (like I did above), especially in such long patches, as it becomes a bit
> tedious to spot your comments and I may miss something.

Noted.

>
> Thanks a lot!
>
> Regards,
>
> --
> Antonio Quartulli
> OpenVPN Inc.
>

  reply	other threads:[~2025-03-26 10:03 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-18  1:40 [PATCH net-next v24 00/23] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 01/23] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 02/23] ovpn: add basic netlink support Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 03/23] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 04/23] ovpn: keep carrier always on for MP interfaces Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 05/23] ovpn: introduce the ovpn_peer object Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 06/23] ovpn: introduce the ovpn_socket object Antonio Quartulli
2025-04-01 13:05   ` Sabrina Dubroca
2025-04-02 23:37     ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 07/23] ovpn: implement basic TX path (UDP) Antonio Quartulli
2025-04-01 13:49   ` Sabrina Dubroca
2025-04-02 12:01     ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 08/23] ovpn: implement basic RX " Antonio Quartulli
2025-04-01  9:47   ` Sabrina Dubroca
2025-04-02 12:04     ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 09/23] ovpn: implement packet processing Antonio Quartulli
2025-03-24 11:02   ` Sabrina Dubroca
2025-03-24 20:53     ` Antonio Quartulli
2025-03-25  9:40       ` Sabrina Dubroca
2025-03-25  2:07   ` Qingfang Deng
2025-03-26  9:41     ` Antonio Quartulli
2025-03-26 10:03       ` Qingfang Deng [this message]
2025-03-26 10:22         ` Antonio Quartulli
2025-03-26 12:43           ` Qingfang Deng
2025-03-26 13:54             ` Antonio Quartulli
2025-04-01  9:59   ` Sabrina Dubroca
2025-04-02 12:08     ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 10/23] ovpn: store tunnel and transport statistics Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 11/23] ovpn: implement TCP transport Antonio Quartulli
2025-04-01 10:02   ` Sabrina Dubroca
2025-04-02 12:09     ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 12/23] skb: implement skb_send_sock_locked_with_flags() Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 13/23] ovpn: add support for MSG_NOSIGNAL in tcp_sendmsg Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 14/23] ovpn: implement multi-peer support Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 15/23] ovpn: implement peer lookup logic Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 16/23] ovpn: implement keepalive mechanism Antonio Quartulli
2025-04-01 12:51   ` Sabrina Dubroca
2025-04-02 12:11     ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 17/23] ovpn: add support for updating local or remote UDP endpoint Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 18/23] ovpn: implement peer add/get/dump/delete via netlink Antonio Quartulli
2025-03-24 10:48   ` Sabrina Dubroca
2025-03-24 23:15     ` Antonio Quartulli
2025-03-25 10:56       ` Sabrina Dubroca
2025-03-26  0:41         ` Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 19/23] ovpn: implement key add/get/del/swap " Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 20/23] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 21/23] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 22/23] ovpn: add basic ethtool support Antonio Quartulli
2025-03-18  1:40 ` [PATCH net-next v24 23/23] testing/selftests: add test tool and scripts for ovpn module Antonio Quartulli
2025-03-28  9:14 ` [PATCH net-next v24 00/23] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2025-03-31 14:47   ` Sabrina Dubroca

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='CALW65jZ=Jngf0THLTuWHuhpQb0NDM=4x4HN_Xj922nmq71EMUQ@mail.gmail.com' \
    --to=dqfext@gmail.com \
    --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=sd@queasysnail.net \
    --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 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).