Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1942985imn; Mon, 1 Aug 2022 05:54:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t1tMW2BQL4MHq360sqm/oWT+GGJIqk+/pFx6ncTrr/6JE3dCpHHEKPwytmDoqG5F7a4Otq X-Received: by 2002:a17:907:7ea4:b0:72b:6929:4571 with SMTP id qb36-20020a1709077ea400b0072b69294571mr11860496ejc.257.1659358444693; Mon, 01 Aug 2022 05:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659358444; cv=none; d=google.com; s=arc-20160816; b=OOkdCQ06YljLKgtj49ipZIKGXTLEcPptFH0TMMUx/vHddPBBZVoBqrLZh23RWi3bzP cyxRFQmGPaafqEneEayugB0AAme0wUQ/UmE9zja1wJALuh8BC20UIWIs1oFipJ8oGv5l cORUXOrkFDDsJF8Nq6zMkUPLvlclp59t58GOyLwa271sQiSvSA5VJQ+pBuGQtVapJHeQ VhLnA0wMdBfdUxqkNq5xDLc7qt0AK5krL3bYWu5guplzxc7H6RNCo9DdRNF+ZcVv/lX/ UY6ICJm016wqulTCn/Hx/9Hslq/8rwao2FSeU9juLZ53depvhSOweL9y5s5PwArH/TUN 12cA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uxrhY4X0npY8IIiV8W8ONJCCJxOTqUVKpWurj+KBMfo=; b=zK8DYFeiUEeYevSjBiPpfPJC2xHBk5bZ2MceXZkjH6HeCUqsgm+SnlB3+vtUFx6NQY KGQCk/Dn5lS3NM5PJ1aaR6bla0T//e2KD6XWbzxiB8/XV1n9eVeWDGNrpQrPdkLZBgls mYrRj2DwQR8d5BT26xp8QCjJbN9qa3LLDXCkF9ZDo/eCug29CgLavGjxBc933BJ/9VTD kx5oVvKPRYKsV2Iabfvgp04A/m+2KHeSIhHSm/IOGUmZir7qD+EYthw1q/rYJuHyF8Va Mb5qwCDYye7XIH7rbquNhqY7/hO0+zM4xVFI9x2JlINIM/IstsnwZXnWdH0BOe9Fobkm kx1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BlbFaccM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a056402120b00b0043db3c4b3b8si103902edw.28.2022.08.01.05.53.37; Mon, 01 Aug 2022 05:54:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BlbFaccM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233760AbiHAMNl (ORCPT + 99 others); Mon, 1 Aug 2022 08:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233839AbiHAMMH (ORCPT ); Mon, 1 Aug 2022 08:12:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1D39747A9; Mon, 1 Aug 2022 04:57:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC54F6010C; Mon, 1 Aug 2022 11:57:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7079C433C1; Mon, 1 Aug 2022 11:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659355042; bh=RrVXgdvfQtwSt4RGJnS3IJQPKE/wnM+B5zyTBr4hOo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BlbFaccMGSGElkk20bqO3GCi0d36fh7iIRA0LlwtWPH3qgpEJN2HDvsnTQsfpvhnJ GKouLfHYNAUyZqz7gepjb5aU7eiDMOSECuJ1bGoOZtIpMf5yOvEchhGQN1Nyk2J1I7 RQdTfG1qVUSLRbyshSxRZXPwVZstePyAr0ZROr8s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Mikityanskiy , Tariq Toukan , "David S. Miller" Subject: [PATCH 5.18 42/88] net/tls: Remove the context from the list in tls_device_down Date: Mon, 1 Aug 2022 13:46:56 +0200 Message-Id: <20220801114139.964066737@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114138.041018499@linuxfoundation.org> References: <20220801114138.041018499@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxim Mikityanskiy commit f6336724a4d4220c89a4ec38bca84b03b178b1a3 upstream. tls_device_down takes a reference on all contexts it's going to move to the degraded state (software fallback). If sk_destruct runs afterwards, it can reduce the reference counter back to 1 and return early without destroying the context. Then tls_device_down will release the reference it took and call tls_device_free_ctx. However, the context will still stay in tls_device_down_list forever. The list will contain an item, memory for which is released, making a memory corruption possible. Fix the above bug by properly removing the context from all lists before any call to tls_device_free_ctx. Fixes: 3740651bf7e2 ("tls: Fix context leak on tls_device_down") Signed-off-by: Maxim Mikityanskiy Reviewed-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tls/tls_device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1351,8 +1351,13 @@ static int tls_device_down(struct net_de * by tls_device_free_ctx. rx_conf and tx_conf stay in TLS_HW. * Now release the ref taken above. */ - if (refcount_dec_and_test(&ctx->refcount)) + if (refcount_dec_and_test(&ctx->refcount)) { + /* sk_destruct ran after tls_device_down took a ref, and + * it returned early. Complete the destruction here. + */ + list_del(&ctx->list); tls_device_free_ctx(ctx); + } } up_write(&device_offload_lock);