Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4810344yba; Tue, 30 Apr 2019 04:53:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqFOM2oFGmOIojSj5nwb/XXzwj3cUFzAnD89WCnQhKx+6mmCzhwPT8UejJ/XSVSqjWyu5e X-Received: by 2002:a17:902:ba8c:: with SMTP id k12mr50271371pls.213.1556625224738; Tue, 30 Apr 2019 04:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625224; cv=none; d=google.com; s=arc-20160816; b=zv649fQdUVr1tD2sSvTJtowndAHK9wkhIw3j1EL++UZwMlKzEjv4Biwi031xmOfzvR OLnw99/2dFxI67ur8F62JtDniReZ2nQODuwRlBOIDW2Ut8tAnOKW6JTL7QnGNTEZwwDo Nvi10MQbQRAxf9hwi9Pink/Q/4pZhL32XpkbnLE/CmVOe4a7pKG9WrfCzvDq6hlE5WuS Vfd2JMxzCwyLuR8wZQxt3nioaMSa4+bkCSt/KYDv4qLZe0BiA+17KauCZulmFJ5qs3ta i92gCPLJxYl3qpLXVrM2BQlW9+Wv0VUwI8dKgh+KP1JxXUp6nMzycwMRd+wQbX6fYOfX kmzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TGBvDBIkCF0cLbECGxcvf4spfx5JM2b9L77e2dl4AcU=; b=r9NTkYCNJIg7Jje4rIZgEjS4EaZz4VTd74jSt4FBbyFMleP/yyQwJfLTAMfahWvKvb 0RfFn+qM1lVf2qDb3bPbuI3Fph3RjyKNfXFLpptsEAOt8k4B8nEfWOvequuvNVtEUobR 4G3HuK3U3bWJEJEYIaY016dVRGNOX2b37v4yGfVSXjbD/72pLiJjcDsAcIQAd0BFCbxJ ZMSCCmyIjhg9oZFhjS59dq2BCw5gF9QcNoNLhAYExOndYDlA/cWg1Gzxv3eYSbvFlMtJ oFFxO6ClgaHp6PZzRokEH7KYZF2Y1BhRDzqXTmTt8Cb3nLEKbGonyaeLDOi+2mjumCtz PK+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JJeBMUIr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si36507717plv.329.2019.04.30.04.53.29; Tue, 30 Apr 2019 04:53:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JJeBMUIr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730578AbfD3Lv5 (ORCPT + 99 others); Tue, 30 Apr 2019 07:51:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:40020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731468AbfD3Lvy (ORCPT ); Tue, 30 Apr 2019 07:51:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67A2A21670; Tue, 30 Apr 2019 11:51:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556625113; bh=GI7f8oxnGKNMvPYBJch+PdzbwEuT7WfPKxWDxpYXwgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJeBMUIramEu1jWNvZ51s2DSYbg4rnsdf1gDOkB2fu7Pjw2s6QgyJsLOAF0MN1jLT L5IE+V/XEZLj6t6ZssxSWHrBsh4Ix2vKlMLOC1e6njPh9b9NIYM3j2qMi85vVJWjCo S1Y9i48bdiW+zNZUCa2shPyaGsgcN6Q0bK8jJ/E4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , Dirk van der Merwe , "David S. Miller" Subject: [PATCH 5.0 89/89] net/tls: dont leak IV and record seq when offload fails Date: Tue, 30 Apr 2019 13:39:20 +0200 Message-Id: <20190430113613.975297817@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jakub Kicinski [ Upstream commit 12c7686111326148b4b5db189130522a4ad1be4a ] When device refuses the offload in tls_set_device_offload_rx() it calls tls_sw_free_resources_rx() to clean up software context state. Unfortunately, tls_sw_free_resources_rx() does not free all the state tls_set_sw_offload() allocated - it leaks IV and sequence number buffers. All other code paths which lead to tls_sw_release_resources_rx() (which tls_sw_free_resources_rx() calls) free those right before the call. Avoid the leak by moving freeing of iv and rec_seq into tls_sw_release_resources_rx(). Fixes: 4799ac81e52a ("tls: Add rx inline crypto offload") Signed-off-by: Jakub Kicinski Reviewed-by: Dirk van der Merwe Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/tls/tls_device.c | 2 -- net/tls/tls_main.c | 5 +---- net/tls/tls_sw.c | 3 +++ 3 files changed, 4 insertions(+), 6 deletions(-) --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -921,8 +921,6 @@ void tls_device_offload_cleanup_rx(struc } out: up_read(&device_offload_lock); - kfree(tls_ctx->rx.rec_seq); - kfree(tls_ctx->rx.iv); tls_sw_release_resources_rx(sk); } --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -304,11 +304,8 @@ static void tls_sk_proto_close(struct so #endif } - if (ctx->rx_conf == TLS_SW) { - kfree(ctx->rx.rec_seq); - kfree(ctx->rx.iv); + if (ctx->rx_conf == TLS_SW) tls_sw_free_resources_rx(sk); - } #ifdef CONFIG_TLS_DEVICE if (ctx->rx_conf == TLS_HW) --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1830,6 +1830,9 @@ void tls_sw_release_resources_rx(struct struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx); + kfree(tls_ctx->rx.rec_seq); + kfree(tls_ctx->rx.iv); + if (ctx->aead_recv) { kfree_skb(ctx->recv_pkt); ctx->recv_pkt = NULL;