Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3500633iob; Tue, 17 May 2022 01:04:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKcRuw1f59bSBpZENzPv94kmSyAGPG5rnPasGh+0L2F2fxMAQyOzwcS4EP35pjGuKKDrBw X-Received: by 2002:a17:90b:4b0d:b0:1dc:3d21:72c1 with SMTP id lx13-20020a17090b4b0d00b001dc3d2172c1mr34800551pjb.21.1652774683806; Tue, 17 May 2022 01:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652774683; cv=none; d=google.com; s=arc-20160816; b=JpcDBJDFotCqZKpaQT0IAdPaHPYN8WMC9l0eEXeoAloS5QF/iGLnNEGtxDS3fNR6n4 7C97YniOqL+pPP6AYfjwZLWUdkOiRjz+69+LzR0MDt8ehwnkKUbQ2UtQtDBQw9WHhcgj QPH/yB2j1CPTy1LU3gPA4KcdvYtwkvhfW+4/Std/ve8WQNXPM6Kw4PCEru+2h5E+9+7a l0nu1wGJxNUq5LGuvQzctk+LvbG/kTeZTzqEFzoAsxF4HPHr2zwFAbv/WlpTTUM3DmQI eN9Pblgn69i2iEovhx+6ZgS6cemiAwIp3J8NwnCwNXfc3Xhr5n4bbza8YY6PC/JF9KgB luqw== 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=GnrCuYnAGiByA3iLkHVwg/tX68TmJeQ6rw2/Acybe7nFOVqpmmfatr7g6KFDF3l8Vq ueYGaSoU0i3YITyCObD/6zOFTvTxhKqcOCV776ihp0+UiZcRtPC8fT/XWi6Z0vxKIshF e+YY9ZqHXh3LBSsH6JhsXVxyQ/MRh2iD0EkYV1FrQfUmpYo5yOeQjlqCCRRMXL6J+q9S lqDOp42zGUh8rWTUeR4Y31LskkoQjxoYenZ+7dmpTW28szJAV5jdx8bblwxOTVb9ZaNT WIdHSWPHqElzBFCn4GiG3J+nK0qe3+7uKS37h5v4xh/FdaPTpuu7O1ywhJ1URXEFUqRQ hRVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VFV2aFAd; 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 f5-20020a056a00238500b0050df2065f65si16895581pfc.124.2022.05.17.01.04.31; Tue, 17 May 2022 01:04:43 -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=VFV2aFAd; 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 S232773AbiEPUOw (ORCPT + 99 others); Mon, 16 May 2022 16:14:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351051AbiEPUB5 (ORCPT ); Mon, 16 May 2022 16:01:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694C1473B8; Mon, 16 May 2022 12:57:28 -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 3197EB81613; Mon, 16 May 2022 19:57:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9807CC385AA; Mon, 16 May 2022 19:57:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652731046; bh=SA/u6TfraJ4HVYA3POmKSQ4ZBz9ogmdGYvSFcf8IZ14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VFV2aFAdKdGzqaG+doSqvAbln0nN0rAQ9g82fzyuhkxfm1ixnr+AK8hM/2Tu00iLP GvlMF84JEPInffWa88v1vE63/FydSFHOae7l2Fox8KMTbQ9UKtJx5jHb+ZMJ8iYB9z Z8Z6hGyAQiVr0sF/fqWHO5L/Mr+lEK04gsY0uZuM= 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.17 046/114] tls: Fix context leak on tls_device_down Date: Mon, 16 May 2022 21:36:20 +0200 Message-Id: <20220516193626.815898749@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193625.489108457@linuxfoundation.org> References: <20220516193625.489108457@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