From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: Colin King <colin.king@canonical.com>,
linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag
Date: Fri, 20 Jan 2017 12:47:03 -0800 [thread overview]
Message-ID: <20170120204703.GF12985@birch.djwong.org> (raw)
In-Reply-To: <113b0890-ef1f-0a27-34c1-95785a4d1d17@sandeen.net>
On Fri, Jan 20, 2017 at 01:26:12PM -0600, Eric Sandeen wrote:
> On 1/20/17 8:26 AM, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > If pag cannot be allocated, the current error exit path will trip
> > a null pointer deference error when calling xfs_buf_hash_destroy
> > with a null pag. Fix this by adding a new error exit lable and
> > jumping to this, avoiding the hash destroy and unnecessary kmem_free
> > on pag.
> >
> > Fixes CoverityScan CID#1397628 ("Dereference after null check")
> >
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
>
> Hm, I think this leaves the code with issues.
>
> > ---
> > fs/xfs/xfs_mount.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
> > index 9b9540d..4e66cd19 100644
> > --- a/fs/xfs/xfs_mount.c
> > +++ b/fs/xfs/xfs_mount.c
> > @@ -207,7 +207,7 @@ xfs_initialize_perag(
> >
> > pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL);
> > if (!pag)
> > - goto out_unwind;
> > + goto out_unwind_pags;
>
> So let's say we got to index == 3 at the top of the loop, and
> this fails.
>
> We succeeded in initializing 0, 1, and 2, but 3 failed.
>
> So we go to out_unwind_pags with index == 3...
>
> > pag->pag_agno = index;
> > pag->pag_mount = mp;
> > spin_lock_init(&pag->pag_ici_lock);
> > @@ -242,6 +242,7 @@ xfs_initialize_perag(
> > out_unwind:
> > xfs_buf_hash_destroy(pag);
> > kmem_free(pag);
> > +out_unwind_pags:
>
> ... where index == 3, and:
>
> > for (; index > first_initialised; index--) {
> > pag = radix_tree_delete(&mp->m_perag_tree, index);
>
> this should fail, because it never got inserted, and...
>
> > xfs_buf_hash_destroy(pag);
>
> this still tries to destroy a NULL pag, no?
>
> There also seems to be an existing issue w/the code where ag 0 is
> never torn down in the error case, because first_initialized doesn't
> stay set to 0:
>
> if (!first_initialised)
> first_initialised = index;
>
> And we don't even tear down ag 1, because:
>
> > for (; index > first_initialised; index--) {
> > pag = radix_tree_delete(&mp->m_perag_tree, index);
>
> when the loop reaches the first initialized AG, it stops.
>
> So we seem to always leak at least 2 if we managed to get far enough
> to initialize them.
Ugh, yeah, the the whole error exit from that function is fubar...
Anyone want to clean this up?
--D
>
> -Eric
>
> >
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-01-20 20:47 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-20 14:26 [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag Colin King
2017-01-20 16:34 ` Darrick J. Wong
2017-01-20 19:26 ` Eric Sandeen
2017-01-20 20:47 ` Darrick J. Wong [this message]
2017-01-20 23:04 ` Colin Ian King
2017-01-24 15:04 ` Bill O'Donnell
2017-01-24 18:34 ` Darrick J. Wong
2017-01-24 21:08 ` [PATCH v2] " Bill O'Donnell
2017-01-24 21:21 ` Darrick J. Wong
2017-01-24 21:28 ` Bill O'Donnell
2017-01-25 19:04 ` [PATCH v3] " Bill O'Donnell
2017-01-26 17:58 ` Eric Sandeen
2017-01-26 18:55 ` Bill O'Donnell
2017-01-26 20:27 ` Eric Sandeen
2017-01-28 19:19 ` [PATCH] xfs: correct null checks and error processing in xfs_initialize_perag Bill O'Donnell
2017-02-03 22:57 ` Eric Sandeen
2017-02-06 17:08 ` [PATCH v2] " Bill O'Donnell
2017-02-06 19:25 ` Darrick J. Wong
2017-02-07 16:54 ` [PATCH v3] " Bill O'Donnell
2017-02-07 20:49 ` Eric Sandeen
2017-02-07 20:59 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170120204703.GF12985@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=colin.king@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).