Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3530272pxb; Mon, 1 Mar 2021 12:26:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwU/EiY8fVcJEd3R1V0WhBDx/y5/cpmPPj+fJCr/GZi+Ba2VgZOPN4M9QovkNPgA4VTUjMx X-Received: by 2002:a17:906:3846:: with SMTP id w6mr12101976ejc.190.1614630384715; Mon, 01 Mar 2021 12:26:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614630384; cv=none; d=google.com; s=arc-20160816; b=pPm+f++oNyB2npLOj1/CFVtaAzlVsgPnD7798fxYqOkm7Dc6urhfgr5ZQzWuzUuHMl /T610OrDpQjOh6npBbSgJjvZamE+dIHqBSKNyHDoo6xSaEyUvR48OVhbDXy4PDfW64f8 7MT0HOeVyJEE2NGQBWwLHU9LqhtigpXsO2Ii2+WWPHsT9Oh7pFsTlivl6l8KLnvZr5cT EdtSv2QZJ+4FFbsKIQBoFrS/34y21uP43IPXVNglte9DyFURWapJg/ursnzixXWM4v4R AMrnrAUQxXkgpkunBUVoWCf9xyZfAqw4RRnXDLnsH0qGo7WBOhgEojWih/Q42W7RrEgC /STg== 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=FeY0Q4+oxlgje0E+29y+t1uOSjnXcECLYZnUHITNk0k=; b=FIBa380wVED4+YXVs/EEd2sDBU0zSDYVrYdNi1KaGRsmwoCPJ30xSib1vhuhr4bVPF TDB+1kMCGnpBtSq22rp8BCdjpQd4sQV3KzLfSVhVfDUetGR+2H+/mIZsXJ7vO7WQD7hP nISIEJAzno4PEWIGUr7uwSVtdqmq5M6MDip4zW/jKGK3GHDx4l5KyZ+HAKVA3R9itmng eYuQSn6mfAzDXSLLl1ITN1jrt2v2abNpTNmeKPX+6FLIjqkqTDT9NXx07qo0BnGK0gVe iOrREnY/yTRZ7ncgUiD+ureQnuywRrYRRepe0em8lRqD5HhqmWtD9c4TbejjspkSm2mR DoVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ia8zzCDF; 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 ce20si12646388edb.138.2021.03.01.12.26.00; Mon, 01 Mar 2021 12:26:24 -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=Ia8zzCDF; 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 S243336AbhCAUX5 (ORCPT + 99 others); Mon, 1 Mar 2021 15:23:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:35190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237019AbhCARGg (ORCPT ); Mon, 1 Mar 2021 12:06:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F39265006; Mon, 1 Mar 2021 16:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616810; bh=mVXHPPGSoVJWCQHkgdeHFEyC1wUa0+k1TnjiwN4hG9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ia8zzCDFijebdNm0Vc/TqooKF/BhQG3vdz4Ul5KzB9tedrjzTLIbMQH/u3nXcOgrW 5FD8bKHe9mX8yFnCFwnT3oIw3M4zkDAU16Lsz2QfEE0f93oSlFEwLGr/v6yEDG/11r lXcfdv7YtmOXGRrym/YEcnCWmGeAAgQXKFgtytjk= 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 4.19 104/247] ima: Free IMA measurement buffer after kexec syscall Date: Mon, 1 Mar 2021 17:12:04 +0100 Message-Id: <20210301161036.762777874@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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 9e4e638fb5051..fe9f6f2dd811d 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -260,6 +260,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 c6a3b6851372c..2fbdb78d66c80 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -168,6 +168,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 9f8449dea5b69..6a10d4d8b6e1d 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -134,6 +134,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