Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3139471imu; Fri, 18 Jan 2019 05:33:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN7LIlUWy9mggqkC6FsDp0X0S9f0cJs0YDC1CcDKP4KL9vTocW9VJQgTWjMqJTMt5nkANqx2 X-Received: by 2002:a17:902:145:: with SMTP id 63mr19150653plb.256.1547818383802; Fri, 18 Jan 2019 05:33:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547818383; cv=none; d=google.com; s=arc-20160816; b=n+oUQLeg/bnxdkWimU+XlI4pzxksNi77Z7ipHXFy5vMa9o7Nn96g3IE6Vi4uApQnVR UayOm0ShkaHtDZIPRu2hwywcoDdjpFmePIgSyQ54m+v/9+FIF5y2nllHWefjXcHYeaYC Zk+1WzJASWgtRHTnWZ8QeEgckoAM4JNWNdG+yA/MGjkWart6JQDsGgYayCOjgRVRs0CO M0fTr9ShgGalM/eVAB20AuUVW5arpWT9FQDP+gNNtob4G2W21DeXWSikhSQPDVce7OxK as+A7nhXUGX6ak0SrKHNMS1xeROf622FVjRnFgZaWOHAvuNDveQowaXPPeYymIz/qqxo FDlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=YrJ7pqhdJGIK0vlsCLdfaGZLzs9qSf+C+FU7n6C0auQ=; b=bwDMBKhicar745OjvTycVBF2/n7qN3m8SMZgib202v8M6WsAfOVCKZiLvonD0zZuIp JYY5nWcrGNKjw6T+/SILJ/aCXp98i7isZiLNRuEJ7HSaigDRBY2JiyRJSpzOA0uLPSLq m7TfPo4H3ScCRzoUQhvySvnC0bfdHDZcCRLcthQ48uH94Ax8Cn5q2hfUDgaAIpowbx/6 WL8BcjlWRjnFv2v/0TSDEL7h/Oki2zoig+x9p9TeNAcHPNSP3dolWNuJy4GuZ9gldVWf tkqtlkW3mxsKA2QtZzx9rJBNWF5bRKvKNBfqTg/AOQrN/uAmWocxByLvPgytftHKJmxr gg3w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 126si4620680pff.77.2019.01.18.05.32.45; Fri, 18 Jan 2019 05:33:03 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbfARM6V (ORCPT + 99 others); Fri, 18 Jan 2019 07:58:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46542 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbfARM6V (ORCPT ); Fri, 18 Jan 2019 07:58:21 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51F9C2CD7EB; Fri, 18 Jan 2019 12:58:20 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.205.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8C519741; Fri, 18 Jan 2019 12:58:18 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: lkml , netdev@vger.kernel.org, Lance Digby Subject: [PATCH] bpftool: Fix prog dump by tag Date: Fri, 18 Jan 2019 13:58:17 +0100 Message-Id: <20190118125817.10763-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Jan 2019 12:58:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Lance reported an issue with bpftool not being able to dump program if there are more programs loaded and you want to dump any but the first program, like: # bpftool prog 28: kprobe name trace_req_start tag 1dfc28ba8b3dd597 gpl loaded_at 2019-01-18T17:02:40+1100 uid 0 xlated 112B jited 109B memlock 4096B map_ids 13 29: kprobe name trace_req_compl tag 5b6a5ecc6030a683 gpl loaded_at 2019-01-18T17:02:40+1100 uid 0 xlated 928B jited 575B memlock 4096B map_ids 13,14 # bpftool prog dum jited tag 1dfc28ba8b3dd597 0: push %rbp 1: mov %rsp,%rbp ... # bpftool prog dum jited tag 5b6a5ecc6030a683 Error: can't get prog info (29): Bad address The problem is in the prog_fd_by_tag function not cleaning the struct bpf_prog_info before another request, so the previous program length is still in there and kernel assumes it needs to dump the program, which fails because there's no user pointer set. Moving the struct bpf_prog_info declaration into the loop, so it gets cleaned before each query. Reported-by: Lance Digby Signed-off-by: Jiri Olsa --- tools/bpf/bpftool/prog.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 2d1bb7d6ff51..b54ed82b9589 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -78,13 +78,14 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size) static int prog_fd_by_tag(unsigned char *tag) { - struct bpf_prog_info info = {}; - __u32 len = sizeof(info); unsigned int id = 0; int err; int fd; while (true) { + struct bpf_prog_info info = {}; + __u32 len = sizeof(info); + err = bpf_prog_get_next_id(id, &id); if (err) { p_err("%s", strerror(errno)); -- 2.17.2