From: luoqing <l1138897701@163.com>
To: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next] sctp: auth: propagate HMAC calculation errors to callers
Date: Thu, 30 Jul 2026 14:42:02 +0800 [thread overview]
Message-ID: <20260730064202.792809-1-l1138897701@163.com> (raw)
From: Qing Luo <luoqing@kylinos.cn>
sctp_auth_calculate_hmac() silently returns when
sctp_auth_asoc_create_secret() fails under memory pressure,
leaving the digest zeroed. Callers then compare the zeroed
digest against the saved one, getting SCTP_IERROR_BAD_SIG
instead of the correct SCTP_IERROR_NOMEM.
Change sctp_auth_calculate_hmac() to return int so callers
can distinguish allocation failures from bad signatures:
- sctp_sf_authenticate() frees save_digest and returns
SCTP_IERROR_NOMEM on failure.
- sctp_packet_pack() frees the auth chunk and returns 0
(drop the packet). In the non-GSO path nskb equals head,
so only free nskb in the GSO path to avoid a double-free;
the caller handles head cleanup when pkt_count is 0.
Also update the declaration in auth.h to match.
Assisted-by: LLM # review
Signed-off-by: Qing Luo <luoqing@kylinos.cn>
---
include/net/sctp/auth.h | 6 +++---
net/sctp/auth.c | 6 ++++--
net/sctp/output.c | 10 ++++++++--
net/sctp/sm_statefuns.c | 9 ++++++---
4 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/include/net/sctp/auth.h b/include/net/sctp/auth.h
index 6f2cd562b1de..eeb3297fe97d 100644
--- a/include/net/sctp/auth.h
+++ b/include/net/sctp/auth.h
@@ -83,9 +83,9 @@ int sctp_auth_send_cid(enum sctp_cid chunk,
const struct sctp_association *asoc);
int sctp_auth_recv_cid(enum sctp_cid chunk,
const struct sctp_association *asoc);
-void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
- struct sk_buff *skb, struct sctp_auth_chunk *auth,
- struct sctp_shared_key *ep_key, gfp_t gfp);
+int sctp_auth_calculate_hmac(const struct sctp_association *asoc,
+ struct sk_buff *skb, struct sctp_auth_chunk *auth,
+ struct sctp_shared_key *ep_key, gfp_t gfp);
void sctp_auth_shkey_release(struct sctp_shared_key *sh_key);
void sctp_auth_shkey_hold(struct sctp_shared_key *sh_key);
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index c901d373af80..4db3a3a4a457 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -613,7 +613,7 @@ int sctp_auth_recv_cid(enum sctp_cid chunk, const struct sctp_association *asoc)
* zero (as shown in Figure 6) followed by all chunks that are placed
* after the AUTH chunk in the SCTP packet.
*/
-void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
+int sctp_auth_calculate_hmac(const struct sctp_association *asoc,
struct sk_buff *skb, struct sctp_auth_chunk *auth,
struct sctp_shared_key *ep_key, gfp_t gfp)
{
@@ -636,7 +636,7 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
/* ep_key can't be NULL here */
asoc_key = sctp_auth_asoc_create_secret(asoc, ep_key, gfp);
if (!asoc_key)
- return;
+ return -ENOMEM;
free_key = 1;
}
@@ -654,6 +654,8 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
if (free_key)
sctp_auth_key_put(asoc_key);
+
+ return 0;
}
/* API Helpers */
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 23e96305cad7..a7930cd9400e 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -517,8 +517,14 @@ static int sctp_packet_pack(struct sctp_packet *packet,
}
if (auth) {
- sctp_auth_calculate_hmac(tp->asoc, nskb, auth,
- packet->auth->shkey, gfp);
+ if (sctp_auth_calculate_hmac(tp->asoc, nskb, auth,
+ packet->auth->shkey, gfp)) {
+ sctp_chunk_free(packet->auth);
+ packet->auth = NULL;
+ if (gso)
+ kfree_skb(nskb);
+ return 0;
+ }
/* free auth if no more chunks, or add it back */
if (list_empty(&packet->chunk_list))
sctp_chunk_free(packet->auth);
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index b01db33bbc36..b68de2c4dc26 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -4455,9 +4455,12 @@ static enum sctp_ierror sctp_sf_authenticate(
memset(digest, 0, sig_len);
- sctp_auth_calculate_hmac(asoc, chunk->skb,
- (struct sctp_auth_chunk *)chunk->chunk_hdr,
- sh_key, GFP_ATOMIC);
+ if (sctp_auth_calculate_hmac(asoc, chunk->skb,
+ (struct sctp_auth_chunk *)chunk->chunk_hdr,
+ sh_key, GFP_ATOMIC)) {
+ kfree(save_digest);
+ return SCTP_IERROR_NOMEM;
+ }
/* Discard the packet if the digests do not match */
if (crypto_memneq(save_digest, digest, sig_len)) {
--
2.25.1
next reply other threads:[~2026-07-30 6:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 6:42 luoqing [this message]
2026-08-04 1:50 ` [PATCH net-next] sctp: auth: propagate HMAC calculation errors to callers Jakub Kicinski
2026-08-04 6:50 ` [PATCH net v2] " luoqing
2026-08-04 8:58 ` [PATCH net v3] " luoqing
2026-08-05 18:06 ` Xin Long
2026-08-07 6:43 ` [PATCH net-next v4] " luoqing
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=20260730064202.792809-1-l1138897701@163.com \
--to=l1138897701@163.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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