Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp209247pxb; Mon, 13 Sep 2021 17:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxBFmGm1Jm0+tjg6A57bg9nyz987Evl4lqgdzW9T5zg6B6Ofd4+u5phW3cmzYigkc3aO4b X-Received: by 2002:aa7:c74c:: with SMTP id c12mr16264716eds.87.1631578362689; Mon, 13 Sep 2021 17:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631578362; cv=none; d=google.com; s=arc-20160816; b=Fd1LAhPWaKNWS88EukGT5j0iIsnSGYYmhm58lJTTDisFDOAW2GkUp58JSfQyX/v/RA pRa/5tkI0CcU5Q/71Eoulyhsk4XSLgln2QkJx2xDHYnT4cs/d7hS00Bls/p9pm2iHORa boTnQOcJSu1qpas5Jv5H5VIZ8lgwhckNPBFcIH4L46HfGdlMmP8DboLcMn+23jJ1nlME U4bIU0gmKvAogkJSMfru7f+20HXGQ4PD4ab38mxuq8h8J8YaJSd7Cpt9qYDRz9n35wzq QghLxsaVug7lM5h1pS7L5z7qMkdcNLIKvnjTW5h3xfc93v/F5GjIsH428G32ohKGjr+F SXgQ== 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=SG8INBhdSwPyXJqKsbNgHNzbSa4hJV0BnM23IEM4DAc=; b=qmDAlgukj9dlRjNxncOWQFGcwDlNDGAp/VHacUG+liXdji4qvN6R98aoG7fugP4x9J Hk+G13AWdwH185eZ/78i8Pv6xqRcRFxWG9WskLWbX5mKr5HcOBJweL8grSEAH9gnxLSt wtvO3T3pDUQGpjQt88NpcNyOL+V212E+zGIl07l3fQLpVeeFKJNzJwHxTXcumuAsW2fR d3k4XdYb3KoJ5CmSlAtk8ZtWLAcTGKTxPf8hylCLkBa8w71j1Gor4yGlN/lG2bPjwmml btgRWssyUvqF8z32/dt0zD9UX9xNTP6siW9lbxkkUzFWQqTTvV+Me/wrWugKXQbkWEDZ 5zYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="V1t/FYmm"; 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 w9si10007232edx.466.2021.09.13.17.12.19; Mon, 13 Sep 2021 17:12:42 -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="V1t/FYmm"; 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 S244154AbhIMOFg (ORCPT + 99 others); Mon, 13 Sep 2021 10:05:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:50900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343928AbhIMOB3 (ORCPT ); Mon, 13 Sep 2021 10:01:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB796613B5; Mon, 13 Sep 2021 13:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540277; bh=pegOMUlMbZdM5E+EtRNU5j8y5kuY5Nu/4AfHP64OQs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1t/FYmmdVkzhzLPqZnhWoGYjXJfBy5Fw5KjV4lsnTnt+ANJ62UU3hyGU2wL8J3qV uZxsbtRtdMpMPOl1C46dmv7OnCmsCoTs1fI8RQSGoHCgEFo1TFKjPT7DUcbbm7xL6d dB+P4M+IHD/wRNJ73lnBTGwFmXh4tGB+DuHxhcaE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuyi Cheng , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.13 094/300] libbpf: Fix the possible memory leak on error Date: Mon, 13 Sep 2021 15:12:35 +0200 Message-Id: <20210913131112.555649472@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: Shuyi Cheng [ Upstream commit 18353c87e0e0440d4c7c746ed740738bbc1b538e ] If the strdup() fails then we need to call bpf_object__close(obj) to avoid a resource leak. Fixes: 166750bc1dd2 ("libbpf: Support libbpf-provided extern variables") Signed-off-by: Shuyi Cheng Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/1626180159-112996-3-git-send-email-chengshuyi@linux.alibaba.com Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index c41d9b2b59ac..2af2d0e4a231 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -7365,8 +7365,10 @@ __bpf_object__open(const char *path, const void *obj_buf, size_t obj_buf_sz, kconfig = OPTS_GET(opts, kconfig, NULL); if (kconfig) { obj->kconfig = strdup(kconfig); - if (!obj->kconfig) - return ERR_PTR(-ENOMEM); + if (!obj->kconfig) { + err = -ENOMEM; + goto out; + } } err = bpf_object__elf_init(obj); -- 2.30.2