From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3550317161; Wed, 11 Mar 2026 00:20:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773188402; cv=none; b=nYuwaPW5+f6lJDeWah8qkXr3q8clZePYzIcE4ws/IJCj8pKtfmDe4zile+koxX8dWdSJzuOHa7K1LE+VzStC3PfG4ZEAnG4vt8/wOIxaWUrBQW/q7K8rh89Y3LDm1eB0lcRLhJx/mUUoDcmVIvnZRRGVgwkLv6QAbiVQp5Ftd1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773188402; c=relaxed/simple; bh=78oJo2JmKzBr6Bl7B58mYl3fBcmHzgJm0VGXULlhPgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aTmHWxU3oinTJA7quyfjNmBUZIucUrzP1h+hHAXfAeF92f1gflLDCT9cK8gKkPSWkjDNNfWkHv28ddbANXTYDQ4qo69sTgNehV+sy/Pb73aCccZu0RYQqFSKS6sXbXJnoo2HnLJ5q1kURQ4X63FQgBw7btJZYU/7tHVF2ZuN03E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rOm6cOg1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rOm6cOg1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A681BC2BC9E; Wed, 11 Mar 2026 00:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773188402; bh=78oJo2JmKzBr6Bl7B58mYl3fBcmHzgJm0VGXULlhPgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rOm6cOg1HXCuyuZcJxxrSIqT15aY2IqIa4rSpi33iakZLcaBJH80TngBdt/YLyCdE SvLDBHconZY6YaOT8Boi4AVGiTPEKtkP6g1O2ubMFDJXTYoiM5quBIwMDCTLfQPbIL ZJcN9Qr+Myan1c8dN6a4v8CCqHMRNyveeWsmNZB150UubVIVZ1mtF0L6fUOzBbrHnv rs8u/HvmvK8l7FIV6awp0uMw9n2Wqn1/yqm8IV6Bw3AJLxTDvRty3U4+A4JvlsW+Oa V/stePc7tra0u8VvprlL+mLLqu8kS2VfeYCHQvktuEDvaoK6l56BNUmwGR9ZKB4m4t eHxSp/TCcbrzQ== From: Chuck Lever To: john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net Cc: netdev@vger.kernel.org, kernel-tls-handshake@lists.linux.dev, Chuck Lever , Hannes Reinecke , Alistair Francis Subject: [PATCH v2 3/8] tls: Fix dangling skb pointer in tls_sw_read_sock() Date: Tue, 10 Mar 2026 20:19:47 -0400 Message-ID: <20260311001952.57059-4-cel@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311001952.57059-1-cel@kernel.org> References: <20260311001952.57059-1-cel@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chuck Lever Per ISO/IEC 9899:2011 section 6.2.4p2, a pointer value becomes indeterminate when the object it points to reaches the end of its lifetime; Annex J.2 classifies the use of such a value as undefined behavior. In tls_sw_read_sock(), consume_skb(skb) in the fully-consumed path frees the skb, but the "do { } while (skb)" loop condition then evaluates that freed pointer. Although the value is never dereferenced -- the loop either continues and overwrites skb, or exits -- any future change that adds a dereference between consume_skb() and the loop condition would produce a silent use-after-free. Fixes: 662fbcec32f4 ("net/tls: implement ->read_sock()") Reviewed-by: Hannes Reinecke Reviewed-by: Alistair Francis Signed-off-by: Chuck Lever --- net/tls/tls_sw.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 81e0e8aaa6f9..e5d0447cbba6 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -2373,7 +2373,7 @@ int tls_sw_read_sock(struct sock *sk, read_descriptor_t *desc, goto read_sock_end; decrypted = 0; - do { + for (;;) { if (!skb_queue_empty(&ctx->rx_list)) { skb = __skb_dequeue(&ctx->rx_list); rxm = strp_msg(skb); @@ -2422,10 +2422,11 @@ int tls_sw_read_sock(struct sock *sk, read_descriptor_t *desc, goto read_sock_requeue; } else { consume_skb(skb); + skb = NULL; if (!desc->count) - skb = NULL; + break; } - } while (skb); + } read_sock_end: tls_rx_reader_release(sk, ctx); -- 2.53.0