Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp480285pxb; Wed, 3 Feb 2021 09:50:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzf3OJVhNfZ9O4CuVwSuBJqmkLGYtMNWcXIrXwMlI1uxcE4v+uILIKOlC7pqMEh2wYjCnPc X-Received: by 2002:a17:907:98d7:: with SMTP id kd23mr3649627ejc.283.1612374633659; Wed, 03 Feb 2021 09:50:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612374633; cv=none; d=google.com; s=arc-20160816; b=ynjhfW0A4szY6gQcif4H/0SOg6stIejjIW8odfcGzOhs5gc9tUVbS8U6xyqpoFgiBp 6Et8HMtqnKfLGVpHrTle5u+nr7FrS50FMyqwb844M4gZueH+JeTLmK0cUrN9ofr5wjG2 FOQAET4hDiLxOot4JW4AWvI1a4g87JH3HoLfASrbpNB/yLZESZHIUNN9DmGUW9uonoGR g+TqNW5UKjf6YfiY17SiVO7UOcJFt5rkJmv/fQ59RZWfDfSgFcVDBDecG4M+oMylkiLq 9SEtyXrP9H0g/qkyA+hde/Tz/X6TETVqD4+7wuwtHOMLGHxwFlua1/TXBhMfwkoPmaKl uXeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-filter; bh=ccdnldXd7ffStD/bkTdf0JjvxcE1PixsU1LgmFGE+AQ=; b=IY3F65/i893R3qjsJsk9K8pIqTgoitoJFQBYabv+TopHXR6vs+j4ikT0r00/M5eDoM Bg5+hxU7DMGsX8PJkOqJ8YFCRogaRL+rBTJi+lW/iK8gS+S2pEIPRzyKHlsjXh4Ea5S6 UV64si8mJ6Cw6sPnHpE1wgq7PG9OVEvACZcJs5bJAXdAlbCfbtIDh0wL9hUTnLzFgGAb C6hDD0u2p70iuxpxxiK5AxEbnDiDMam9UkgExY9fW7IUfmIYHqx+OIugFl18aewfdd1g w2vZXzYtBSAdSvBNXBIpjqwemyM0ZfIAnJiUIX/3QgHrZGEtGNu9xfd/OYQI4Q6J7Jz4 /Ijw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ajqWrUw9; 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 q21si1781640ejz.227.2021.02.03.09.50.08; Wed, 03 Feb 2021 09:50:33 -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=ajqWrUw9; 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 S232149AbhBCRsi (ORCPT + 99 others); Wed, 3 Feb 2021 12:48:38 -0500 Received: from linux.microsoft.com ([13.77.154.182]:53822 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231591AbhBCRsf (ORCPT ); Wed, 3 Feb 2021 12:48:35 -0500 Received: from [192.168.0.104] (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 60A2620B7192; Wed, 3 Feb 2021 09:47:54 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 60A2620B7192 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1612374474; bh=ccdnldXd7ffStD/bkTdf0JjvxcE1PixsU1LgmFGE+AQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ajqWrUw9CR8dAwPmXY6LCKNUEia6bR5EjopHsReroJkEk/G8oj/LNYo6yVlhZHRPT gifIXM2rLnviz18/bU47RYoODn6g6eAz/ehhd+XdLDkL4/Db9ETaET7WsCMd4Jm0IR qbpqJGZRQppoEWCB6hHj8+tqyW4Ca58BYHrUL/GM= Subject: Re: [PATCH 1/2] ima: Free IMA measurement buffer on error To: Thiago Jung Bauermann Cc: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, ebiederm@xmission.com, gregkh@linuxfoundation.org, sashal@kernel.org, tyhicks@linux.microsoft.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20210121173003.18324-1-nramas@linux.microsoft.com> <87eeic1u6b.fsf@manicouagan.localdomain> From: Lakshmi Ramasubramanian Message-ID: <918ff442-2a0d-0e5b-4e95-c47dafc11382@linux.microsoft.com> Date: Wed, 3 Feb 2021 09:47:53 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <87eeic1u6b.fsf@manicouagan.localdomain> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/22/21 2:30 PM, Thiago Jung Bauermann wrote: > > Hi Lakshmi, > > Lakshmi Ramasubramanian writes: > >> 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. In error code paths this memory >> is not freed resulting in memory leak. >> >> Free the memory allocated for the IMA measurement list in >> the error code paths in ima_add_kexec_buffer() function. >> >> Signed-off-by: Lakshmi Ramasubramanian >> Suggested-by: Tyler Hicks >> Fixes: 7b8589cc29e7 ("ima: on soft reboot, save the measurement list") >> --- >> security/integrity/ima/ima_kexec.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c >> index 121de3e04af2..212145008a01 100644 >> --- a/security/integrity/ima/ima_kexec.c >> +++ b/security/integrity/ima/ima_kexec.c >> @@ -119,12 +119,14 @@ void ima_add_kexec_buffer(struct kimage *image) >> ret = kexec_add_buffer(&kbuf); >> if (ret) { >> pr_err("Error passing over kexec measurement buffer.\n"); >> + vfree(kexec_buffer); >> return; >> } > > This is a good catch. Thanks. > >> >> ret = arch_ima_add_kexec_buffer(image, kbuf.mem, kexec_segment_size); >> if (ret) { >> pr_err("Error passing over kexec measurement buffer.\n"); >> + vfree(kexec_buffer); >> return; >> } > > But this would cause problems, because the buffer is still there in the > kimage and would cause kimage_load_segment() to access invalid memory. > > There's no function to undo a kexec_add_buffer() to avoid this problem, > so I'd suggest just accepting the leak in this case. Fortunately, the > current implementations of arch_ima_add_kexec_buffer() are very simple > and cannot fail, so this is a theoretical problem. > Agreed. I'll post a new patch with the above change removed. thanks, -lakshmi