Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp538484imm; Wed, 18 Jul 2018 06:37:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe2DEKM8eDxGr55lOw9Vi9ro3beBatarjadcHF5uaOKPHYEMqoW1KDZJ3S2FylZ54cVhse+ X-Received: by 2002:a17:902:26c:: with SMTP id 99-v6mr5844992plc.341.1531921058127; Wed, 18 Jul 2018 06:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531921058; cv=none; d=google.com; s=arc-20160816; b=FFEiPPeeJTMm8QdFEFjV97AD01OuOOfu+KQ5z7Czh05+UQNN5K9Qzyq6JltR7gNEGB +VSyyUm+EL7O1Q3REEmGNiZhVBMJ19p9PehqCYJVlMG0AKYJnk7lGnu5BbsSd0flkZC/ 1KHQCTkIjlRkRQ8bb7u+qKt+sS9yuTsvFNpfh8ny6OpFsnLK1mtxjnCqno66iOf5hwmQ 9V6nq0oRnT0P5oC05Hrvq9FtaQG7IJqX6ZPMZlUczJFQMN4U/PJBxA8SE1KQZWznngEf AkcM/Bg9WgcxbUzOm1fc0qws75mwyt/gtAuunch0UGfweaSflEVTnp6ojJfVeCYyCsVe 2YZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Q/vKiI+Uaarkqq+CU6r4VtkCm6YsK5C5NdCa4R57fmg=; b=QixUXmKrnA2QfqgFacqEZDnVVkM0Pbg/9xcYQQMcOdt6dF2U1NbdLuRKx0w20emBEP B9M6Y8XqiGPaJgMD2pABVRkZ07nBhfGPDAs3+pFa2Q7tQDP1RrI79Uslt1vh9WCm3rr3 m5qC0hHxNd6EJ2botZHp4bjOQGCOrH6l8KwBziY42WQMWMNOgJw+nTAez5kTbkTHrFnV WzaNmknj5Cg3WxxoF2FPdkAHQB+QJvT9/4fqAa7iVZqX/KSANBnP/H/Lq8c6bEXa/pjV VAmdouDF+W8gg8xdCExa2WQ0F99h67+JZYjicrBMGjxp0+UQUiyMTfHJYm4mmAKADKdz lT5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BgRLfT4V; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7-v6si3407820pgn.194.2018.07.18.06.37.13; Wed, 18 Jul 2018 06:37:38 -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=@gmail.com header.s=20161025 header.b=BgRLfT4V; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731442AbeGRONs (ORCPT + 99 others); Wed, 18 Jul 2018 10:13:48 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:42199 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730831AbeGRONr (ORCPT ); Wed, 18 Jul 2018 10:13:47 -0400 Received: by mail-pf0-f196.google.com with SMTP id l9-v6so2219915pff.9; Wed, 18 Jul 2018 06:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q/vKiI+Uaarkqq+CU6r4VtkCm6YsK5C5NdCa4R57fmg=; b=BgRLfT4V7bTMQm4XljYeJ8a0nl86whKQgVfNfcW2zofesP7ty7y8Cu/k4BS8+ElDjZ 0ObeJ/sE6PVjbw/sfN/XK6tE2+PR7yNoZumpHLdOSQifFoVOmmTW9Mu2D6g3H9fyfinZ 8KIzj09XOGJnXvTwpzhXNMdWteXnQXlwbn4baF4lpN2LecH1OpzSCIoNVK2qilQHLwGw mCvIAovQIYvKsUbNkz4WA1PbnckfPZIIhe5Xk4aZb3kC1l7AyMtXz3AsE6qxy1zKTEGY I8xVMFgWW/LX/lPOCmx/rvJe905kQOFKLoyIXnoelWD4Gqf1+U17SgL6vIKdrj+S9u+K WCYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q/vKiI+Uaarkqq+CU6r4VtkCm6YsK5C5NdCa4R57fmg=; b=WaJlVM5i20GbQhJ+ubcWOqwn36GYJr9ADnuOgb0eQ1ldXfMrOqN1YyIhd5FBJTsHbY RKspAP/7kfUXfARgyKEdhLzY0t3CeRpzvIOTjx/ovpyxPyYka/Tk95d+x7gSDymFovwa hVRrQuT7at7vAdg84Ul04P4maTGJlOYH8GOqw5+R1KvvcTZYhLycCaG5m5YN6CmUV4SS YphTojoAtAjPd6eAm2xQ6WprIZKHvt6Lez5347Pe1Ad/sD3mT+ZAzRKSjtItYy+TwLW7 6bJQspNKlYLPApt3F8grGc7eUvCCp0PpZmgTYZh+hLs/OGspVeB7/U2oWY5EMs6kLaF8 RoCg== X-Gm-Message-State: AOUpUlGAKfGQ1u/qU/aFqE8QMveuDwBAa2OwOqUlMLZrvDMa8PF4sgBM IhcfpzOamMy3+qqebegDhrE= X-Received: by 2002:a63:a011:: with SMTP id r17-v6mr5623929pge.90.1531920949560; Wed, 18 Jul 2018 06:35:49 -0700 (PDT) Received: from localhost.localdomain ([211.196.191.92]) by smtp.gmail.com with ESMTPSA id z11-v6sm9217203pff.162.2018.07.18.06.35.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 06:35:48 -0700 (PDT) From: Taeung Song To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH 2/2] tools/bpftool: Fix segfault case regarding 'pin' arguments Date: Wed, 18 Jul 2018 22:35:26 +0900 Message-Id: <20180718133526.19669-2-treeze.taeung@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180718133526.19669-1-treeze.taeung@gmail.com> References: <20180718133526.19669-1-treeze.taeung@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); + 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)); -- 2.17.1