Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp852013ybj; Thu, 7 May 2020 09:03:44 -0700 (PDT) X-Google-Smtp-Source: APiQypK6fKhSLdNmezz+p2dy8IdsHjIrZOiorqOsqYqQPb76dy8egf49Yyjjtm20bqg9aStRJ2Bw X-Received: by 2002:a05:6402:712:: with SMTP id w18mr12849268edx.386.1588867423930; Thu, 07 May 2020 09:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588867423; cv=none; d=google.com; s=arc-20160816; b=l+iD5QXOpjPDVFUOZ/zl1anCHYviZiLLC5PaKDZOStkRLM/Eozm+evATaQ5kJ3XnDA vYjabpyWg1gt3/kwS6xBUUmtTXLoRzza7xyaUVuQFCdlckY+8YkHrHQwWZhQfmbyndr+ +51R3dD2gSKspSvlf0Ap9si5i0X1hUtVp/s35ZPBOpPIaM0F5FWZdRBsN36qq8WEzce5 k9uCgHHPFDA9nCOj8sSVnt5ZXeIIFEowJcBmeq+/DY0JO1vRPg1iNUst5nPAojHkGyTn gZ/Wa8hk+/8Jm5cz8pqmae8pJUZ5S8MFTgVOHkNLsz7fr7Tsxzs1Y6SZ0+ZjNKxChzfA B1og== 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=PVh9nVA946hsytwFmqd0SsQ0I/UUDrXTjwnvQizW6Ag=; b=KqHdXNN0hO4BwwdHsmt/kXyW7BGCH4iK6jtL+YSYFK+YOOVqFflh4PSZp3vcvZN+dT 7R4MC6mMMtEzOBBUm0VMO23vN7mz+xtKQJbkaP74w8nycZLAoxl4rA/gnmIzogC/H3Xg IHmDf0QCF3tJ6qDaZtyj5lllQQj+Nn8EwIytEUdGT+lfbkHUZtKYEQ++5szIT+lNjZci iRuXUl666bveR1Pl9Y2rGqFFDySocmZh95jdmN4fn50zVVlivdcW0A9eyxjygqE4KzVR G5rHEp1og846H4CguzO14X2O1QUDme88KwXLvAqpOe/8LsgwO8GowwyweAM5N1XjXmw4 5lVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dbz7rPhI; 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 s15si3321218edr.462.2020.05.07.09.03.16; Thu, 07 May 2020 09:03:43 -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=Dbz7rPhI; 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 S1727799AbgEGP6J (ORCPT + 99 others); Thu, 7 May 2020 11:58:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:47422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbgEGP6J (ORCPT ); Thu, 7 May 2020 11:58:09 -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 3D44A20659; Thu, 7 May 2020 15:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588867089; bh=NITQjEgRSoBKX5wE3WldFfda5i/NM+D9hwjjZEqYonk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Dbz7rPhILm+FqlSj6+mj6XquWajcLLt5/vfSaMpMTmc1ff/m+frJQnWwlt9/Joulk K2Ai1Z8ndhpLL3MYb6Rlz0JBjUDVVof33WPJUKGTJITfqYXj3kpIfmEsBDe8i3ircG hit2Ez3+NpF2xt8D7jP6jPuO4ItpSIVyoe8dVFsg= Date: Fri, 8 May 2020 00:58:05 +0900 From: Masami Hiramatsu To: Steven Rostedt Cc: Yunfeng Ye , , , , Masami Hiramatsu Subject: Re: [PATCH] tools/bootconfig: fix resource leak in apply_xbc() Message-Id: <20200508005805.9ae13059958e36ce9ebdd5aa@kernel.org> In-Reply-To: <20200508005647.dc6f79c0aeca041203af1d8d@kernel.org> References: <583a49c9-c27a-931d-e6c2-6f63a4b18bea@huawei.com> <20200508005647.dc6f79c0aeca041203af1d8d@kernel.org> 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 Fri, 8 May 2020 00:56:47 +0900 Masami Hiramatsu wrote: > 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 > Hi Steve, can you pick this up? Thank you, > > > > 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 -- Masami Hiramatsu