Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net] sctp: move the active_key update after sh_keys is added
@ 2021-08-01  6:25 Xin Long
  2021-08-03 10:50 ` patchwork-bot+netdevbpf
  2021-08-03 13:59 ` Marcelo Ricardo Leitner
  0 siblings, 2 replies; 3+ messages in thread
From: Xin Long @ 2021-08-01  6:25 UTC (permalink / raw)
  To: network dev, davem, kuba, linux-sctp; +Cc: Marcelo Ricardo Leitner

In commit 58acd1009226 ("sctp: update active_key for asoc when old key is
being replaced"), sctp_auth_asoc_init_active_key() is called to update
the active_key right after the old key is deleted and before the new key
is added, and it caused that the active_key could be found with the key_id.

In Ying Xu's testing, the BUG_ON in sctp_auth_asoc_init_active_key() was
triggered:

  [ ] kernel BUG at net/sctp/auth.c:416!
  [ ] RIP: 0010:sctp_auth_asoc_init_active_key.part.8+0xe7/0xf0 [sctp]
  [ ] Call Trace:
  [ ]  sctp_auth_set_key+0x16d/0x1b0 [sctp]
  [ ]  sctp_setsockopt.part.33+0x1ba9/0x2bd0 [sctp]
  [ ]  __sys_setsockopt+0xd6/0x1d0
  [ ]  __x64_sys_setsockopt+0x20/0x30
  [ ]  do_syscall_64+0x5b/0x1a0

So fix it by moving the active_key update after sh_keys is added.

Fixes: 58acd1009226 ("sctp: update active_key for asoc when old key is being replaced")
Reported-by: Ying Xu <yinxu@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/auth.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index fe74c5f95630..db6b7373d16c 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -857,14 +857,18 @@ int sctp_auth_set_key(struct sctp_endpoint *ep,
 	memcpy(key->data, &auth_key->sca_key[0], auth_key->sca_keylength);
 	cur_key->key = key;
 
-	if (replace) {
-		list_del_init(&shkey->key_list);
-		sctp_auth_shkey_release(shkey);
-		if (asoc && asoc->active_key_id == auth_key->sca_keynumber)
-			sctp_auth_asoc_init_active_key(asoc, GFP_KERNEL);
+	if (!replace) {
+		list_add(&cur_key->key_list, sh_keys);
+		return 0;
 	}
+
+	list_del_init(&shkey->key_list);
+	sctp_auth_shkey_release(shkey);
 	list_add(&cur_key->key_list, sh_keys);
 
+	if (asoc && asoc->active_key_id == auth_key->sca_keynumber)
+		sctp_auth_asoc_init_active_key(asoc, GFP_KERNEL);
+
 	return 0;
 }
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] sctp: move the active_key update after sh_keys is added
  2021-08-01  6:25 [PATCH net] sctp: move the active_key update after sh_keys is added Xin Long
@ 2021-08-03 10:50 ` patchwork-bot+netdevbpf
  2021-08-03 13:59 ` Marcelo Ricardo Leitner
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-08-03 10:50 UTC (permalink / raw)
  To: Xin Long; +Cc: netdev, davem, kuba, linux-sctp, marcelo.leitner

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Sun,  1 Aug 2021 02:25:31 -0400 you wrote:
> In commit 58acd1009226 ("sctp: update active_key for asoc when old key is
> being replaced"), sctp_auth_asoc_init_active_key() is called to update
> the active_key right after the old key is deleted and before the new key
> is added, and it caused that the active_key could be found with the key_id.
> 
> In Ying Xu's testing, the BUG_ON in sctp_auth_asoc_init_active_key() was
> triggered:
> 
> [...]

Here is the summary with links:
  - [net] sctp: move the active_key update after sh_keys is added
    https://git.kernel.org/netdev/net/c/ae954bbc451d

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] sctp: move the active_key update after sh_keys is added
  2021-08-01  6:25 [PATCH net] sctp: move the active_key update after sh_keys is added Xin Long
  2021-08-03 10:50 ` patchwork-bot+netdevbpf
@ 2021-08-03 13:59 ` Marcelo Ricardo Leitner
  1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Ricardo Leitner @ 2021-08-03 13:59 UTC (permalink / raw)
  To: Xin Long; +Cc: network dev, davem, kuba, linux-sctp

On Sun, Aug 01, 2021 at 02:25:31AM -0400, Xin Long wrote:
> In commit 58acd1009226 ("sctp: update active_key for asoc when old key is
> being replaced"), sctp_auth_asoc_init_active_key() is called to update
> the active_key right after the old key is deleted and before the new key
> is added, and it caused that the active_key could be found with the key_id.

I know it's late, but anyway:
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-03 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-01  6:25 [PATCH net] sctp: move the active_key update after sh_keys is added Xin Long
2021-08-03 10:50 ` patchwork-bot+netdevbpf
2021-08-03 13:59 ` Marcelo Ricardo Leitner

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).