Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp402318pxb; Thu, 21 Jan 2021 09:43:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyijLrnGmUnqCI0juXNYsZ48VsTzNBn1GsqD9OfeuB4TpdGTnCqI1nejqOQdOY1rIl7jts3 X-Received: by 2002:a50:bc14:: with SMTP id j20mr182990edh.381.1611250986432; Thu, 21 Jan 2021 09:43:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611250986; cv=none; d=google.com; s=arc-20160816; b=DWw0jjCO1waEfBqp7LHaEt75HsoK5FnwSQ79Kl94Y/Uuoxrl4VHJLxTunUofIPh3+j oLJzSTolqcJRQJVNqbzQgE0CttprLVDMVB2Qf1ySkQSZV4OHnqn9kFcvmz6EMw3c/aWJ jdHooSsXsqPwH7KJ3eKNgECO4KaGr2PaQEpCs6gOr10VO6oiJLQYYBxHch/K30HNfWcb 7SpyG1SIwvHCrOpUnyFgdbv3dEwhe3J0qojkhFQrSZx4rlHLFTi6NvaeAj3UbS9ibTXr VoeJ6jdoDRIbiORjrkCE5VRjyY5jrfUBJLGlWuhyH0mvrY3Gr1dTMF2rMe3MF2a+6Zhb DEAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-filter; bh=fbcRcp3idFFWOwiOjLdBsLqpIczhr4t2xXWIs0rFOng=; b=Uz+8dcx6Oa4+ro17gg2D8COVpnID32Zd5veQzYTdsjJGtxcFWpdV4n3kk9FazXc12K o+rww9n58h+GZOXd5ulVcxMp9zBy1yLNZHDA/14cYQMZGaaxaL0C+zhdZzwqGmQCodHK 7tmTjw5aiLgUAezOadjevzfuRxhptUP+gSj6GXOCl6uDkICr1GavsNa0Sxdcq1AnnN6x mdRYaK24YHSD/Jd2dJHdOLQIJaakoVmC63Te31tKibtPdEL5/rHBcIA6wbfHlxTdWipn Sv/CM3Vlrg9C+NIF8jQDPh7sbbcj6/rBEYY3V1RRlgX4LhVYZU/8umlPipa6oHJg8PbQ A4vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Fmcd9Krw; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx12si2028610ejb.375.2021.01.21.09.42.38; Thu, 21 Jan 2021 09:43:06 -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=@linux.microsoft.com header.s=default header.b=Fmcd9Krw; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388910AbhAURju (ORCPT + 99 others); Thu, 21 Jan 2021 12:39:50 -0500 Received: from linux.microsoft.com ([13.77.154.182]:58572 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731961AbhAURh6 (ORCPT ); Thu, 21 Jan 2021 12:37:58 -0500 Received: from sequoia (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 30AE920B7192; Thu, 21 Jan 2021 09:37:17 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 30AE920B7192 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1611250637; bh=fbcRcp3idFFWOwiOjLdBsLqpIczhr4t2xXWIs0rFOng=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Fmcd9KrwyIO9TqvZmr0jqA0gEJmzIDHUMnaPFQFbijMEsfENZEAaX5Xo++kbH58i2 agEegx67+IM2QDODuukFUevio4kE2yxldq9dWrZ+0CmuNgv6vejrdDnHKRZRE9PLqW uEJDWxGe0Mz7g7InS7KFcW/oXqQJKMMVZuGT+FUw= Date: Thu, 21 Jan 2021 11:37:15 -0600 From: Tyler Hicks To: Lakshmi Ramasubramanian Cc: zohar@linux.ibm.com, bauerman@linux.ibm.com, dmitry.kasatkin@gmail.com, ebiederm@xmission.com, gregkh@linuxfoundation.org, sashal@kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH 2/2] ima: Free IMA measurement buffer after kexec syscall Message-ID: <20210121173715.GF259508@sequoia> References: <20210121173003.18324-1-nramas@linux.microsoft.com> <20210121173003.18324-2-nramas@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210121173003.18324-2-nramas@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-21 09:30:03, Lakshmi Ramasubramanian wrote: > 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 > Fixes: 7b8589cc29e7 ("ima: on soft reboot, save the measurement list") Reviewed-by: Tyler Hicks Tyler > --- > 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 9e93bef52968..5f61389f5f36 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 b02086d70492..5c3447cf7ad5 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 212145008a01..8eadd0674629 100644 > --- a/security/integrity/ima/ima_kexec.c > +++ b/security/integrity/ima/ima_kexec.c > @@ -130,6 +130,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.30.0 >