Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp828021imm; Wed, 18 Jul 2018 11:20:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpceS7JD8A/7+Qd36GIjim7WjfC6g0kd4WE1q1kdZjkl9+ezMgXSuTKVW9D6lpTJ2lnHAunm X-Received: by 2002:a63:6b86:: with SMTP id g128-v6mr6925432pgc.344.1531938049478; Wed, 18 Jul 2018 11:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531938049; cv=none; d=google.com; s=arc-20160816; b=yYMBFqIplTTMdzXSml8jlqAXCklJIk4df4mA3zMZbuCsOcpgGzartSpAdtLyVQ+xyZ bi7yMK0Uu4H+Oq27C7n4m+tQGGwXTbDQ00Sn/3IVHp3DOcsydYV+QdUhb2RoHpOaKFs1 8GqqHeMNCT8k5A2Nclx5bTYlyqxKnbUdr8bBJZIz4xY+mZckJKCbMgNP60SQwjeXuB3I uzjiMx8Vv89mYqaLSJHxZVuGR/3lUv8GFfN5PGVVzIZR71zyCD3hwytONhOz7P6tb9GK 2cSXNUvh3HnZlN0PROsMVx7xGPndOfJNtkxulocBHKNH0dSqjSJ/H1Kj1D0wM4PcFq4Y qjrQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature:arc-authentication-results; bh=MSbKYAMIU6EsKJxhvFHArp1Gp/2l4cYJvXqXvd/wmK8=; b=YwGvm8WIiPlLrJZ+GpFU5j7r7Njyg/oNkxwIEJB721Es0Z1ftr41kOqtUEkvZxyMPk ja2USK2KhdWllYsLZDiXiKvCSocpn/Y841iTV7gln7XC4bYeKkxAsyYxyEbqgyq02tFJ Q3BwX7+vgibC6mDwdkMYTf547ITNw3sD2AzU8i2xoBYEM6l6158i+TmAaZvwma00JCUN Wwkq1S1v5IFTTGYVaHoFOaye0/00QuJqcclz4aJ1JXdh+8WpG6BvfqvKlS/9sKHxBDIJ RS4r/ZSVATLvnQSsX4zf/CA3sTSNJ4CM3Dvyly5C2aHXY74Bu93NHBxJz6hdhu2ilcnb mhHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=BvmcBHwH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12-v6si1415273plo.475.2018.07.18.11.20.34; Wed, 18 Jul 2018 11:20:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=BvmcBHwH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729594AbeGRS67 (ORCPT + 99 others); Wed, 18 Jul 2018 14:58:59 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38915 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729215AbeGRS66 (ORCPT ); Wed, 18 Jul 2018 14:58:58 -0400 Received: by mail-pg1-f193.google.com with SMTP id g2-v6so2367027pgs.6 for ; Wed, 18 Jul 2018 11:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=MSbKYAMIU6EsKJxhvFHArp1Gp/2l4cYJvXqXvd/wmK8=; b=BvmcBHwH5x7O0FcrTx54B3mF2OzfVjQhSXkSnlxWBH9KPfBykiqayoyLo0+onpXXbx b2pY3K4dkndaywH6/VCC3tmz9psTkXNvhnMcS44VJu9k9nI7GP9xEyK0dVhIMMOX28FD q8Lp3McqzqHruNE8Y8pvSD0NlMc9jGtcHbYgoIfQCBR78rzM36So2kHly9nCYYbvquC1 niXbFT4Rqv1Yhb5lJx0npT+8b1KKTh2XP6jPqZLu0dGe+cc1AVamag/36sAlQEbwPI+f CuXU2cCAot1BLQZ4kLUxTpgot2FdotbnisvsW+ZSIymyM8jQuZOVitD3CjMyaf8//LRZ P7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=MSbKYAMIU6EsKJxhvFHArp1Gp/2l4cYJvXqXvd/wmK8=; b=lSe8P1KDM4EebRrEVSzxVE6816j809/FBjFITotVsekYDEaXLBJEHOUUiL2cJTSNM+ 6cx9jj8mSAiMnkSVJaq6azRDSbiqWSzBx7kSuHROgdHwtUiTH4Kq1ib0xuzUI9nTfnkn zNZ60X1ZZwl0TkMMDUsJMV1s831Dk3nkmK9h9HafQb7WafrMCUs/kbefpxmTnuHTo9w3 ZPXNQP+uyTTahNi8FERO/60D02Q80HIvnfWwf4GsBN//HJD9o1n1SeilA5wIzRWh0WYs rjdqLXMgOL7Ht06NHODFYSBA9g8QCKaivl9gHWOPoZY1985uYlcn+77blPRk669CqFvr vt2g== X-Gm-Message-State: AOUpUlHor7EW1nrXymxeVewecX815Dsh5l62lv+HtOUO6RhWKxqA5ttm I9lASpf0v2pPiEDy3jhwPpPFVq2t X-Received: by 2002:a63:64c2:: with SMTP id y185-v6mr6745734pgb.126.1531937992801; Wed, 18 Jul 2018 11:19:52 -0700 (PDT) Received: from cakuba.lan (c-73-231-89-118.hsd1.ca.comcast.net. [73.231.89.118]) by smtp.gmail.com with ESMTPSA id s27-v6sm14038964pfk.133.2018.07.18.11.19.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Jul 2018 11:19:52 -0700 (PDT) Date: Wed, 18 Jul 2018 11:19:49 -0700 From: Jakub Kicinski To: Taeung Song Cc: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] tools/bpftool: Fix segfault case regarding 'pin' arguments Message-ID: <20180718111949.325c985b@cakuba.lan> In-Reply-To: <20180718133526.19669-2-treeze.taeung@gmail.com> References: <20180718133526.19669-1-treeze.taeung@gmail.com> <20180718133526.19669-2-treeze.taeung@gmail.com> Organization: Netronome Systems, Ltd. 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 Wed, 18 Jul 2018 22:35:26 +0900, Taeung Song wrote: > Arguments of 'pin' subcommand should be checked > at the very beginning of do_pin_any(). > Otherwise segfault errors can occur when using > 'map pin' or 'prog pin' commands, so fix it. > > # bpftool prog pin id > Segmentation fault > > Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool") > Cc: Jakub Kicinski > Reported-by: Taehee Yoo > Signed-off-by: Taeung Song > --- > tools/bpf/bpftool/common.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c > index 32f9e397a6c0..b1e1ba9e1c90 100644 > --- a/tools/bpf/bpftool/common.c > +++ b/tools/bpf/bpftool/common.c > @@ -217,6 +217,14 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32)) > int err; > int fd; > > + if (argc < 3) { > + p_err("too few arguments, id PROG_ID and FILE path is required"); Thanks for the fix! You can't say PROG_ID here, because this function is also called by bpftool map pin id X. How about s/PROG_ID/ID/ ? > + return -1; > + } else if (argc > 3) { > + p_err("too many arguments"); > + return -1; > + } > + > if (!is_prefix(*argv, "id")) { > p_err("expected 'id' got %s", *argv); > return -1; > @@ -230,9 +238,6 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32)) > } > NEXT_ARG(); > > - if (argc != 1) > - usage(); > - > fd = get_fd_by_id(id); > if (fd < 0) { > p_err("can't get prog by id (%u): %s", id, strerror(errno));