Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1891884pxb; Mon, 13 Sep 2021 07:38:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/4HQGMIpDLXkEvPYbBdy7iIH74wWpTg+hYVNK/npQblVj8/JlSDvvTfwzVFFmAMWoY2e9 X-Received: by 2002:aa7:d649:: with SMTP id v9mr13870136edr.38.1631543907977; Mon, 13 Sep 2021 07:38:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631543907; cv=none; d=google.com; s=arc-20160816; b=E7HdA3fekG025vlD4jlVxw8Jipm/HL2MGWoDnHxLaMRQIey7EK4YVXxt3rhgVP6x2M 9e15ux4L5B3ThJxO0HqcAoyj5x1jS520x4dtD/iZiVR7EGDH2My8C7/iwdarjoWLTLBw uoVVi9gRBfFWDj0P851hQvXWQGq3nF0wa2kIPDaiWSniryCOQhps0feTQNx1Z0npYqPR WELoP7IG8MIsC+KTSB6Pvs1d6mG3ZcqSGVMixXJ1lWAo9K1iZYZree1lA1p9nBj6xhu6 bf5FFEpWdUqTf9+5smC15nhByUVyMc0lJcgNbm0ElJZ3vIdlLvbh+otzHzje6Vx1vH9p lr6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SNwLXoihgBarLc9RKSNkTY7Osglqd0N2v4HO/USlqZM=; b=ToK+n4MsGXywxIjydZIbO12bZdIxIfbZhB2/iiPkooOqttkkbCOEfAS/z0aBwUtrg/ klY/vBueu9LZ8JU0yTbbbuR48eM3Gr5t4n6Uf1/dnVhCu5W4+AUnz5AKRT7IOPcL1n0n b40/QUJwlaZ1OXXQOE+x6KiKxABsrvL+XFP6/1U8U976yqJudeZOzUfHT/fnutjSAKy9 cfaAfrTXRo3mamlqhAwKqVQKezwBnAaotxbjP8mgY8UUp9rzZBoNyY8pNDnF1Hq7cQ6w ZDAIFEsstky5gSZJJeCqzxUSB/q7E73qiRQzWIOHm2dhZdxXrNrFn3IEoTNzQ45X4aqY gHeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HoKl9l0y; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si7588355ejj.636.2021.09.13.07.38.02; Mon, 13 Sep 2021 07:38:27 -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=@linuxfoundation.org header.s=korg header.b=HoKl9l0y; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344864AbhIMOdb (ORCPT + 99 others); Mon, 13 Sep 2021 10:33:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:51896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346876AbhIMO3y (ORCPT ); Mon, 13 Sep 2021 10:29:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A67CE615E3; Mon, 13 Sep 2021 13:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631541039; bh=gGZ2JOSjaNy98g9bYWbfmMs3svm/2BEYqec6l1DCEPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HoKl9l0yDkODWpqRhInYtEF/9lozBWkHv4KAwpK8wMHvM7pmqTdk+8J5LUIxtTa6g tQ9VIrNk7rKNisV7g5Na2rWTD7M7Byx2zNjgDImQdIcc+5mLbYuRIhrqoOxaT4MkL+ CSRSKVn/SqSdyaFrSzYmZ/R30J60X5wSY/ZtTcXI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Martynas Pumputis , John Fastabend , Sasha Levin Subject: [PATCH 5.14 104/334] libbpf: Fix removal of inner map in bpf_object__create_map Date: Mon, 13 Sep 2021 15:12:38 +0200 Message-Id: <20210913131116.888045917@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131113.390368911@linuxfoundation.org> References: <20210913131113.390368911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martynas Pumputis [ Upstream commit a21ab4c59e09c2a9994a6e393b7484e3b3f78a99 ] If creating an outer map of a BTF-defined map-in-map fails (via bpf_object__create_map()), then the previously created its inner map won't be destroyed. Fix this by ensuring that the destroy routines are not bypassed in the case of a failure. Fixes: 646f02ffdd49c ("libbpf: Add BTF-defined map-in-map support") Reported-by: Andrii Nakryiko Signed-off-by: Martynas Pumputis Signed-off-by: Andrii Nakryiko Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/20210719173838.423148-2-m@lambda.lt Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 1bfd11de9be6..aa5ad6fc5f40 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4479,6 +4479,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b { struct bpf_create_map_attr create_attr; struct bpf_map_def *def = &map->def; + int err = 0; memset(&create_attr, 0, sizeof(create_attr)); @@ -4521,8 +4522,6 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b if (bpf_map_type__is_map_in_map(def->type)) { if (map->inner_map) { - int err; - err = bpf_object__create_map(obj, map->inner_map, true); if (err) { pr_warn("map '%s': failed to create inner map: %d\n", @@ -4547,8 +4546,8 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b if (map->fd < 0 && (create_attr.btf_key_type_id || create_attr.btf_value_type_id)) { char *cp, errmsg[STRERR_BUFSIZE]; - int err = -errno; + err = -errno; cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg)); pr_warn("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", map->name, cp, err); @@ -4560,8 +4559,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b map->fd = bpf_create_map_xattr(&create_attr); } - if (map->fd < 0) - return -errno; + err = map->fd < 0 ? -errno : 0; if (bpf_map_type__is_map_in_map(def->type) && map->inner_map) { if (obj->gen_loader) @@ -4570,7 +4568,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b zfree(&map->inner_map); } - return 0; + return err; } static int init_map_slots(struct bpf_object *obj, struct bpf_map *map) -- 2.30.2