From: "Jérémy Jean" <jeremy.jean@oss.cyber.gouv.fr>
To: Tung Quang Nguyen <tung.quang.nguyen@est.tech>
Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Jon Maloy <jmaloy@redhat.com>
Subject: Re: [PATCH net v2] tipc: protect received keys from concurrent flush
Date: Mon, 05 Oct 2026 21:01:49 +0200 [thread overview]
Message-ID: <2ac35bd0a3d8c774d0ee2bc977a45cf0@oss.cyber.gouv.fr> (raw)
In-Reply-To: <DU4P189MB37501CA7DBF5D6C3C8752349C6962@DU4P189MB3750.EURP189.PROD.OUTLOOK.COM>
Hello,
On 2026-10-05 04:14, Tung Quang Nguyen wrote:
>> /* Attach it to the crypto */
>> if (likely(!rc)) {
>> - rc = tipc_crypto_key_attach(c, aead, 0, master_key);
>> + spin_lock_bh(&c->lock);
>> + if (ukey == c->skey_in_use && c->skey != ukey)
>> + rc = -ECANCELED;
>
> This check should be done earlier, before calling tipc_ahead_init() ?
Would moving the check before tipc_aead_init() be enough, given that a
flush can still happen while AEAD setup is running and before the key
is attached?
Indeed, the race goes something like:
1. Worker starts tipc_aead_init()
2. Flush clears rx->skey
3. Worker finishes AEAD setup
AFAIU, we still need the check under c->lock, immediately before
tipc_crypto_key_attach(), so that a revoked key cannot be published
after flush.
>
>> + else
>> + rc = tipc_crypto_key_attach(c, aead, 0, master_key);
>> + spin_unlock_bh(&c->lock);
>> if (rc < 0)
>> tipc_aead_free(&aead->rcu);
>> }
>> @@ -1151,6 +1158,8 @@ int tipc_crypto_key_init(struct tipc_crypto *c,
>> struct
>> tipc_aead_key *ukey,
>> * @pos: desired slot in the crypto key array, = 0 if any!
>> * @master_key: specify this is a cluster master key
>> *
>> + * The caller must hold c->lock.
>> + *
>> * Return: new key id in case of success, otherwise: -EBUSY
>> */
>> static int tipc_crypto_key_attach(struct tipc_crypto *c, @@ -1158,20
>> +1167,19
>> @@ static int tipc_crypto_key_attach(struct tipc_crypto *c,
>> bool master_key)
>> {
>> struct tipc_key key;
>> - int rc = -EBUSY;
>> u8 new_key;
>>
>> - spin_lock_bh(&c->lock);
>> + lockdep_assert_held(&c->lock);
>> key = c->key;
>> if (master_key) {
>> new_key = KEY_MASTER;
>> goto attach;
>> }
>> if (key.active && key.passive)
>> - goto exit;
>> + return -EBUSY;
>> if (key.pending) {
>> if (tipc_aead_users(c->aead[key.pending]) > 0)
>> - goto exit;
>> + return -EBUSY;
>> /* if (pos): ok with replacing, will be aligned when needed */
>> /* Replace it */
>> new_key = key.pending;
>> @@ -1201,11 +1209,7 @@ attach:
>> c->working = 1;
>> c->nokey = 0;
>> c->key_master |= master_key;
>> - rc = new_key;
>> -
>> -exit:
>> - spin_unlock_bh(&c->lock);
>> - return rc;
>> + return new_key;
>
> Remove lock from tipc_crypto_key_attach() is enough. Why adding many
> irrelevant changes that do not seem necessary ?
Those extra changes in tipc_crypto_key_attach() are more cleanup than
anything else; I preferred the direct returns since the function no
longer owns the lock, but I can reduce the patch and keep the exit
label.
Thanks,
Jérémy
prev parent reply other threads:[~2026-10-05 19:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 20:59 [PATCH net v2] tipc: protect received keys from concurrent flush Jérémy Jean
2026-10-02 21:04 ` netdev-bot+sinfo
2026-10-05 2:14 ` Tung Quang Nguyen
2026-10-05 19:01 ` Jérémy Jean [this message]
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=2ac35bd0a3d8c774d0ee2bc977a45cf0@oss.cyber.gouv.fr \
--to=jeremy.jean@oss.cyber.gouv.fr \
--cc=jmaloy@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=tung.quang.nguyen@est.tech \
/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