From: Oleg Nesterov <oleg@redhat.com>
To: syzbot <syzbot+f7a1c2c2711e4a780f19@syzkaller.appspotmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
jolsa@kernel.org
Cc: acme@kernel.org, adrian.hunter@intel.com,
alexander.shishkin@linux.intel.com, irogers@google.com,
kan.liang@linux.intel.com, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, mark.rutland@arm.com,
mhiramat@kernel.org, mingo@redhat.com, namhyung@kernel.org,
peterz@infradead.org, syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [perf?] KASAN: slab-use-after-free Read in __uprobe_unregister
Date: Sun, 11 Aug 2024 14:35:04 +0200 [thread overview]
Message-ID: <20240811123504.GB30068@redhat.com> (raw)
In-Reply-To: <20240811121444.GA30068@redhat.com>
On 08/11, Oleg Nesterov wrote:
>
> Hmm, bpf_uprobe_multi_link_attach() looks obviously wrong.
>
> bpf_link_prime() is called after the
>
> for (i = 0; i < cnt; i++) {
> uprobe_register(...);
> ...
> }
>
> loop. If bpf_link_prime() fails, bpf_uprobe_multi_link_attach() just do
> kvfree(uprobes) without _unregister(). In particular, this leaks the freed
> bpf_uprobe->consumer in the uprobe->consumers list.
>
> After that another _unregister() on the same uprobe can hit the problem.
>
> I guess we need a simple patch for -stable...
Something like below on top of perf/core. But I don't like the usage of
"i" in the +error_unregister path...
Oleg.
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3486,17 +3486,19 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
&uprobes[i].consumer);
if (IS_ERR(uprobes[i].uprobe)) {
err = PTR_ERR(uprobes[i].uprobe);
- bpf_uprobe_unregister(uprobes, i);
- goto error_free;
+ 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(uprobes, i);
+
error_free:
kvfree(uprobes);
kfree(link);
next prev parent reply other threads:[~2024-08-11 12:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-10 20:17 [syzbot] [perf?] KASAN: slab-use-after-free Read in __uprobe_unregister syzbot
2024-08-11 12:14 ` Oleg Nesterov
2024-08-11 12:35 ` Oleg Nesterov [this message]
2024-08-12 4:20 ` Andrii Nakryiko
2024-08-12 10:00 ` Oleg Nesterov
2024-08-12 15:22 ` Andrii Nakryiko
2024-08-12 19:24 ` Oleg Nesterov
2024-08-12 20:00 ` Andrii Nakryiko
2024-08-11 12:58 ` Oleg Nesterov
2024-08-11 13:29 ` syzbot
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=20240811123504.GB30068@redhat.com \
--to=oleg@redhat.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=syzbot+f7a1c2c2711e4a780f19@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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;
as well as URLs for NNTP newsgroup(s).