Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp848130ybj; Thu, 7 May 2020 08:59:05 -0700 (PDT) X-Google-Smtp-Source: APiQypJ/xpeVBa1j7HAAkZiTLmMDLhD1n7paivTdXu2ivz2ZX2iHkV+L5Gm15HcuZLaVQyTn7WOD X-Received: by 2002:aa7:d408:: with SMTP id z8mr12693611edq.83.1588867145532; Thu, 07 May 2020 08:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588867145; cv=none; d=google.com; s=arc-20160816; b=bPc7UK+pRKidPVWhHXqU7MdXProbyzDq13KkyzgCfiD3VpXuy/+FHRUomMfg5K/XWw ZjbVeZk/UaznAxPoTrZf9xgRVAXVvnSt9qaViFY2CuFFrongYa5M3VpRWUm+xe/pc0kB 8uXUNjz2FUiTp+cEj2w5KC9QiicQjrr+7vCFV1U3W4M2UcfWkDnfYhfkXgkaAXS+ZwVW UFXWVmc08NvY3MbBhuUqd0FZhnfKzBpWhApwth+9Qc6Zer3rbsviaJR32NGoi7of4N1m u29E6EJxEUr+JNoWpVUgVamj3ItC5Jubf0nWFz+mT5bafEPfyQCo0EDgJsIHILfF1fPz wDow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=D9MgU53JTVJ5DQNWqoNFjADKdzjFyXhUgnZYP0wHW+E=; b=pKE37QSm383lw0QvcNjyaL7MPhRMniYi5PpTqmluI9b5+/wLoMlbhxA8EvWNhEwzAl lpQZZTaVYDPcWdg12xfjXv/k1HExd2W5/Gd/xEIRx6TkNkeL7EbVKvx6pnCBEjDXEtcl QHtpZRXWDTkRxiPpDuidvVN0ITa87YMI7P0OxiLXjJXOQFYlFCPME+OHxHbaZ/G7+mjw iCbcwfdHvCUrsr6apWWvQEgFT8twVyRX7+VVrqBCb0v2FY/tWjq5/3h1INv2DmBn/g9P fNW4+y8Sxb7a9Ecz27ItOZm/5+6TqLdiWh7X6A6CX+H7LZ/DeZcD5jTY4D8vAw+HSBb6 g6rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dppe2oZS; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si3490447ejh.256.2020.05.07.08.58.40; Thu, 07 May 2020 08:59:05 -0700 (PDT) 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=@kernel.org header.s=default header.b=Dppe2oZS; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727975AbgEGP4x (ORCPT + 99 others); Thu, 7 May 2020 11:56:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:45162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726742AbgEGP4v (ORCPT ); Thu, 7 May 2020 11:56:51 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FEA120659; Thu, 7 May 2020 15:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588867011; bh=+sTRjNnWHwB8S8eiOkQh8qJCetN9mW6k4KevGbYDMoU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Dppe2oZSUKtcMFJAMh2EKp3ioe6doznduRkGVyPvBPwURvnMEoiewHO6W8ZXyTh+j TBKeadECx07JInOjUiLDyUeIWbXKIyhKxEOH+jPwogSFcVCCj3r0r2H5ZB0YVE0fpL RsbbSVcLuF8rhTk0UTgW1RyvcZ0ZDBOPlN+dfPN4= Date: Fri, 8 May 2020 00:56:47 +0900 From: Masami Hiramatsu To: Yunfeng Ye , Steven Rostedt Cc: , , Subject: Re: [PATCH] tools/bootconfig: fix resource leak in apply_xbc() Message-Id: <20200508005647.dc6f79c0aeca041203af1d8d@kernel.org> In-Reply-To: <583a49c9-c27a-931d-e6c2-6f63a4b18bea@huawei.com> References: <583a49c9-c27a-931d-e6c2-6f63a4b18bea@huawei.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 May 2020 17:23:36 +0800 Yunfeng Ye wrote: > The @data and @fd is leak in the error path of apply_xbc(), so this > patch fix it. Good catch! Thanks for fixing! Acked-by: Masami Hiramatsu > > Signed-off-by: Yunfeng Ye > --- > tools/bootconfig/main.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c > index 16b9a420e6fd..001076c51712 100644 > --- a/tools/bootconfig/main.c > +++ b/tools/bootconfig/main.c > @@ -314,6 +314,7 @@ int apply_xbc(const char *path, const char *xbc_path) > ret = delete_xbc(path); > if (ret < 0) { > pr_err("Failed to delete previous boot config: %d\n", ret); > + free(data); > return ret; > } > > @@ -321,24 +322,26 @@ int apply_xbc(const char *path, const char *xbc_path) > fd = open(path, O_RDWR | O_APPEND); > if (fd < 0) { > pr_err("Failed to open %s: %d\n", path, fd); > + free(data); > return fd; > } > /* TODO: Ensure the @path is initramfs/initrd image */ > ret = write(fd, data, size + 8); > if (ret < 0) { > pr_err("Failed to apply a boot config: %d\n", ret); > - return ret; > + goto out; > } > /* Write a magic word of the bootconfig */ > ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN); > if (ret < 0) { > pr_err("Failed to apply a boot config magic: %d\n", ret); > - return ret; > + goto out; > } > +out: > close(fd); > free(data); > > - return 0; > + return ret; > } > > int usage(void) > -- > 1.8.3.1 > -- Masami Hiramatsu