Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp831290pxu; Mon, 23 Nov 2020 05:25:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtdurr1Sx4GtavXwQcMDq2LZiXqLTwoxeJT72Wx9Rvpynf4B2tKCGBA4nmEWuGhvq6Ry+3 X-Received: by 2002:a05:6402:144b:: with SMTP id d11mr47854316edx.195.1606137909735; Mon, 23 Nov 2020 05:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606137909; cv=none; d=google.com; s=arc-20160816; b=fYgij30KbarYKueNEix/UdTdD5vLhE09uQlB9wB2VUNH9YTJvsWhFgpwJ4gNVF2XP3 9YmHV2IewbaLj0Q/oWN0OfFRrC7GnkH3xzJD7AkSq4VXLQ1LFjCNIg+MZ9AfGvVMsumM HyeHgoNK340DEdIdKTUZ+5FVz4ec301bKyLdX2Dassn0IgFGE/UybyRbqHqAd7hvadYc MxHpoThNqW0LlHQPLBCTYR+chM8affvFYZA/24Dll37z7xjFBuWucSnSrClxe/cfXrRu Fy+DOb28cOve6B8OIshzhzOdpDbhk9XwXuRN4PrZIUrwwfdtTbyjer5cK4MiHAI+5irZ 2DAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XcZZ7u/NjGZ/ZaAVHLsVpVCYzZe65MrUrZCIRh4YdnE=; b=w4BfxRYy+NLxVbwpfZWG4XO11UX0aFbKH2KiMX9B3nrKUtaNpTZcdQC606+aNOY5rj w3SKz8IytXA2c4e/pv9X4+dt40+mF66zyc+vx4/L2iUlHeqKjsxfX10EUbYXGCRKVtwY ws39Wj4SUq75O1yacFZWlXeAv78mR6UhwnLWbF11b2PbOiJgGqazDKTIiByc110I4apG o1ksHltf92I+3xLCPn60NbbMrlrTefW6ojg337JyWfcpVK93y5FQvMuBvXq0GQddlMTf e61/AH1Fe1RPl9WMBLm9T0qWn++TeFH87CPRhijrnO1HitjnjhTeCF2kUoE4jqvmFMIk Zhpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=isgLhMp2; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si6539445ejz.363.2020.11.23.05.24.46; Mon, 23 Nov 2020 05:25:09 -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=@linuxfoundation.org header.s=korg header.b=isgLhMp2; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388828AbgKWNWS (ORCPT + 99 others); Mon, 23 Nov 2020 08:22:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:49074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731825AbgKWMgw (ORCPT ); Mon, 23 Nov 2020 07:36:52 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 843D72065E; Mon, 23 Nov 2020 12:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135012; bh=zRbcK81dP3lykh7Lie0sKi3uPFLovLliutkdOcjLtpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=isgLhMp2RCOYxX0PJd+AB9viDQ7BFe4usTDN+ueRCYyebCQIiiDxSVrc8Jf7utC14 DuPXOsaK0vXWvpNlQquSDNm/RxFAlJ7qP1pjiJBjGpmjGtPJTFW20JVQijEcmtaofx h/WW7GHgvuzR+rXXglvf+gaDvRj/YcHrfLWogmN8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wang Hai , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.4 073/158] tools, bpftool: Add missing close before bpftool net attach exit Date: Mon, 23 Nov 2020 13:21:41 +0100 Message-Id: <20201123121823.460500486@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wang Hai [ Upstream commit 50431b45685b600fc2851a3f2b53e24643efe6d3 ] progfd is created by prog_parse_fd() in do_attach() and before the latter returns in case of success, the file descriptor should be closed. Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface") Signed-off-by: Wang Hai Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20201113115152.53178-1-wanghai38@huawei.com Signed-off-by: Sasha Levin --- tools/bpf/bpftool/net.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 4f52d31516166..bb311ccc6c487 100644 --- a/tools/bpf/bpftool/net.c +++ b/tools/bpf/bpftool/net.c @@ -312,8 +312,8 @@ static int do_attach(int argc, char **argv) ifindex = net_parse_dev(&argc, &argv); if (ifindex < 1) { - close(progfd); - return -EINVAL; + err = -EINVAL; + goto cleanup; } if (argc) { @@ -321,8 +321,8 @@ static int do_attach(int argc, char **argv) overwrite = true; } else { p_err("expected 'overwrite', got: '%s'?", *argv); - close(progfd); - return -EINVAL; + err = -EINVAL; + goto cleanup; } } @@ -330,17 +330,17 @@ static int do_attach(int argc, char **argv) if (is_prefix("xdp", attach_type_strings[attach_type])) err = do_attach_detach_xdp(progfd, attach_type, ifindex, overwrite); - - if (err < 0) { + if (err) { p_err("interface %s attach failed: %s", attach_type_strings[attach_type], strerror(-err)); - return err; + goto cleanup; } if (json_output) jsonw_null(json_wtr); - - return 0; +cleanup: + close(progfd); + return err; } static int do_detach(int argc, char **argv) -- 2.27.0