From: Oleg Nesterov <oleg@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: syzbot <syzbot+f7a1c2c2711e4a780f19@syzkaller.appspotmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
jolsa@kernel.org, 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: Mon, 12 Aug 2024 12:00:29 +0200 [thread overview]
Message-ID: <20240812100028.GA11656@redhat.com> (raw)
In-Reply-To: <CAEf4Bza8Ptd4eLfhqci2OVgGQZYrFC-bn-250ErFPcsKzQoRXA@mail.gmail.com>
On 08/11, Andrii Nakryiko wrote:
>
> On Sun, Aug 11, 2024 at 5:35 AM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > Something like below on top of perf/core. But I don't like the usage of
> > "i" in the +error_unregister path...
> >
>
> Wouldn't the below be cleaner?
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index cd098846e251..3ca65454f888 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -3491,8 +3491,10 @@ int bpf_uprobe_multi_link_attach(const union
> bpf_attr *attr, struct bpf_prog *pr
> }
>
> err = bpf_link_prime(&link->link, &link_primer);
> - if (err)
> + if (err) {
> + bpf_uprobe_unregister(&path, uprobes, cnt);
I disagree. This code already uses the "goto error_xxx" pattern, why
duplicate bpf_uprobe_unregister() ? What if another "can fail" code
comes between register and bpf_link_prime() ?
See the patch below, on top of perf/core.
> We should probably route this through the bpf tree, I don't think it
> will conflict with your changes, right?
It will conflict, and in this sense it is even worse than the "#syz test"
patch I sent in https://lore.kernel.org/all/20240811125816.GC30068@redhat.com/
Because with your version above the necessary change
- bpf_uprobe_unregister(&path, uprobes, cnt);
+ bpf_uprobe_unregister(uprobes, cnt);
won't be noticed during the merge, I guess.
So can we route this fix through the perf/core ? I'll add "cc: stable",
in the next merge window the Greg's scripts will report the "FAILED"
status of the -stable patch, I'll send the trivial backport in reply.
No?
Oleg.
---
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 4e391daafa64..90cd30e9723e 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3484,17 +3484,20 @@ 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;
+ 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(uprobes, link->cnt);
+
error_free:
kvfree(uprobes);
kfree(link);
next prev parent reply other threads:[~2024-08-12 10:00 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
2024-08-12 4:20 ` Andrii Nakryiko
2024-08-12 10:00 ` Oleg Nesterov [this message]
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=20240812100028.GA11656@redhat.com \
--to=oleg@redhat.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii.nakryiko@gmail.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).