From: Oleg Nesterov <oleg@redhat.com>
To: gregkh@linuxfoundation.org
Cc: andrii@kernel.org, jolsa@kernel.org, peterz@infradead.org,
stable@vger.kernel.org
Subject: Re: FAILED: patch "[PATCH] bpf: Fix use-after-free in bpf_uprobe_multi_link_attach()" failed to apply to 6.11-stable tree
Date: Wed, 2 Oct 2024 12:39:07 +0200 [thread overview]
Message-ID: <20241002103905.GC27552@redhat.com> (raw)
In-Reply-To: <2024100247-spray-enjoyable-b1d0@gregkh>
[-- Attachment #1: Type: text/plain, Size: 201 bytes --]
Hi Greg,
On 10/02, gregkh@linuxfoundation.org wrote:
>
> The patch below does not apply to the 6.11-stable tree.
Please see the attached patch. Should work for 6.11 and the previous versions.
Oleg.
[-- Attachment #2: 0001-bpf-Fix-use-after-free-in-bpf_uprobe_multi_link_atta.patch --]
[-- Type: text/plain, Size: 2000 bytes --]
From 69238e2134d57bd7d55c02e1e19fcea75121f21c Mon Sep 17 00:00:00 2001
From: Oleg Nesterov <oleg@redhat.com>
Date: Thu, 19 Sep 2024 15:28:53 +0200
Subject: [PATCH -stable] bpf: Fix use-after-free in bpf_uprobe_multi_link_attach()
commit 5fe6e308abaea082c20fbf2aa5df8e14495622cf upstream.
If bpf_link_prime() fails, bpf_uprobe_multi_link_attach() goes to the
error_free label and frees the array of bpf_uprobe's without calling
bpf_uprobe_unregister().
This leaks bpf_uprobe->uprobe and worse, this frees bpf_uprobe->consumer
without removing it from the uprobe->consumers list.
Fixes: 89ae89f53d20 ("bpf: Add multi uprobe link")
Closes: https://lore.kernel.org/all/000000000000382d39061f59f2dd@google.com/
Reported-by: syzbot+f7a1c2c2711e4a780f19@syzkaller.appspotmail.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: syzbot+f7a1c2c2711e4a780f19@syzkaller.appspotmail.com
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240813152524.GA7292@redhat.com
---
kernel/trace/bpf_trace.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index cd098846e251..af7669a70f2b 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3485,17 +3485,20 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
uprobes[i].ref_ctr_offset,
&uprobes[i].consumer);
if (err) {
- bpf_uprobe_unregister(&path, uprobes, i);
- goto error_free;
+ link->cnt = i;
+ goto error_unregister;
}
}
err = bpf_link_prime(&link->link, &link_primer);
if (err)
- goto error_free;
+ goto error_unregister;
return bpf_link_settle(&link_primer);
+error_unregister:
+ bpf_uprobe_unregister(&path, uprobes, link->cnt);
+
error_free:
kvfree(uprobes);
kfree(link);
--
2.25.1.362.g51ebf55
next prev parent reply other threads:[~2024-10-02 10:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 10:05 FAILED: patch "[PATCH] bpf: Fix use-after-free in bpf_uprobe_multi_link_attach()" failed to apply to 6.11-stable tree gregkh
2024-10-02 10:39 ` Oleg Nesterov [this message]
2024-10-02 11:21 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241002103905.GC27552@redhat.com \
--to=oleg@redhat.com \
--cc=andrii@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jolsa@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox