From patchwork Tue Jan 21 16:50:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David CARLIER X-Patchwork-Id: 13946455 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC77913BC0C for ; Tue, 21 Jan 2025 16:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737478253; cv=none; b=BQAa5BcShsy4Hv9Qmgccf5SoqI+sHlFxxCdRjfdbbs0J1RywCNhUooOV49645m1TVzkUKIJSN3uGd4+55yYhu/JI3flU8Jo0u+F7gFD2MhokygvaRbWHz2vEWNT1mhcZdCday1wP1fBYJgPJddVyYf/R2liODZ7ITICS9SfCElg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737478253; c=relaxed/simple; bh=SsXmSGW57WprIatXJQU3GgUJc0Iq3+wXch4RgUbJtpY=; h=MIME-Version:From:Date:Message-ID:Subject:To:Content-Type; b=sKu/gYxyXAsGkDeUIJrT9X4hlc/gudIfYad6APzV4Fpw3ahKmIJJzcdSs2KhDVwD6DZsWrO8+BeBt0WxMB9idF7JZlJqLVFCPCjlScEaWDQuyWeMMKa95WkImi6SCacRaqj2eNTYJIMQdLS837JQ7ykqIjtNPW3e8waEvJ/hDMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k7D3j8VJ; arc=none smtp.client-ip=209.85.161.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k7D3j8VJ" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5f33ad7d6faso3747698eaf.0 for ; Tue, 21 Jan 2025 08:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737478250; x=1738083050; darn=vger.kernel.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=qIrDR2ZN/EUQN3BtPjqgq3XG3zWYH9SNKP4tKdFLz20=; b=k7D3j8VJ67+ikfDDLDtbZOND5N2QJEaaXhB/bZx3BPV7JGEJy5Rf4nDzq1N+4M36Jo DNhBH4x13buUK8YYRBmD/52XGvM6JowgeqXdPfitr0hbxoRHxdWPb7Ebqw/FuztHKxJl Ag7MedzYScc09iNNSfvCSwZkX85f4iHy2f7JOnYbARpR2apSVYRsrBFxA7pJiIKSTvPV h4nUEPi9EOXyWd2OkyYI8G2zk9sH3iLHo83JlNyf978BnlJ3YWxbYAluHiwcNJUHR+HU fcLVK04njeHNXyNFYk3Cc82gogBqV5tq5sfobBAGVBefQf5+gtjJAoiSDWOVESlbiLvN fVrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737478250; x=1738083050; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qIrDR2ZN/EUQN3BtPjqgq3XG3zWYH9SNKP4tKdFLz20=; b=lMjdZSLk5L82MZt51SYLsEge7w9fJnvoe/vUvfi6LmGbx7FxqNXZaYJML7BusCJTP9 M/oQFSV+Sbcr7/9EXs1CTNLGA/OuLkdggqcA9a7CM4/j4f87DI5IceOOXOU0x2sb9A/W p3ynahSHdXL4n8ZQQCc4c81MQsXw3qelgA7JQLZ2e8cFQK2X/6Y9TrBQgG3lCdi5YCeN LPXKEa/8PaYFtYvD2dMVD4VBj0iHItSX/UMSXUpA+bnE3J1dIdhEDMyl1+TawDnLmAT/ cHs/nG0hZ+Q3mObjjpK4VygBqlWjh891O4ZfjYCa/QkwtEgMjLq2e6DlVdGD6XlGgWh8 is6Q== X-Gm-Message-State: AOJu0YwwMpoT6w46eoVgXORS9skTocVEIPAKVLqsBKMG2So3kXVDFQdw IdUKygGkrTn7D472TRRPkm0KAavI3pXqmC5Kft1AT8lZTUoA2w0xWpyFJ+jrIa/ly9qXA5GH054 H3fbR7tTKOmmRtwwoV0ACzH19FseI/g== X-Gm-Gg: ASbGncsbHrkplSBbm06ts1Gq+PZzynuhOH2XWWn9vrC9aYXc/28BnvQAY3383jWnHnB gDnsuuXlyLhb5lBfPFy1gb2IMbUOe9ntiiKnsVza766ohlE3a9g== X-Google-Smtp-Source: AGHT+IFJKo9XDHWURrrlprj329eayn4UoDqadyTZu2AiZrVqBxxqp3rUzXRijSuv6Db64xYbIi73COhgPjWbLlNSLmY= X-Received: by 2002:a05:6820:2706:b0:5f6:6547:8a0f with SMTP id 006d021491bc7-5fa3887bbfamr10970193eaf.6.1737478250416; Tue, 21 Jan 2025 08:50:50 -0800 (PST) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: David CARLIER Date: Tue, 21 Jan 2025 16:50:39 +0000 X-Gm-Features: AbW1kvaYwkyOzt09tAYe3f5VvhOJyqoKd6xI-qw9BiRuuyvxROzxpoqpzMVhWfg Message-ID: Subject: [PATCH bpf-next 1/1] To: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net libbpf.c memory leaks fixes proposal. From 381ae513671ea214f0f6a04ca9da75dfe4411683 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 18 Jan 2025 10:30:39 +0000 Subject: [PATCH] libbpf.c: bpf_program__attach_uprobe_opts fix possible memory leaks. bpf_program__attach_perf_event_opts() might be not enough to close the file descriptor, bpt_link__destroy() does a more thorough clean up including its inner file descriptor. Applying to bpf_program__attach_kprobe_opts/bpf_program__attach_tracepoints_opts too. Signed-off-by: David Carlier --- src/libbpf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libbpf.c b/src/libbpf.c index 194809d..e571675 100644 --- a/src/libbpf.c +++ b/src/libbpf.c @@ -11271,7 +11271,7 @@ bpf_program__attach_kprobe_opts(const struct bpf_program *prog, link = bpf_program__attach_perf_event_opts(prog, pfd, &pe_opts); err = libbpf_get_error(link); if (err) { - close(pfd); + bpf_link__destroy(link); pr_warn("prog '%s': failed to attach to %s '%s+0x%zx': %s\n", prog->name, retprobe ? "kretprobe" : "kprobe", func_name, offset, @@ -12259,7 +12259,7 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid, link = bpf_program__attach_perf_event_opts(prog, pfd, &pe_opts); err = libbpf_get_error(link); if (err) { - close(pfd); + bpf_link__destroy(link); pr_warn("prog '%s': failed to attach to %s '%s:0x%zx': %s\n", prog->name, retprobe ? "uretprobe" : "uprobe", binary_path, func_offset, @@ -12514,7 +12514,7 @@ struct bpf_link *bpf_program__attach_tracepoint_opts(const struct bpf_program *p link = bpf_program__attach_perf_event_opts(prog, pfd, &pe_opts); err = libbpf_get_error(link); if (err) { - close(pfd); + bpf_link__destroy(link); pr_warn("prog '%s': failed to attach to tracepoint '%s/%s': %s\n", prog->name, tp_category, tp_name, errstr(err)); -- 2.47.2