Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp991108pxb; Wed, 6 Apr 2022 06:11:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMkDCX5ZHgUy8tDYG/+dZmvwg3DDOzB/NtQsOni4dvbrg0A8nCdH77gtrfKWvIauikMQV+ X-Received: by 2002:a05:6e02:148a:b0:2c9:a0b2:b14 with SMTP id n10-20020a056e02148a00b002c9a0b20b14mr3845624ilk.259.1649250693620; Wed, 06 Apr 2022 06:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649250693; cv=none; d=google.com; s=arc-20160816; b=aI6+YqUxKvJi1kI8lLQjITNa6AhW/7Ix8b6A8jfK2DDCgL8F7WKKbKBQieSavyoJa6 uBMh8H3dm5y5pLMhODowKKaH3zoXA44SXNTacHxneEwT2nIDsg5FirAvrwjjpEdzY2v+ 3rxEyQQPUTpohLPLtga3l5yQMJz1LcM/GmIuI/+vqID1ms7DFthst+2zEbOfF8mVZ/F6 /HYR9Qaxlro5azRou0GLAdh51COVXRzqBMl0U+xlBKzjzrKBhA+gE7mOlKR2DgmRLIRY aZslD8UYKHc95dWZ7YRLTkGQGAOB+rIL9wnD3GDmIdc3QKbtC03+vSNndZbFJVuKj7mL dN8A== 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=bNGy7ipYmpKh+6bOBuG/wqiUkLRh2/SBh16zHap6GKo=; b=UDXNirB9NiLgQpbmdeJOzQTckDXro9s3W7QTfw1SbAD7z1TE+HsdxMXfaW7eP/ApSy OhoKf97T2AO86JTIVwQ7sNhHMrG6lbzXQa0O6tENSOgF9z+bH5UwE91RKoxMl6cl9RgS UfZ6I4uCNUBn49QsRda266foW+pNzqsGqB77HUdmIW+2zLRPZ+1bLOqoHR/4K+6O577U 6hstjzljWDQyUaexrTFne73odUvdqRNzmd39SoX0B9N9mksQITFDPYGBoMlRFuFwOAmu FIQDIGW7sbxzAALpmqyIbKAnmhqFS8VWgkQT5uMsdxzdFJhRc9YuTiTu7BoG1QoLJiB5 9AFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aMi1m1bF; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x6-20020a056638160600b0031a2a4215edsi10061933jas.15.2022.04.06.06.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:11:33 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aMi1m1bF; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B9B9F4F3185; Wed, 6 Apr 2022 03:36:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235115AbiDEVLn (ORCPT + 99 others); Tue, 5 Apr 2022 17:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232972AbiDEJsi (ORCPT ); Tue, 5 Apr 2022 05:48:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AFEB9285C; Tue, 5 Apr 2022 02:35:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 47C35B81B75; Tue, 5 Apr 2022 09:35:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99996C385A2; Tue, 5 Apr 2022 09:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151355; bh=GltpdBVeULqUGpBO1nAxh639HFSQaoT6tOmZcNXQin4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aMi1m1bFpYsX3FR/wzkQdbKww6JeAYOoo6oi87k4NkgXLt/blrVPPLF86leV5MRQC w9LYo3bxBiFVbNDKBgPPFdl9wWmD5CNpFzID6uRYegFIfzvt7++0AVM2k5CkeJsHWH Y0tPnSSrOOFUTCDGYvX7e8tyYCoaBTMUEvMM8PME= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Fu , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.15 386/913] bpftool: Only set obj->skeleton on complete success Date: Tue, 5 Apr 2022 09:24:08 +0200 Message-Id: <20220405070351.417249214@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei Fu [ Upstream commit 0991f6a38f576aa9a5e34713e23c998a3310d4d0 ] After `bpftool gen skeleton`, the ${bpf_app}.skel.h will provide that ${bpf_app_name}__open helper to load bpf. If there is some error like ENOMEM, the ${bpf_app_name}__open will rollback(free) the allocated object, including `bpf_object_skeleton`. Since the ${bpf_app_name}__create_skeleton set the obj->skeleton first and not rollback it when error, it will cause double-free in ${bpf_app_name}__destory at ${bpf_app_name}__open. Therefore, we should set the obj->skeleton before return 0; Fixes: 5dc7a8b21144 ("bpftool, selftests/bpf: Embed object file inside skeleton") Signed-off-by: Wei Fu Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20220108084008.1053111-1-fuweid89@gmail.com Signed-off-by: Sasha Levin --- tools/bpf/bpftool/gen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index d40d92bbf0e4..07fa502a4ac1 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -870,7 +870,6 @@ static int do_skeleton(int argc, char **argv) s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));\n\ if (!s) \n\ goto err; \n\ - obj->skeleton = s; \n\ \n\ s->sz = sizeof(*s); \n\ s->name = \"%1$s\"; \n\ @@ -955,6 +954,7 @@ static int do_skeleton(int argc, char **argv) \n\ \"; \n\ \n\ + obj->skeleton = s; \n\ return 0; \n\ err: \n\ bpf_object__destroy_skeleton(s); \n\ -- 2.34.1