Re: [TECH TOPIC] Rust for Linux

Geert Uytterhoeven
2021-07-08T13:43:41Z

Hi Wedson,

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?

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