Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1465950pxu; Thu, 17 Dec 2020 10:33:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRnQU4MW387P9rljZLy7Qm968zvKUNb9SDnC2iv7i9DluM7/qKNPCUJhn2KuBYu80vWopF X-Received: by 2002:a17:906:d784:: with SMTP id pj4mr328356ejb.360.1608229996659; Thu, 17 Dec 2020 10:33:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608229996; cv=none; d=google.com; s=arc-20160816; b=SboUDpGaeWFh5KKuM6jThK+HKoNQ5BJvCj9NxinsqumOYHezeVOEsIQ4iNbAvSicy0 53i7rP60E1Uecr2lpoDV1cxJlyBPEIvqbsnQQlsqhmcfW5TzjjZxUYEmS9Wb/kFIz4OO GUb8oU38q0rm7pSaJyZkaU0g1L29zemXvmz2WITjq0GbisUMPSo58G85O2OGV29JwF+U hu16W9x7Rd6dJ1A44CLtvXoyEJB35cBekDWfcsdeZr4u6qmS00cBZUne1/G991v06fUA mTpzRV+RDHAGYydTg6U/jHlA5fyJp3PrHHeF8gM/KyiDCu2vmJsY9+327YoewjBRFEWI 0Ptw== 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:references:cc :to:from:subject:dkim-signature:dkim-filter; bh=MGlSEbnnlqPYIh5vvkUAJ9wW9ncNIo/aKpPc5ykNpWA=; b=jdCer4/+fRp9HGIde/ldUDGGThpyR8uKuLCJQRdyFeVl4yR/VnR33sEk6KNIw762f2 vf0JuwNzD9+FZq7RdVGoeLcy1FyeYglUHrFrnxeRrorI5wD4w+zdrYmQ+6tDO0N2up82 W6Sc4tWfxBijGfpZN9hmDw7b4/1yOJWU0co/wDlS0cLH0Nz5MMUipZP4cjvDJVVbKeHu HjpVSys6of4OL7jmDchYNXN2fN6+D+d8n3lQoqVjL65WHjnrKdqop8GrTsWFajDxxzys CnReowPmkb9Wv1nNLqVd+rGsQ2q9jwQiPXDSDtmhgXjAl5uNSQeju+m8wh8uptFauPXY uPgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="MBs0E0/6"; 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 qq23si2780043ejb.232.2020.12.17.10.32.54; Thu, 17 Dec 2020 10:33:16 -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="MBs0E0/6"; 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 S1731455AbgLQSbL (ORCPT + 99 others); Thu, 17 Dec 2020 13:31:11 -0500 Received: from linux.microsoft.com ([13.77.154.182]:58646 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727063AbgLQSbL (ORCPT ); Thu, 17 Dec 2020 13:31:11 -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 EDEFB20B717A; Thu, 17 Dec 2020 10:30:29 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EDEFB20B717A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1608229830; bh=MGlSEbnnlqPYIh5vvkUAJ9wW9ncNIo/aKpPc5ykNpWA=; h=Subject:From:To:Cc:References:Date:In-Reply-To:From; b=MBs0E0/64gfpXXWMig+JHbYgTQl0GVsOSxSIdumb+USW3RMdDr84Beh9aeCAMpKPq K5HBuk5POcskxq0qZGZ5WCP4UsaJvIRMaDIX6IOGHpr7kRfA7oyHbxSm2BWWrolczs 6faFUqmqpBy8Uy6I1wMgOSKbSN2OH8ySkSZiw0p8= Subject: Re: [PATCH v12 3/4] arm64: Free DTB buffer if fdt_open_into() fails From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, prsriva@linux.microsoft.com, balajib@linux.microsoft.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org References: <20201217173708.6940-1-nramas@linux.microsoft.com> <20201217173708.6940-4-nramas@linux.microsoft.com> Message-ID: <50e52d9b-db37-f95b-7056-d90476475fd9@linux.microsoft.com> Date: Thu, 17 Dec 2020 10:30:29 -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: <20201217173708.6940-4-nramas@linux.microsoft.com> 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 12/17/20 9:37 AM, Lakshmi Ramasubramanian wrote: > create_dtb() function allocates memory for the device tree blob (DTB) > and calls fdt_open_into(). If this call fails the memory allocated > for the DTB is not freed before returning from create_dtb() thereby > leaking memory. Typo in the email address of James Morse (ARM.com). Sorry about that. Adding the correct email address. -lakshmi > > Call vfree() to free the memory allocated for the DTB if fdt_open_into() > fails. > > Signed-off-by: Lakshmi Ramasubramanian > --- > arch/arm64/kernel/machine_kexec_file.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c > index 7de9c47dee7c..3e045cd62451 100644 > --- a/arch/arm64/kernel/machine_kexec_file.c > +++ b/arch/arm64/kernel/machine_kexec_file.c > @@ -65,8 +65,10 @@ static int create_dtb(struct kimage *image, > > /* duplicate a device tree blob */ > ret = fdt_open_into(initial_boot_params, buf, buf_size); > - if (ret) > + if (ret) { > + vfree(buf); > return -EINVAL; > + } > > ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr, > initrd_len, cmdline); >