All of lore.kernel.org
 help / color / mirror / Atom feed
* Catching use-after-free easily in linux kernel.
@ 2025-03-10  7:54 Amit
  2025-03-11  0:35 ` Al Viro
  0 siblings, 1 reply; 7+ messages in thread
From: Amit @ 2025-03-10  7:54 UTC (permalink / raw)
  To: linux-kernel

Hi,

We can catch use-after-free easily if we do the following:

kfree(x);
(x) = NULL;

Now, if someone uses 'x' again then the kernel will crash and we will know where
the use-after-free is happening and then we can fix it.

Regards,
Amit

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Catching use-after-free easily in linux kernel.
@ 2026-01-13 12:03 Amit
  0 siblings, 0 replies; 7+ messages in thread
From: Amit @ 2026-01-13 12:03 UTC (permalink / raw)
  To: linux-kernel

On Tue, 11 Mar 2025 at 06:05, Al Viro <viro@...iv.linux.org.uk> wrote:
>
> On Mon, Mar 10, 2025 at 01:24:54PM +0530, Amit wrote:
> > Hi,
> >
> > We can catch use-after-free easily if we do the following:
> >
> > kfree(x);
> > (x) = NULL;
> >
> > Now, if someone uses 'x' again then the kernel will crash and we will know where
> > the use-after-free is happening and then we can fix it.
>
> That assumes that no pointer is ever stored in more than one place.
> Which is very clearly false.

In general, I don't think that in linux kernel ""lots of dynamic
pointers"" are being cached/saved/duplicated in global structures - I
haven't gone through all the kernel code but I can't think of logical
scenarios where ""lots of dynamic pointers"" will be
cached/saved/duplicated in global structures.

By dynamic pointers, I mean pointers to transient memory/data that can
come and go (not like pointers to pre-allocated inodes of filesystems
like ext4, etc.).

And, obviously, local caching/saving/duplication
(caching/saving/duplication in a function) doesn't matter. So, the
above code should be very effective.

Also, something is better than nothing.

----

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-13 12:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10  7:54 Catching use-after-free easily in linux kernel Amit
2025-03-11  0:35 ` Al Viro
2025-03-11  3:29   ` Amit
     [not found]   ` <CAFf+5zjGKMSCYNZvOzaCNRFKHjWe2a6TKmmKqg7Fe-TLQW07yA@mail.gmail.com>
2025-03-11  4:42     ` Al Viro
2025-03-11  4:53       ` Amit
2025-03-11  6:48       ` Amit
  -- strict thread matches above, loose matches on Subject: below --
2026-01-13 12:03 Amit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.