Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1839515pxb; Mon, 13 Sep 2021 06:41:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygOYob1A7MadmIBpEhCkH1uExf1/XoQElp8skFlASN0bbysPmAO4lq9FLV9BYweOUJPyhC X-Received: by 2002:a6b:2c08:: with SMTP id s8mr8981419ios.216.1631540493185; Mon, 13 Sep 2021 06:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631540493; cv=none; d=google.com; s=arc-20160816; b=lnEObh8FcEfuyhqgIckNzSl1OFR4SnwetUc7a1eiz6iQbnua33+H7VZu4gSYgw9MDk ZSPtgTvHf6hX8DKuDBFA4xdJOLcVkDSrUAsr8sSMpk73wfn3CjvJhhDw4Hu02cRreXzM Qjs0A2yZmNmWMc2qtwNIUb8vpjRepkdXsTJNJrAQB1zaamrf+l3OaJLIf1RkqATPufWm NRo9pNM1C6hMwCWqtwKmi7epjAayC43tnGlEdxtxfzCr6Yqc0wsps+Op85YeuBLv+V7A Q37IHVhf1RWX4Bqpfu7yGupJfRI7J3CUpuffbS/h3Y7QLfzyFRLv6b5cxN9w/cyQaEAU JKBQ== 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=FqmY7G460JGgK6qcb9Y93UGeORR6h5bNumqE1UY+1gc=; b=GKI5RQI7C6WEyqG0vqLQw2gftkn2Y4l1ZVwsAj6pqVBARM9PKghTnqLgHm0yTHo1qS h7BYxvmag7OWFFAZ5zi77ZU8Jf2Nj3y9YTqB14jVHkPxQsqPaFyT1xPLdVb0VKakcURS K0SN1wjZ3vpHB0sqfsfsRRl3dff6IYae05vsPmY0WZW0Ir+EVxFOMskdt980mDKIA/7E vv30N7GEhdoOLptDTqndrQazpfmrhnAwOQDJ1r61FUhVl9al8HTfTwrLn9neBf3I4VPo P555Y/OPubaGsLQoFLthFo0uM5Y8jVEoVDhgnuonyRrio9sM8Iz8Vs2MeVIRYtNF1OeM tW4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aXcRi2s1; 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 f46si6575678jaa.87.2021.09.13.06.41.21; Mon, 13 Sep 2021 06:41:33 -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=aXcRi2s1; 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 S242278AbhIMNkO (ORCPT + 99 others); Mon, 13 Sep 2021 09:40:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:58346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242946AbhIMNeg (ORCPT ); Mon, 13 Sep 2021 09:34:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A2E2861107; Mon, 13 Sep 2021 13:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539599; bh=5g772FIa1JKIzWCgK2pejEwmlejNBzBFBpU6kSf7rpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aXcRi2s1bU50i8zCMbwTEHUwiCrTpYshqAxnzWSXuNLe/rjb2QnN7sVJMB21FGqqX PPE/VVzRUt2Vb1xyN1qWqbwX3e82og/YJQEkcrH1dlkGEp7F/Y4ZEbWU06mV81PedU 36HWU7PTlN7tKugEVqfbNnxQs1t4siOz368vwuCU= 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.10 086/236] libbpf: Fix removal of inner map in bpf_object__create_map Date: Mon, 13 Sep 2021 15:13:11 +0200 Message-Id: <20210913131103.278478448@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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 04cde732d686..28923b776cdc 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4123,6 +4123,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map) { struct bpf_create_map_attr create_attr; struct bpf_map_def *def = &map->def; + int err = 0; memset(&create_attr, 0, sizeof(create_attr)); @@ -4165,8 +4166,6 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map) 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); if (err) { pr_warn("map '%s': failed to create inner map: %d\n", @@ -4183,8 +4182,8 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map) 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); @@ -4196,15 +4195,14 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map) 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) { bpf_map__destroy(map->inner_map); zfree(&map->inner_map); } - return 0; + return err; } static int init_map_slots(struct bpf_map *map) -- 2.30.2