From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DC583E317B for ; Fri, 31 Jul 2026 12:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785499562; cv=none; b=XfAlY3Lf8Rvq2+htqC4FhIOPtLafqsMvemIWKUavh4+Q7wuz42ONDAnfthI9mPbSRVCXRgPqX6DEVgwNO1RXxU+SBbFg6Ch5P9IOqpSRNzblcZuqUMoi0zjtePLLihsKZDV61wSjrh4dwIXmYyeRLbgIPKUzZRW0OdRLJgVCVQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785499562; c=relaxed/simple; bh=7Nv247yt1+fKJsVSZ0a7lvl522Kt3IM0DYz6/l5ynCo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GNkgCdrYRw8YUyEauN3J8d9OUrBCx1soPeuFtNjEIWmkgCy6Q5U8eThnLuDl49aPBG1Y8BQMwUlBUA8g40CvFfvB7KtoHKnh308jzoixTF/vXPutb02CgkgeYZ956f/+kmzTHvUL3eItTMS8RcgmK+MZKqsI99FfZlxShZRGVEA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=gR2ObLPe; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="gR2ObLPe" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-934956bee57so54508085a.2 for ; Fri, 31 Jul 2026 05:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1785499560; x=1786104360; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Q3JgexJ0YvH/Q9Rjtz2xt8Xnp3qUV33bbtdN0HErD0c=; b=gR2ObLPeMWA7Eqsua5+qF0F6anzq8gCumz6WvUrghHw8WylUTdVYFmORyP66lot9r1 K9k5rFeoDlo1ZBSKH0LcnpsoILS+QJgZMxylPB+lND6Q1iXrjLQviSFd15qpEn+U2vk5 kQ6FnHZ+paN3lUxJOlSEYsIwbPsPSSjw6GYmi/MPYEJA6iE4agoWW/2+OhUC7wbQbzqt m49YSpIy3tsZOEekEjQiRpikO0giwAcwkrY8/vK+qwsXYx7iCEekjt1egRcTH5q/NM+I o8eZl2EkmFM6jSTCsnZ5oSMo7qrIy6we3/SUS2L7lsKLqtnxheLQVgnH4SkGBZhacbto CA2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785499560; x=1786104360; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Q3JgexJ0YvH/Q9Rjtz2xt8Xnp3qUV33bbtdN0HErD0c=; b=gSOdxlXtZ/IhwA1KQIw6v/BYXsNOsS6L9qoHV4bvMzDvv83KnF7I9G63Ydrh9U+lr4 m4Pyd9Sba26pkAVFKpYZlK7FarufBJ1ZhCRNIfNg0NFiAqLDf5HlQm+M/dpbgsXvi0jI p7haQpZd/qxwdOXX1bfP9wbTOc9BRFJuqfm1S8886Wxddf26KRX6Rn+I9e2jOLh305uB +lBK6Q2G3R5SKkBWvBn+I/EdwrauIoODlfaXbGssCTr7NEzhWdxenNofgAuPJ7bFvLZ2 VWBTPGGppC7KpsjMvhrxvczD0jFFpjb/56op1viwTYDRg7PGsjBvBCqNU+pnIoGu4CbP Drlw== X-Forwarded-Encrypted: i=1; AHgh+RqTYzUjzOpshQgF3Bl29ZH9rDhXKCX3mTbt5oZCGPNABHI1gra/KaFTnqaVaAiqGyhhagNW+wT75zahObY=@vger.kernel.org X-Gm-Message-State: AOJu0YxARSd8RI8cgDXzlk82sJwzUWPLU2xxXGPI2hTf9d3futiiec8Z ePVw92bdGKPio0EmHMm4tccgEbSbtqwFZPa5KZkHqR3X9ZL0q3h6rxv8pJbmQmuL5ws= X-Gm-Gg: AR+sD11VWA8TRUtB+VCWaL3IitHc338jIEKVqZIiybvxNJe04jOtQNGMX9K637CbFUG Yc86t4Nl94xGFHcnx+7B4dhR/eYj8Z9s18s9JR2aVMRvLy6kVjVyMYB9iU4H3dWOxfGcAuBIiDh jD42fDiRoXJzT3+EjUKiiRBQyYEn0eogRTE7wRVKy/tGsBivG7MgVaX7w5xV1Pwkh3sR1M/oB7S GGrumpM7B0+QyHFx3mr787oalc/kZtsEbcAUMirVcf6GDM78LT8NHDe0lImos/1GkChjc/1jPl9 zB90SQ06E38zXQTg3LTPgtjzqPAnIxNyuu4ohzmX9tFM0UHUgBsPF5Uzl+0A7w7iuIV2ER37gad dBYbbYJUQfRFmjIwu886igUiqPyFFGfg2uj7/Kjsb1XbGHPlLzCwleiJt18u9OwAc9ZH0tIyEi8 9kSQx4I3B/n67olFfFcoZO4uVluwZpK7OJjj8FkZMTAbnxI8B6PYGdLQhOOVcrx8t43Q== X-Received: by 2002:a05:620a:6293:b0:934:8ea0:9512 with SMTP id af79cd13be357-934965b723fmr259762985a.7.1785499559744; Fri, 31 Jul 2026 05:05:59 -0700 (PDT) Received: from localhost ([146.190.222.192]) by smtp.gmail.com with UTF8SMTPSA id af79cd13be357-9349c199c2asm40966085a.28.2026.07.31.05.05.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 Jul 2026 05:05:59 -0700 (PDT) From: David Lee To: marcelo.leitner@gmail.com, lucien.xin@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: David Lee , Kyle Zeng , Dominik 'Disconnect3d' Czarnota , horms@kernel.org, linux-sctp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] sctp: hold shkey across socket migration Date: Fri, 31 Jul 2026 12:05:57 +0000 Message-ID: <20260731120558.558957-1-david.lee@trailofbits.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit sctp_sock_migrate() transfers queued DATA skbs from the old socket to the new one. skb_orphan() invokes sctp_wfree() during that transfer and drops the skb-owned shared-key reference. If userspace has removed that key from the association, this can be the final reference. The following sctp_set_owner_w() then dereferences the freed chunk->shkey while trying to take the new owner reference. Take a temporary shared-key reference before orphaning the skb and release it after the new owner has taken its reference. This preserves the selected authentication key throughout the ownership transfer. Fixes: 1b1e0bc99474 ("sctp: add refcnt support for sh_key") Bug found and triaged by OpenAI Security Research and validated by Trail of Bits. Assisted-by: Codex:gpt-5.6-sol gpt-5.5-cyber Signed-off-by: Kyle Zeng --- Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can share if needed. net/sctp/socket.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index c7b9e325e..4a08023d5 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -147,9 +147,19 @@ static inline void sctp_set_owner_w(struct sctp_chunk *chunk) static void sctp_clear_owner_w(struct sctp_chunk *chunk) { + /* Keep the shkey alive until the new owner takes its reference. */ + if (chunk->shkey) + sctp_auth_shkey_hold(chunk->shkey); skb_orphan(chunk->skb); } +static void sctp_set_owner_w_migrate(struct sctp_chunk *chunk) +{ + sctp_set_owner_w(chunk); + if (chunk->shkey) + sctp_auth_shkey_release(chunk->shkey); +} + #define traverse_and_process() \ do { \ msg = chunk->msg; \ @@ -9632,7 +9642,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w); sctp_assoc_migrate(assoc, newsk); - sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w); + sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w_migrate); /* If the association on the newsk is already closed before accept() * is called, set RCV_SHUTDOWN flag. -- 2.53.0