Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp687172pxb; Tue, 5 Apr 2022 18:48:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/NvLaP2nh6Cf1N22ru4fzaVzguUC5+OPJNqRB2CmV8Tk6gF4nqztHVkvyhQuVbeiDi/TW X-Received: by 2002:a63:5b48:0:b0:381:10:43e5 with SMTP id l8-20020a635b48000000b00381001043e5mr5208784pgm.544.1649209722314; Tue, 05 Apr 2022 18:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649209722; cv=none; d=google.com; s=arc-20160816; b=IhtvCF4HAj7SDxxdpZFxCOsAGGvMLFAPWIPfkjhA9vTNg1EXu3x5bEpKzN1DkR3Gwo s3Q5mZWo6fZMCGN25F7OyJmNXgxch6d3HotzB/oXeGD0HhNqjkJt2eaYfjKIAzu0Wv8Y wr+7X/Fc0oc7XV0s7ppcN6uyONoNoObZRrcUpiOHdBpsZbssESVimOyyDqNebNrRJSlF 13Z2a381JfNEl0zwShGrX5Y8UfEVxQ4UWK1jfjY8avBchyJTkH7Wc+8ONdHJ36o3LVt4 ITlsrlVq0P4azVFNYjA16A+ItODS2RQdo1ktA0T4PWZTKees3r4tFy9EaGbwPTNlVemM Yg0g== 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=vz6DsZHB0tYbr4tzIKAuzOvN6s/gvslPioZkJNzRjxo=; b=pLlRH0679zqNt1OxaDzmlQlG9BYScCNzREkjRsGIVVHms/P7cfjUwXnmsL6SVo1UL8 7Bu6+SivE1aytMKRRwAQPG5lszdZBd4RZLOaj00xeUDOZvMnMngIFsf849sftl58tXpG zoizY9IPQLAvuBlBqCsdAKbn6+SAjrWzixbDyg1FfknKD3IHxz6omj14LsjwTwYQ+gxT sgQ1aBpGh6ib9PcaTJU60lMHkPX2MvoiossjFPWI1NBxR2JVsvuPwYBEsrIbdO8+rM/Z cKO3MYjWGqBFd6S2P9XyIeilaOvz3LRe8oaXt7R8bBixLgd2voMtZQx7zcMmHVR0oAbi nQNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DhXMlL/f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be3-20020a170902aa0300b00153b2d1650esi14266011plb.278.2022.04.05.18.48.27; Tue, 05 Apr 2022 18:48:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DhXMlL/f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237983AbiDEMdz (ORCPT + 99 others); Tue, 5 Apr 2022 08:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235638AbiDEJCY (ORCPT ); Tue, 5 Apr 2022 05:02:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE203DF82; Tue, 5 Apr 2022 01:54:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6A4AE609D0; Tue, 5 Apr 2022 08:54:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EAF9C385A0; Tue, 5 Apr 2022 08:54:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148851; bh=hivumiYj3Vdez4XqYK2ou4xLfloLyBkHYVMfL/efwgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DhXMlL/fuCFK6BSVImSn393nejQP8Xk92Fp62Q+quAIamvTQzZRv3NwFP4zwBeoMj L1iscyz2v0EhVkRD9fIu9wf+maXhMKoGhhUvKeTjZBzEz6RF0GPO72YCE1II48fcli U5vnal3MZSEgaJqWITrLuvmHSBqCNgVJODt6CPaY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Daniel Borkmann , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Sasha Levin Subject: [PATCH 5.16 0503/1017] libbpf: Fix memleak in libbpf_netlink_recv() Date: Tue, 5 Apr 2022 09:23:36 +0200 Message-Id: <20220405070409.229958390@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Andrii Nakryiko [ Upstream commit 1b8c924a05934d2e758ec7da7bd217ef8ebd80ce ] Ensure that libbpf_netlink_recv() frees dynamically allocated buffer in all code paths. Fixes: 9c3de619e13e ("libbpf: Use dynamically allocated buffer when receiving netlink messages") Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Acked-by: Toke Høiland-Jørgensen Link: https://lore.kernel.org/bpf/20220217073958.276959-1-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/lib/bpf/netlink.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index 69b353d55dbf..fadde7d80a51 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -176,7 +176,8 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq, libbpf_nla_dump_errormsg(nh); goto done; case NLMSG_DONE: - return 0; + ret = 0; + goto done; default: break; } @@ -188,9 +189,10 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq, case NL_NEXT: goto start; case NL_DONE: - return 0; + ret = 0; + goto done; default: - return ret; + goto done; } } } -- 2.34.1