Re: [TECH TOPIC] Rust for Linux

Geert Uytterhoeven
2021-07-08T14:17:06Z

Hi Wedson,

On Thu, Jul 8, 2021 at 3:54 PM Wedson Almeida Filho <wedsonaf@google.com> wrote:
> On Thu, Jul 08, 2021 at 03:43:28PM +0200, Geert Uytterhoeven wrote:
> > On Thu, Jul 8, 2021 at 3:42 PM Wedson Almeida Filho <wedsonaf@google.com> wrote:
> > > On Thu, Jul 08, 2021 at 09:20:25AM +0200, Geert Uytterhoeven wrote:
> > > > > Weak references need to upgraded to strong references before the underlying
> > > > > objects can be accessed; upgrading may fail if the strong count has gone to
> > > > > zero. It is, naturally, implemented as an increment that avoids going from 0 to
> > > > > 1. It is safe to try to do it because the memory is kept alive while there are
> > > > > weak references.
> > > >
> > > > What does "may fail" imply?
> > >
> > > Upgrading is essentially calling `refcount_inc_not_zero` on the strong count.
> > > It succeeds when the count is already non-zero, it fails when the count is zero.
> > >
> > > So "may fail" here means "your attempt to upgrade came too late, the object is
> > > gone". (The memory is still around so that attempts to upgrade don't cause UAF,
> > > but the object is gone.)
> >
> > So what happens if this fails?
>
> You move on the next element in your data structure. This one doesn't really
> exist anymore; once you release it lock, the cleanup code will likely come and
> remove it.

I'm confused. Which next element?
What happens if I have a weak reference to an object that cannot be
upgraded to a strong reference, and I try to access the object?
E.g. read from or write to a member of the object?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds