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 99BD46D22 for ; Thu, 7 Sep 2023 17:08:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFEFFC43391; Thu, 7 Sep 2023 17:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694106508; bh=8jO1W9mwUvUnadY4KgpKhvkbf1MemC0e4uimo5BuJz4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AzM0rQmCUMf0ZFSbEc1BwCzm2ypPlMdLo+R3MwnzGaQfYMWxZPCg8PMOBVC3VmpKm XSSKdE0Wo0nEYM1GywOuLT1mNoM1sEg7oKwu6GsvQKlYbqaINM14SREVdLNa4TzhS4 0FR4lPmLWg72nwQonPuXArq0XwiLF/pVV9V6Mj5AFweGMpIBA9vo+0gGJiykdwKsYl sm7hputKL1xNXybZ1MXGbdUifhWdul43/c9pJGsQss7B04avGXVIdTDPhToceDJ6nZ jX8vPpEy3+QcCH1eeaXan6D61X6uBk4b6ChhXcmh5lpW1N28rUB4733qtDsrDUQsS/ Gaa40gi2hCf2Q== Date: Thu, 7 Sep 2023 10:08:27 -0700 From: Jakub Kicinski To: Sabrina Dubroca Cc: Herbert Xu , netdev@vger.kernel.org, Dave Watson , Vakul Garg , Boris Pismenny , John Fastabend Subject: Re: [PATCH net 5/5] tls: don't decrypt the next record if it's of a different type Message-ID: <20230907100827.7c3553ec@kernel.org> In-Reply-To: References: <20230906204727.08a79e00@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 7 Sep 2023 14:21:59 +0200 Sabrina Dubroca wrote: > I wonder if the way we're using ctx->async_wait here is correct. I'm > observing crypto_wait_req return 0 even though the decryption hasn't > run yet (and it should return -EBADMSG, not 0). I guess > tls_decrypt_done calls the completion (since we only had one > decrypt_pending), and then crypto_wait_req thinks everything is > already done. > > Adding a fresh crypto_wait in tls_do_decryption (DECLARE_CRYPTO_WAIT) > and using it in the !darg->async case also seems to fix the UAF (but > makes the bad_cmsg test case fail in the same way as what I wrote in > the cover letter for bad_in_large_read -- not decrypting the next > message at all makes the selftest pass). > > Herbert, WDYT? We're calling tls_do_decryption twice from the same > tls_sw_recvmsg invocation, first with darg->async = true, then with > darg->async = false. Is it ok to use ctx->async_wait for both, or do > we need a fresh one as in this patch? I think you're right, we need a fresh one. The "non-async" call to tls_do_decryption() will see the completion that the "async" call queued and think it can progress. Then at the end of recv we check ->decrypt_pending and think we're good to exit. But the "non-async" call is still crypt'ing. All makes sense.