Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4431pxb; Wed, 11 Nov 2020 17:51:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxm8+2j6zG3eLsJFfG7g81xJlYw3djEnJUcPgGZyNYlunPHrcwobJBm7ZAHXlV9fONLu/AC X-Received: by 2002:a17:906:82c4:: with SMTP id a4mr26565511ejy.131.1605145895940; Wed, 11 Nov 2020 17:51:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605145895; cv=none; d=google.com; s=arc-20160816; b=YNGzoM8oVcNu44myfWTwgAd1ew+Ke5we4TX9As5O8NOy+GbdGw7neV7ZSoM5xMpv9D sQEvXf3B6kb0tHXvTWKi8HNrQ/6bDtK+QHS1Wx1eGQHdppKC+/ianWV0bwbFSiHguH2x tseqM1DANxOeW8LGOahibgJq74jYcEYJEb0KgNKHbIt8JYUPKys4GQnwNTmmNkasM5xU 2cxc/KzlTrfLpi4RjC/PMYC01wVF0Hs8V8o5VSbC0RmgbuCyq7UUn8Aryv7lglyLAa0T U2CRZ6w4Ud9BfFCYdTjBTwnYlbri49VMufdDiJrFiIxa1V5BrivyGcjClqrqYx6STl1i uIdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=N5VYtEHc8PJh6B9Pxwlx+Xskau4NMSgJa2pe+N/+0hQ=; b=phihMdhCLlfrtom8AwQ79mTfNE++7Tnc6VF/uONeAwCdhUvo1EhflCNjHyEw4Sou9J i6nVtoFbWBeOXeYlx2XvbGPLMJNb/RAeI/kRcgPocP9Nvgnyd2Q6F17KH14E00SAwv2k VhZ/7U/NJanO3MqpsgzJ09LGi9R4JXHEv+qpq4eC7Xsv2Qlk8p2lT3h0z9iz75AF8CnE kXjoqMj1Vojim8kup4bq5g8hWdFxTLd+0P1RQKgOw1L/0I0l38PCBYm1ZnVgXAVQYSXK bEAs5tG6MgbSQ8qg0uF0KrlcZ+9WNpgIWqGzCwXP3bO++Zg4jBrhtti/HY8xAV6XRebn 0AxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mIC6jicw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si2943333edi.348.2020.11.11.17.51.12; Wed, 11 Nov 2020 17:51:35 -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=@gmail.com header.s=20161025 header.b=mIC6jicw; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728461AbgKLBcj (ORCPT + 99 others); Wed, 11 Nov 2020 20:32:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727194AbgKKWqp (ORCPT ); Wed, 11 Nov 2020 17:46:45 -0500 Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14B2CC040208; Wed, 11 Nov 2020 14:37:53 -0800 (PST) Received: by mail-yb1-xb44.google.com with SMTP id o71so3116040ybc.2; Wed, 11 Nov 2020 14:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=N5VYtEHc8PJh6B9Pxwlx+Xskau4NMSgJa2pe+N/+0hQ=; b=mIC6jicwNMDMYFiuiMuBACCgPbD4hSINY8bHnJF3OU19jk/QMCYS7pM4BqBYavjA0W pHxyF+5JWJ8hwLLq8P+ss5fOJeI9XR3Ao4i+1Qehu4nmX3b2R4SR6OlZatgHcBT+Z1MD gAhYz1nodwBBFDlSTR5wkXAbX3s2h30wOkMt0Nl3Gx5gN0WuFqgPKmdajV5Fqp5EkdKL DbkVkXX2DJ82y3plY4hdjt4ShFcoj1g7LOgV7GjgWklZ0FHTLCtzaDaFqkMlvVsFwSKF Cam5QJUDpkf0ccxOJVmYz5OL0RQ4cnwrBEG8pgOLj+kmKXOEy1qW9ZMcrkguIMBBkY95 YbjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=N5VYtEHc8PJh6B9Pxwlx+Xskau4NMSgJa2pe+N/+0hQ=; b=WgQ+XSsYE2loy5eJGekzcKizIxnNM0HHKr9TlsT4HbEGtLLMPhFLh8FtVSVSNx2/cu 3QbVq5XwDGglodZVtn27r5EVXlOPtEFvhkwMEsk+sQ6POun/tuZUwSqFcGi6KKgThoPo HbyEkFD4gGCXZUgCRM3JXcDpwi0SVDt1qS5ZGGcR2M43uGr91HSwfeRXvOOPtZyMkrwH 9NHmUZFdxOLGAcrm91VlWaJig9NCSuLZ7ZcEV0Z+8QscmTZ/eSCzL028Wez30jByJIM6 04uJx/HX6e/5ax/I2bApE1kDm5afAmqvaAl/F1eUx3Mcz82Jg1cPNwUr51NQcTKcL7kA PVLA== X-Gm-Message-State: AOAM533FnOHm0GxSX+6EvwB6TYOdna3KBFNimIEFubyJzQLcuJEOZbJ4 0XItsjKKwKx9LrLoEJl2fQuc6oLRUI1z3N9lXgk= X-Received: by 2002:a25:e701:: with SMTP id e1mr12067008ybh.510.1605134272385; Wed, 11 Nov 2020 14:37:52 -0800 (PST) MIME-Version: 1.0 References: <20201111135425.56533-1-wanghai38@huawei.com> <6a589c0b-e2fb-5766-542b-62f40b16253a@iogearbox.net> In-Reply-To: <6a589c0b-e2fb-5766-542b-62f40b16253a@iogearbox.net> From: Andrii Nakryiko Date: Wed, 11 Nov 2020 14:37:41 -0800 Message-ID: Subject: Re: [PATCH v3 bpf] tools: bpftool: Add missing close before bpftool net attach exit To: Daniel Borkmann Cc: Wang Hai , john fastabend , Quentin Monnet , Michal Rostecki , Alexei Starovoitov , Martin Lau , Song Liu , Yonghong Song , Andrii Nakryiko , KP Singh , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , "Daniel T. Lee" , bpf , Networking , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 11, 2020 at 1:24 PM Daniel Borkmann wrote: > > On 11/11/20 2:54 PM, Wang Hai wrote: > > progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, > > it should be closed. > > > > Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface") > > Signed-off-by: Wang Hai > > --- > > v2->v3: add 'err = 0' before successful return > > v1->v2: use cleanup tag instead of repeated closes > > tools/bpf/bpftool/net.c | 18 +++++++++++------- > > 1 file changed, 11 insertions(+), 7 deletions(-) > > > > diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c > > index 910e7bac6e9e..f927392271cc 100644 > > --- a/tools/bpf/bpftool/net.c > > +++ b/tools/bpf/bpftool/net.c > > @@ -578,8 +578,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) { > > @@ -587,8 +587,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; > > } > > } > > > > @@ -597,16 +597,20 @@ static int do_attach(int argc, char **argv) > > 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; > > + err = 0; > > Why is the 'err = 0' still needed here given we test for err != 0 earlier? > Would just remove it, otherwise looks good. This patch was already applied. Wang, can you please follow up with another patch to address Daniel's feedback? > > > +cleanup: > > + close(progfd); > > + return err; > > } > > > > static int do_detach(int argc, char **argv) > > >