Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2695534ybl; Thu, 29 Aug 2019 11:35:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxc2F9FaMfQKwMTdUTzQweaAcZ07Qfwhhn/+Q8Ary5IAhR2q+0CWJS0EPgFOmVOEubL7N0m X-Received: by 2002:a17:902:a01:: with SMTP id 1mr11719476plo.278.1567103730199; Thu, 29 Aug 2019 11:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103730; cv=none; d=google.com; s=arc-20160816; b=hB/XINic5GacY7NzXd1THpxQnsHze/eT7Z24Uic0eO91L8uusb3rIUbgeKPhIptxKU FaTEEpeE+XrqTENqV4Noc86K2xl/wYcWHYlsrqBN7Po+z4vc152nBOrpXjL18FCPI2lz Hfk7L6s4vmp3kAPObPplsjkov+OxzkydGAJcCXMBCljgi+jmwFbQhTjtZY5amtgjq7sh mRfz9E1gKsNUBi/d8NeCfynTMYEnZwlL40FBhpiMGqY4oCrldxk0/hgABpuvrCiyAlhV vH+g/C+/Q+K5S9JP//sRQj2vghgFg3RgPId9COESA3zOpG3L75Gq/B6cc/9a8Ul60Y2b 3M2g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ddew/oRJLqQtlpggWn8gAaHoWOsuY57UDEs7EEQ5vPk=; b=EVsvdmKg+2Vwx8kzi2qem8FYY+3Tp4bzwP/QddlIq5buuMd9LGweAbhBnpTx271wCL hJijd4FXDyeeuNvH/jf3jY4TQhw7X9121cUhIRaTkp0AjhUK4D9vetyr0I58oYuQ/ASg dyrB/FSwYXrSGtz5lSUY3PukLsIHWSu1VHkO7WHTpfHogRq0qzBxA63HpX8p2+MuNSg1 NB5WY+WZUdeoVHtSC+DXClxaY/rNx+2f/mUhPiI0Yycdi+KYUwBUMKuPf0VKQj99+dH/ 0iuHF7dHwsQQYYQ63QsRE4YxbDib3AreaqK1LEmW77iXlwRID0AZVJEiIHCe2MECzYBb DrjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qtxi24um; 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=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 g10si1841588plo.203.2019.08.29.11.35.14; Thu, 29 Aug 2019 11:35:30 -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=@kernel.org header.s=default header.b=Qtxi24um; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728148AbfH2SNV (ORCPT + 99 others); Thu, 29 Aug 2019 14:13:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:55070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727087AbfH2SNR (ORCPT ); Thu, 29 Aug 2019 14:13:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67AC12189D; Thu, 29 Aug 2019 18:13:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102396; bh=hkBnbXIj4Ow5ukHzAWFpSqN0IRB8d7dNXP7A+zZpRBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qtxi24umdUcuSRIwdfk7cQXF9cWXQuDwXySud/jP4Yb1VydCYv1vxcTVEmOFlYLix DnOO0zrNtbjc7N5iw5smu2WgFVdqBeRRrn/pCf0RADLso02pyRUR40r5wgBvH7oqLr NhoRCbGxY4kMc8AcjRPeclf+lUt1g1TI+QBbHrY8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrii Nakryiko , Andrey Ignatov , Alexei Starovoitov , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 03/76] libbpf: set BTF FD for prog only when there is supported .BTF.ext data Date: Thu, 29 Aug 2019 14:11:58 -0400 Message-Id: <20190829181311.7562-3-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko [ Upstream commit 3415ec643e7bd644b03026efbe2f2b36cbe9b34b ] 5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD") introduced backwards-compatibility issue, manifesting itself as -E2BIG error returned on program load due to unknown non-zero btf_fd attribute value for BPF_PROG_LOAD sys_bpf() sub-command. This patch fixes bug by ensuring that we only ever associate BTF FD with program if there is a BTF.ext data that was successfully loaded into kernel, which automatically means kernel supports func_info/line_info and associated BTF FD for progs (checked and ensured also by BTF sanitization code). Fixes: 5d01ab7bac46 ("libbpf: fix erroneous multi-closing of BTF FD") Reported-by: Andrey Ignatov Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index e308fcf16cdd0..ce579e3654d60 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2066,7 +2066,11 @@ load_program(struct bpf_program *prog, struct bpf_insn *insns, int insns_cnt, load_attr.license = license; load_attr.kern_version = kern_version; load_attr.prog_ifindex = prog->prog_ifindex; - btf_fd = bpf_object__btf_fd(prog->obj); + /* if .BTF.ext was loaded, kernel supports associated BTF for prog */ + if (prog->obj->btf_ext) + btf_fd = bpf_object__btf_fd(prog->obj); + else + btf_fd = -1; load_attr.prog_btf_fd = btf_fd >= 0 ? btf_fd : 0; load_attr.func_info = prog->func_info; load_attr.func_info_rec_size = prog->func_info_rec_size; -- 2.20.1