Re: [PATCH] xfs: libxfs: move xfs_perag_put late

From: PanBian
Date: Mon Nov 26 2018 - 05:36:36 EST


On Mon, Nov 26, 2018 at 10:31:39AM +0100, Carlos Maiolino wrote:
> On Sat, Nov 24, 2018 at 05:44:20PM +0800, Pan Bian wrote:
> > The function xfs_alloc_get_freelist calls xfs_perag_put to drop the
> > reference. In this case, pag may be released. However,
> > pag->pagf_btreeblks is read and write after the put operation. This may
> > result in a use-after-free bug. This patch moves the put operation late.
> >
>
> The patch looks reasonable, can you detail more how did you find it? Via code
> inspection of you hit this user-after-free in some way?

I wrote a tool to check such bugs statically. It first scans the source code
to extract paired alloc/free functions. Equipped with such functions, it
performs an intra-procedural data flow analysis to detect mismatched
alloc/free bugs and use-after-free bugs.

Best regards,
Pan Bian