Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp61123rdb; Wed, 18 Oct 2023 18:26:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEutY5J+sLmz9pnI6mqV2kSNo1Lf9OH63BizGxyq9+79iflBZYuXfcdRUiRtFA3YqG6m1n5 X-Received: by 2002:a05:6a00:2da4:b0:6bd:8c4a:ab9c with SMTP id fb36-20020a056a002da400b006bd8c4aab9cmr772906pfb.4.1697678773986; Wed, 18 Oct 2023 18:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697678773; cv=none; d=google.com; s=arc-20160816; b=cVvevsf6Pji8CTyw+ooFi/1f1gWLw6dNRziWT7KcK1YoX4aCkMv0ot4DNAGLMxiBsU 1PwXWsnTfCIKatCn5z5sl7rzi/kzaAlvjYAzuQHUW9orefkLmeZ4ALj0SRCWGokXkEcx 0850+0racKPegTg3PBTKx16EWxwp13574pmmtwOmEFFJG9IKcUl02xxZSubPIIkiaRfq cQEXzQNzNT/9s2FVg5LH0fcgl3BnO87cwsQ53Thv9hztl+rWw1zhs80t9X9YWlqnRC6P MMauVCsjVN64qYqPnOPGMwhQIhcNUB0TlKVXd8Htw2sotvwzZOvWurlSM/jNy52sK9GC 8H3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=WgQkp9yWI/pkNQl5HDhgY05PHsBCgsE3JkDGuHifJO0=; fh=fKyVCt3PqRlYvleAGYcAwisidGMs/bu5Uc2vKZRFOXc=; b=oDaMQaZ4EJFFEufUGvyrQLsXOqKRX5iPsQtYwr+dgoGbhhSX4x7eKN974O0hAsdzvh cwqLS8v1gCZKZcR7d/pKNwBLnSPG+VWwB76JgYAckk9aIPTW/n9u2MToiBaWOAJ+KsN9 otngEFS0MwZhnsyW4PUEnlXEYWaLp44vHma9lr/v8uQfsA9UkWO3k8JEKi7JgjniSfw2 VsXz51ABaNf5k2OoFwSkPqCtnQjsxbW7a6uGrLr4MYtZbr+IwILzGVJrPwxbgq7R0jn1 tE01MvgkthsHF4gWw4XoCZDdiINS7THatYB+4pwVT4yfk7bYfC0g6FUujIT+DK1ffU9R DlQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sMU+hWZx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id j1-20020a056a00130100b006be0559d029si5305480pfu.109.2023.10.18.18.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 18:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sMU+hWZx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 88296822A498; Wed, 18 Oct 2023 18:26:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbjJSBZ6 (ORCPT + 99 others); Wed, 18 Oct 2023 21:25:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJSBZ6 (ORCPT ); Wed, 18 Oct 2023 21:25:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 996BA124 for ; Wed, 18 Oct 2023 18:25:56 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6704C433C8; Thu, 19 Oct 2023 01:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697678756; bh=Bo2rNx1P5rqGaRjEElKR9ESp+uBQTFt4srxoPCP49qg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sMU+hWZx+AHKSSgK5/4oSCK2E6eC9t2jpi3nyN5NybU+tl2tCFztBba96/APfBvvq u/qJp3EtjORVy7stL42taf3tyMTEI213hGi0U+r5iH2qAwdLwTfxURxu9Z29EDSRnS 5Kfkm6s2DzVngw5z1tzt9dguOMfONFXhab5MIE590zpON8/3hJnjVjg1JdmaSwcYe9 RwIxwSU+x+FGYErCc5CwSe3ipiRRhmkAOM0F8me9v/oioEr+u+JZBe08YCfSfA8CJW HxPgYb+V5eGyrExTi/yKZG3TKXYJWyVcJQ4cSvoEreID/PpI8fhCDPx6Gj51r8/ym3 u22ebC2xUj6+A== Date: Wed, 18 Oct 2023 18:25:55 -0700 From: Jakub Kicinski To: Juntong Deng Cc: borisp@nvidia.com, john.fastabend@gmail.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, syzbot+29c22ea2d6b2c5fd2eae@syzkaller.appspotmail.com, Sabrina Dubroca Subject: Re: [PATCH v2] net/tls: Fix slab-use-after-free in tls_encrypt_done Message-ID: <20231018182555.28f1a774@kernel.org> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 18:26:10 -0700 (PDT) On Wed, 18 Oct 2023 00:22:15 +0800 Juntong Deng wrote: > In the current implementation, ctx->async_wait.completion is completed > after spin_lock_bh, which causes tls_sw_release_resources_tx to > continue executing and return to tls_sk_proto_cleanup, then return > to tls_sk_proto_close, and after that enter tls_sw_free_ctx_tx to kfree > the entire struct tls_sw_context_tx (including ctx->encrypt_compl_lock). > > Since ctx->encrypt_compl_lock has been freed, subsequent spin_unlock_bh > will result in slab-use-after-free error. Due to SMP, even using > spin_lock_bh does not prevent tls_sw_release_resources_tx from continuing > on other CPUs. After tls_sw_release_resources_tx is woken up, there is no > attempt to hold ctx->encrypt_compl_lock again, therefore everything > described above is possible. Whoever triggered the Tx should wait for all outstanding encryption to finish before exiting sendmsg() (or alike). This looks like a band-aid. Sabrina is working on fixes for the async code, lets get those in first before attempting spot fixes. -- pw-bot: cr