Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp916562pxb; Wed, 3 Mar 2021 20:58:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxi22C8H3GF6Fir/j9xQiSl8i91eG4EgERrBcTtdHirxk3NiW+Txh4FXB6VPmOCp+VUYRMN X-Received: by 2002:a17:906:13c4:: with SMTP id g4mr2293280ejc.390.1614833889271; Wed, 03 Mar 2021 20:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614833889; cv=none; d=google.com; s=arc-20160816; b=TKAO2iu8z/HTXd9/HOw84g2jwABN+5yd6rYs2HBActg1KLsWG5maC4X9w+Hx7sGdKq Kh87kQW2I/dvIamYDZ33liUn2O4JfBKncED4X2hp7wkaYvx87oGTC28uNAbHD/yirlkL MoeJcN992479DXBm7k6NfR/UWkOYa2kYeVh/mffsbBAQ1b/+VFShszNlMGudbZqga7I+ FwqPEJZS0h8ufsHQRJH39zuYnZ5k3oITVcQSjrWk/B9Y8JIVl6DDXYy0x0ODqF7ZoKMd e3seuFetCPHc0twNsQaPbBUkDdAfHwHnRERvyPERGSRIWVHp0xwQVlpfIuymRLjeW7hn TiXQ== 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=IrTMV/G0P50aKYGEOe3LTBbuVN91ZQN/HIr0RhWXIqM=; b=0pGlEWR9zL60ZWPN3QcrYngdXYToFzfryUrVBkdRMBXSdp9GOT8FVc4qn2PCibLNy4 3nFWcwtzV8lvAmwJ94zXaIJMWSrt5Fgee3Zi+rlWUpgP8y8SA36zWR0Otd57WNdWaEf6 UNK/BSNR8CD4/owrglrf2mPeWG1zn8fto8BHIefERIsZpj86dBt85ZJpWVyFeZHV22gg skipnywnfhAYAEGyaS69DCOMIRhhcU//04hI6OS6tpNwyDMQAeuNoYGfnT7bb62IPiFk bQPno3YhE3oV8g5SV9HNEPZhdjzjyZ9tQcZ2QgI8MHnWepGEBrF0ViC1RGWzykuG4AYf G4OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FZKqcwWp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si17309586edb.465.2021.03.03.20.57.47; Wed, 03 Mar 2021 20:58:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FZKqcwWp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1443076AbhCBCSY (ORCPT + 99 others); Mon, 1 Mar 2021 21:18:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:55144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234733AbhCATof (ORCPT ); Mon, 1 Mar 2021 14:44:35 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9ECC76510B; Mon, 1 Mar 2021 17:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618870; bh=xnB4jhQfrv/DG2lf8LK+Veia8APj8DVBYW29+Jt0+qg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FZKqcwWpuOd2oGm88M/zl3DMI4LbD+6ZnRSKr/t5WFP8akanaxd3Q0jEz3Z/lfetm zNQXvNmNm2PXPxghg7OiQTeWwyV2VFAL9+woz8nI0OHs4ckCysO/RKQ2z+o+Dcikij 46zNjO9Ap9tvvIyRDH/EuLGGxhK3Zncm/w7FwzJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lakshmi Ramasubramanian , Tyler Hicks , Thiago Jung Bauermann , Mimi Zohar , Sasha Levin Subject: [PATCH 5.10 247/663] ima: Free IMA measurement buffer after kexec syscall Date: Mon, 1 Mar 2021 17:08:15 +0100 Message-Id: <20210301161154.041224805@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lakshmi Ramasubramanian [ Upstream commit f31e3386a4e92ba6eda7328cb508462956c94c64 ] IMA allocates kernel virtual memory to carry forward the measurement list, from the current kernel to the next kernel on kexec system call, in ima_add_kexec_buffer() function. This buffer is not freed before completing the kexec system call resulting in memory leak. Add ima_buffer field in "struct kimage" to store the virtual address of the buffer allocated for the IMA measurement list. Free the memory allocated for the IMA measurement list in kimage_file_post_load_cleanup() function. Signed-off-by: Lakshmi Ramasubramanian Suggested-by: Tyler Hicks Reviewed-by: Thiago Jung Bauermann Reviewed-by: Tyler Hicks Fixes: 7b8589cc29e7 ("ima: on soft reboot, save the measurement list") Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin --- include/linux/kexec.h | 5 +++++ kernel/kexec_file.c | 5 +++++ security/integrity/ima/ima_kexec.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 9e93bef529680..5f61389f5f361 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -300,6 +300,11 @@ struct kimage { /* Information for loading purgatory */ struct purgatory_info purgatory_info; #endif + +#ifdef CONFIG_IMA_KEXEC + /* Virtual address of IMA measurement buffer for kexec syscall */ + void *ima_buffer; +#endif }; /* kexec interface functions */ diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index e21f6b9234f7a..7825adcc5efc3 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -166,6 +166,11 @@ void kimage_file_post_load_cleanup(struct kimage *image) vfree(pi->sechdrs); pi->sechdrs = NULL; +#ifdef CONFIG_IMA_KEXEC + vfree(image->ima_buffer); + image->ima_buffer = NULL; +#endif /* CONFIG_IMA_KEXEC */ + /* See if architecture has anything to cleanup post load */ arch_kimage_file_post_load_cleanup(image); diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c index 206ddcaa5c67a..e29bea3dd4ccd 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -129,6 +129,8 @@ void ima_add_kexec_buffer(struct kimage *image) return; } + image->ima_buffer = kexec_buffer; + pr_debug("kexec measurement buffer for the loaded kernel at 0x%lx.\n", kbuf.mem); } -- 2.27.0