Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp150281pxb; Mon, 13 Sep 2021 15:34:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTa89POsJajnY/4bUzc1Ln7PTx3gYkGs9PqNk83+4/Z6K0r+VPOAaGXflaZrcABxy6drPA X-Received: by 2002:a50:d713:: with SMTP id t19mr15678141edi.2.1631572491738; Mon, 13 Sep 2021 15:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631572491; cv=none; d=google.com; s=arc-20160816; b=KxscaOxxN7p90OXW28svFkLfjNmvYPgi4fvBTIPgWWDCow1tYkpLfdN362H1asyQfh YmIh9E93mr6WhR7sQigvzQSKFxyWlJsvrum9bb+UCYH/pl2V8Rp7Mc3eAmHywMYL8A9i KOlK7xV/33ufwcRxpA8y7MuYEeonYhI3nFTBdv/7NjxB5bW2YrEsmCMgyOwaiHnGWufo +zwUDXy5Aqvrknw6IZaNYJutbFCBt/NZM3bFdZsLwUCuouFep8FietZsY98xGbf94XzT 9+uWA0HIjEgIO5rgRuYIx4cTQ8UH0V2EcjE4/nNQPMOCDIJh3z8pPi/PYRc0dLpfs3/q rnUQ== 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=U1THq8tj4h7SQ7sZ/q/YAcINVeILTSR2lTqn8OQA+/M=; b=TlAroPP3c8O4flKw0jOg2HhQnOBrtIyGgwsQ9J4OK0ElWRdqI4Tyvrq5cVZe9cWTbz SQQH6pCORuQOMTmBEWeoNNXKGC75SMkAioI+01Ye6ZrIRUKXH5xEGtnLuyhMxslc75E+ cEG8Zn72dhN0aVfEywnRx8gY8b6+jCdmJdG/MKFQRduwOVi+8VDt74y7bDYjizxep1WU OOhfw+6tMIwtLbct/beCNIgyrDyfpGKY6TF+zDmyTzqmQhnFGjrmt/oPcJzRpj655bjj m8OmSHN2dxgzFacFRB3hMzpxcsRGimUwBaWxTCfCZme7tBT4WOrVUxFptfLeNDJK07xQ dEZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UWd48goy; 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 d19si397487edx.318.2021.09.13.15.34.27; Mon, 13 Sep 2021 15:34:51 -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=UWd48goy; 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 S245268AbhIMOBS (ORCPT + 99 others); Mon, 13 Sep 2021 10:01:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:46226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244583AbhIMN6o (ORCPT ); Mon, 13 Sep 2021 09:58:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1381461A09; Mon, 13 Sep 2021 13:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540213; bh=thT2wqlvZf15xo7YVN8BMgNJmBy43XTZYaqLpOtEODU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWd48goyVHFng+o3gGNVMc7n2XDvJ4G5fkZGH49wE76G7gcLsuST25UhmxHjmp9rU rsArwau8jWA86gT/ADT1+CC8lZ4t7/KaJ2HVLx0broazFsuUoobhe3cit+xEFkCfHX steNAeIyej7mnCS8GIs/Vy7axwsuy/ZFsXqeF4ao= 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.13 100/300] libbpf: Fix removal of inner map in bpf_object__create_map Date: Mon, 13 Sep 2021 15:12:41 +0200 Message-Id: <20210913131112.757649153@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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 2af2d0e4a231..f6ebda75b030 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -4409,6 +4409,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)); @@ -4451,8 +4452,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", @@ -4469,8 +4468,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); @@ -4482,15 +4481,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