Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp112716ybg; Mon, 8 Jun 2020 17:58:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7oQVUWewuUL03ciuNxhgUT2aVhjMo4M1L64m62YAmWfMORooeVjHYbRLA6gazylVwcAGa X-Received: by 2002:a50:d0dc:: with SMTP id g28mr11804321edf.71.1591664299574; Mon, 08 Jun 2020 17:58:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591664299; cv=none; d=google.com; s=arc-20160816; b=jc5m//h87vIxh9Z83tE4LLGPwLwP8KM7RW+nnTCrxd9EmcI9PGItrz4udWED5hiBBw xFwjiYDZSiv1igOnMR9ZffVnaho5Kp7zfbRtbzYfnL4+cJ9Q29T52HwLeIek0hRtFXjD zS0ktlT2vJWnRk/MbgUHMBu07vb1iKccobgL6qx3hSwiOpuOnxe/pMfM4QoLtDTnZCsy 0MLmJg6UuJpqwUh+W8JxspZqBKZfgd+YM3p3bxjQkzYVEK+y057zD6mAnFU1YUlWj8Qz SiDjfYGh3rxZ594dCyagET+xCFc44nptt993AR2ttiqc/DLRywnNvRUvZcsW6owv1r5a EcOw== 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=8WBG2G+w1HhOk23aEpgzP06nSmCNRf4kdpSTrZCNczg=; b=TWbi8BVk1O+FhEFbhoomxql9ZUZ00ii046/yfok+ckQK9JPYTsM5UKzJmyM+5KK9mV bHpN4ByIZi++Uc8kLTqDWh8MVSGDqs5NTWPUP6aV6aKPh6jCPwoBmonj/Gr/LBJ1cDRl 2i9HAXyIpOSksJtE9gOxe7aeLMBWrEOXdQxCMRsSLgOkuREXXBzaweCfivROBHzRuh+M c6Kw3Biv663p33KXmFunT2TjyT5XolvGnP5eeu7AaEFzchugJmaYqDAfJAn+BOYo42IU SvqbANkLGxQ/Sp2DPEu0fUOL+cr/ysK3wjveKJ8I6qIdlvMP49155RMlXtIosIUXhS+4 WjjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UFAcSbgj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id c10si9882821edj.163.2020.06.08.17.57.56; Mon, 08 Jun 2020 17:58:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UFAcSbgj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1733007AbgFIA4Q (ORCPT + 99 others); Mon, 8 Jun 2020 20:56:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:54714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728323AbgFHXJF (ORCPT ); Mon, 8 Jun 2020 19:09:05 -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 817A620B80; Mon, 8 Jun 2020 23:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657745; bh=eLGvbqasm5wT9Qyyy9tJRN20dYjw6ehaSKc9NufMyLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UFAcSbgjNs+965jiLFuV2TERJGezRivtk/hkb7aQtTZ0g0CynvXb7o3u3JKZ9qYnf uL9elq8MtaRcyro2jinmJ2n2Jd+DeIfwvGy4JwkgJxKr6SF/b1cGKuXekCI+AEHj3K 4eXDZu7OHMw6kuOvH1kqMdf50vf6DEau9O75GQJw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrii Nakryiko , Alexei Starovoitov , KP Singh , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 133/274] libbpf: Fix huge memory leak in libbpf_find_vmlinux_btf_id() Date: Mon, 8 Jun 2020 19:03:46 -0400 Message-Id: <20200608230607.3361041-133-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-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 3521ffa2ee9a48c3236c93f54ae11c074490ebce ] BTF object wasn't freed. Fixes: a6ed02cac690 ("libbpf: Load btf_vmlinux only once per object.") Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Cc: KP Singh Link: https://lore.kernel.org/bpf/20200429012111.277390-9-andriin@fb.com Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 63fc872723fc..cd53204d33f0 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -6688,6 +6688,7 @@ int libbpf_find_vmlinux_btf_id(const char *name, enum bpf_attach_type attach_type) { struct btf *btf; + int err; btf = libbpf_find_kernel_btf(); if (IS_ERR(btf)) { @@ -6695,7 +6696,9 @@ int libbpf_find_vmlinux_btf_id(const char *name, return -EINVAL; } - return __find_vmlinux_btf_id(btf, name, attach_type); + err = __find_vmlinux_btf_id(btf, name, attach_type); + btf__free(btf); + return err; } static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd) -- 2.25.1