From patchwork Wed Sep 6 17:08:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 13375806 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D5A6AEDB for ; Wed, 6 Sep 2023 17:09:12 +0000 (UTC) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1171998 for ; Wed, 6 Sep 2023 10:09:11 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6983620007; Wed, 6 Sep 2023 17:09:09 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: Sabrina Dubroca , Dave Watson , Jakub Kicinski , Vakul Garg , Boris Pismenny , John Fastabend Subject: [PATCH net 4/5] tls: fix race condition in async decryption of corrupted records Date: Wed, 6 Sep 2023 19:08:34 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: sd@queasysnail.net X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In case a corrupted record is decrypted asynchronously, the error can be reported in two ways: - via the completion's error mechanism - via sk->sk_err If all asynchronous decrypts finish before we reach the end of tls_sw_recvmsg, decrypt_pending will be 0 and we don't check the completion for errors. We should still check sk->sk_err, otherwise we'll miss the error and return garbage to userspace. This is visible in the bad_auth test case. Fixes: 94524d8fc965 ("net/tls: Add support for async decryption of tls records") Signed-off-by: Sabrina Dubroca --- net/tls/tls_sw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index babbd43d41ed..f80a2ea1dd7e 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -2116,6 +2116,9 @@ int tls_sw_recvmsg(struct sock *sk, ret = 0; if (pending) ret = crypto_wait_req(-EINPROGRESS, &ctx->async_wait); + /* Crypto completion could have run before us, check sk_err */ + if (ret == 0) + ret = -sk->sk_err; __skb_queue_purge(&ctx->async_hold); if (ret) {