Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3282057iob; Mon, 16 May 2022 18:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzghNXua4Com8HNI2F3O+stN8hYmcFFgerBP1VRkGdXlgQnYVItpH5Ndeb3qfyQqZYzaJxg X-Received: by 2002:a05:6a00:134f:b0:50e:10e0:ef82 with SMTP id k15-20020a056a00134f00b0050e10e0ef82mr20178706pfu.45.1652749419529; Mon, 16 May 2022 18:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652749419; cv=none; d=google.com; s=arc-20160816; b=kweaNECQF+KTK4f2uypJp8H2018iv2Gs/amqtgEBM86W60XDhYjPYFHa2H1E6WP191 oCZT6YhjroVhe59giJK2Wl61FjuYcB+AFGErE2UxXstg6qa4htldpuf/bxOnHSFo/VsC Y6JsTZ74cYwT0DQmVGDZ+dD8HJqkCj2CWDN9uPj2h0tB5HiMtT8ncqyJzR2pf0Fvoail WtIcpGSZepluZOF0t4uvx0WEJAdI64cn22y2/a6GhZnggvZ/fA3BMVl68tscUtGI0uQx 8TDFPFjTcqB0hZJ+zX2/jjQvIsgtcthYE7Ye48WA2TLs2olaQTaYsa0D9jheB1mAfV4+ 1sNw== 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=p4Bx6GMT0/76JxyK5fw3OXTqYLz3TQp6AQFcMJIwcCU=; b=ULnO1MZceTL97+t0jX5E3tZY93oAKSPQTb+J0d7VwyyQjFkxTXHcN056V6jSLRkCIJ JK+3qtb9V4TK40+H60rqwwkH+XfyX/TgO0N9fXwrog0aDKzkgC8+obJOAPvI4ck+5d1a gVlG8p3DPKlxm192rVzZ9a1iF3dTF/GXnqJfsNvz1G3iyDMfvS2GrnIKfM8+sdvSMjyS CuwJkujbOPjN4TM8G+KTjBACIAit4Q0aHrnm9eQxHos4hKSX6+T5McQM6J879gWKPupZ tBgCeCvy/djENaAcvylagIgC89nMCVMPwnCB7VdLfwNqy4IM0wPfBejCKm+2BhUNgAeS hAlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pFLEKuEP; 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 b1-20020a170902b60100b0016157654cf4si8886778pls.227.2022.05.16.18.03.26; Mon, 16 May 2022 18:03:39 -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=pFLEKuEP; 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 S1347591AbiEPU03 (ORCPT + 99 others); Mon, 16 May 2022 16:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347571AbiEPT54 (ORCPT ); Mon, 16 May 2022 15:57:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DA1248328; Mon, 16 May 2022 12:49:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2F59FB81613; Mon, 16 May 2022 19:49:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8539FC34100; Mon, 16 May 2022 19:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730579; bh=SA/u6TfraJ4HVYA3POmKSQ4ZBz9ogmdGYvSFcf8IZ14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pFLEKuEPiqf4Nu780VqcEKAq6ujFGom+svEyZkmDfvxFsz89F/QRuxaRuykF7nl5A tP9LFKXYYCWIVi/AR9shO1+iAiFr/zlsOeh1NfhD+PSY6wo3dH7j+RMPFtpiPzMT6U 0BxeKMFr8gf5RqRS8h+gJcgQ4Yt/VivRi18jaexg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Mikityanskiy , Tariq Toukan , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 042/102] tls: Fix context leak on tls_device_down Date: Mon, 16 May 2022 21:36:16 +0200 Message-Id: <20220516193625.208088763@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@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.4 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,T_SCC_BODY_TEXT_LINE autolearn=ham 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 [ Upstream commit 3740651bf7e200109dd42d5b2fb22226b26f960a ] The commit cited below claims to fix a use-after-free condition after tls_device_down. Apparently, the description wasn't fully accurate. The context stayed alive, but ctx->netdev became NULL, and the offload was torn down without a proper fallback, so a bug was present, but a different kind of bug. Due to misunderstanding of the issue, the original patch dropped the refcount_dec_and_test line for the context to avoid the alleged premature deallocation. That line has to be restored, because it matches the refcount_inc_not_zero from the same function, otherwise the contexts that survived tls_device_down are leaked. This patch fixes the described issue by restoring refcount_dec_and_test. After this change, there is no leak anymore, and the fallback to software kTLS still works. Fixes: c55dcdd435aa ("net/tls: Fix use-after-free after the TLS device goes down and up") Signed-off-by: Maxim Mikityanskiy Reviewed-by: Tariq Toukan Link: https://lore.kernel.org/r/20220512091830.678684-1-maximmi@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/tls/tls_device.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index a40553e83f8b..f3e3d009cf1c 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1347,7 +1347,10 @@ static int tls_device_down(struct net_device *netdev) /* Device contexts for RX and TX will be freed in on sk_destruct * 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)) + tls_device_free_ctx(ctx); } up_write(&device_offload_lock); -- 2.35.1