Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1211476imm; Wed, 18 Jul 2018 19:45:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfptChkqxOc9CO8EQM8VEjsw/CbfK6AF47vXrC/6tCYoFEF0cla3C4Ni0UVYErFR/6RmcKa X-Received: by 2002:a65:498c:: with SMTP id r12-v6mr8298462pgs.112.1531968335114; Wed, 18 Jul 2018 19:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531968335; cv=none; d=google.com; s=arc-20160816; b=kIHDh7jneDb5yAO7eBYRs8Z/zdGJHTq3ZRPywlipZqPuq4mKVJEWvowgPAagpviO4F 0AUSAxN4ppvgkqTMjzsLxtIfn8+cbiU3Xdl3OfpqfPrWmtcsWgBN9ZKQJk1RqGbZKeWS 1JPF4c3oqg9RNtSjobk8lscNLibNEnKaWwYV7zCapro9RqwtFV7I7NfbML01KCGz0y0S tV/XnEShDvVfW6WS3GCQNcPwNh19OJHtxk/Hj2SP/YQI8OdksPsZfIEdxC40e+QPVAWU 8+XK5TM6sUGdQoj57zvfuCb5jUZ/YFVXVpSNTzjCnvY4MTqzoQHBsRv4XH6aKITyT0Zg KsSw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=Yl/AJryFflJ8m1IV+vL8IPGmVYTxrlVBVA1WlFqper8=; b=KC2u7tfe7tNh3gP2mSj/0ydV8kptxhlOSOMB9+jATCltezTuSMwPUvsg1YbPNJAsH5 1wqYJ5U01Ozz/kCd3gXJqxr2JijqBaLGvQHMfV4z/qfNRnUHQI6oPfDMEyjlvW372KiY Cr5chKHKsZNEX8RtU472tjY3Yr758cSBPmCU+rGlCtTnT2I1TlqjdpEZPx4/KX15G18j vryrzL61lHgJPzoZN0eit2J98AjWlcz6fyUj161Q1jbPNU4gSox2128vjC7MsRUGAj3k 2Kk/7QxlnB6f/whyvAY3BsXxDuEVu5e7ZqNUQeWore7oZK5UNCqLQuYNYzkRDRuC3sYR gv0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QasZxfbA; 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 k1-v6si4391566pld.40.2018.07.18.19.45.20; Wed, 18 Jul 2018 19:45:35 -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=QasZxfbA; 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 S1731251AbeGSDZR (ORCPT + 99 others); Wed, 18 Jul 2018 23:25:17 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43935 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729209AbeGSDZR (ORCPT ); Wed, 18 Jul 2018 23:25:17 -0400 Received: by mail-pf0-f196.google.com with SMTP id j26-v6so3117426pfi.10; Wed, 18 Jul 2018 19:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Yl/AJryFflJ8m1IV+vL8IPGmVYTxrlVBVA1WlFqper8=; b=QasZxfbAH0jjcU1nla4Zs5q0YJErGSACcjBsRhIxAwS62T1squ/lthPPlEMP3H0uU/ pBU2H5oDgxsim3INg8r7fZOBAptmCnRMHSMRi/p9Dz8K4633Ls5TufmB1CFGWJmbQ8uI eqqx8Yj6pBsDB43Im0X7lJwAPyz7t1CscSouI92HGYR8aWQ/nJKuvFapu2f3Fh6ZirRx c/7LkehL9Amr4Lv6bY6XZ1/mX3sA1F3+upBjj6l86hvatIYogmeeUL3E+YplpuQtqKmc 8KjuR590rRB6I40X4mPp0RaHDkOi/nNaLBZAd1bx2s7tLvDZ6/0B3R04SHFvUrz/mJJ+ LZCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Yl/AJryFflJ8m1IV+vL8IPGmVYTxrlVBVA1WlFqper8=; b=HJOpw5CQUakKLgfbHpU+Rm78u6wx2NtvuqtK5lrdpC+w0+ArxpyPjGzF5oHtTZGSvi 4wntfciQN0IWtMYQRhVCsHz67Er89hlMNUXB4uIILoK6I/UVqIh0cbWPQYOHQ8WOCtKh kXSQaFwTO04nIaI37gUMNjrQFpSumIkzwTvNB604+XTelLw0/LOrL3mH1HOH/XYInC2r ylgqcCMsPj2KdokWcVR0sv6oyynKWJYNiDpiiPNyqlfNBTF+T6Qz+GE+mKPZ2HrAom9g sHgzldut+5ZCtMLoaMzbXxuSIi/Z/uk9y5eS+BaleqKRMDY044Rxo8WLH7yQT6tgzIb9 1U7Q== X-Gm-Message-State: AOUpUlG8jGcJe7EN/HiVLmL8l740a1Jl9L8EE6sPEmLdG+Gx38ML5CaQ JyVvi1I/0QrJWUtVPPJqVqPQ9asz X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr8371077pgv.52.1531968267955; Wed, 18 Jul 2018 19:44:27 -0700 (PDT) Received: from [192.168.0.77] ([211.196.191.92]) by smtp.gmail.com with ESMTPSA id f126-v6sm7525043pgc.88.2018.07.18.19.44.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 19:44:26 -0700 (PDT) Subject: Re: [PATCH 2/2] tools/bpftool: Fix segfault case regarding 'pin' arguments To: Jakub Kicinski Cc: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180718133526.19669-1-treeze.taeung@gmail.com> <20180718133526.19669-2-treeze.taeung@gmail.com> <20180718111949.325c985b@cakuba.lan> From: Taeung Song Message-ID: <3c25319b-0873-721b-7fd0-a828cc683acf@gmail.com> Date: Thu, 19 Jul 2018 11:44:23 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180718111949.325c985b@cakuba.lan> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/19/2018 03:19 AM, Jakub Kicinski wrote: > 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/ ? > Yep! will fix it :) -- Thanks, Taeung >> + 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)); >