Re: [PATCH 3/3] uprobes: make uprobe_register() return struct uprobe *
From: Andrii Nakryiko
Date: Thu Jul 11 2024 - 13:13:02 EST
On Thu, Jul 11, 2024 at 2:28 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> On 07/10, Oleg Nesterov wrote:
> >
> > -void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
> > +void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
> > {
> > - struct uprobe *uprobe;
> > -
> > - uprobe = find_uprobe(inode, offset);
> > - if (WARN_ON(!uprobe))
> > - return;
> > -
> > down_write(&uprobe->register_rwsem);
> > __uprobe_unregister(uprobe, uc);
> > up_write(&uprobe->register_rwsem);
> > - put_uprobe(uprobe);
>
> OK, this is obviously wrong, needs get_uprobe/put_uprobe. __uprobe_unregister()
> can free this uprobe, so up_write(&uprobe->register_rwsem) is not safe.
uprobe_register(), given it returns an uprobe instance to the caller
should keep refcount on it (it belongs to uprobe_consumer). That's
what I did for my patches, are you going to do that as well?
We basically do the same thing, just interfaces look a bit different.
>
> I'll send V2 on top of Peter's new version.
>
> Oleg.
>