Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1563643 > unrolled thread
| Started by | Colin King <colin.king@canonical.com> |
|---|---|
| First post | 2017-01-20 15:30 +0100 |
| Last post | 2017-01-24 19:40 +0100 |
| Articles | 7 — 5 participants |
Back to article view | Back to linux.kernel
[PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag Colin King <colin.king@canonical.com> - 2017-01-20 15:30 +0100
Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag "Darrick J. Wong" <darrick.wong@oracle.com> - 2017-01-20 17:40 +0100
Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag Eric Sandeen <sandeen@sandeen.net> - 2017-01-20 20:40 +0100
Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag "Darrick J. Wong" <darrick.wong@oracle.com> - 2017-01-20 21:50 +0100
Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag Colin Ian King <colin.king@canonical.com> - 2017-01-21 00:10 +0100
Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag Bill O'Donnell <billodo@redhat.com> - 2017-01-24 16:10 +0100
Re: [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag "Darrick J. Wong" <darrick.wong@oracle.com> - 2017-01-24 19:40 +0100
| From | Colin King <colin.king@canonical.com> |
|---|---|
| Date | 2017-01-20 15:30 +0100 |
| Subject | [PATCH] xfs: do not call xfs_buf_hash_destroy on a NULL pag |
| Message-ID | <t1Imu-8mw-33@gated-at.bofh.it> |
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>
---
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;
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:
for (; index > first_initialised; index--) {
pag = radix_tree_delete(&mp->m_perag_tree, index);
xfs_buf_hash_destroy(pag);
--
2.10.2
[toc] | [next] | [standalone]
| From | "Darrick J. Wong" <darrick.wong@oracle.com> |
|---|---|
| Date | 2017-01-20 17:40 +0100 |
| Message-ID | <t1Koh-19S-15@gated-at.bofh.it> |
| In reply to | #1563643 |
On Fri, Jan 20, 2017 at 02:26:42PM +0000, 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>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Applied, thanks.
--D
> ---
> 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;
> 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:
> for (; index > first_initialised; index--) {
> pag = radix_tree_delete(&mp->m_perag_tree, index);
> xfs_buf_hash_destroy(pag);
> --
> 2.10.2
>
> --
> 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
[toc] | [prev] | [next] | [standalone]
| From | Eric Sandeen <sandeen@sandeen.net> |
|---|---|
| Date | 2017-01-20 20:40 +0100 |
| Message-ID | <t1Ncu-2V1-3@gated-at.bofh.it> |
| In reply to | #1563643 |
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.
-Eric
>
[toc] | [prev] | [next] | [standalone]
| From | "Darrick J. Wong" <darrick.wong@oracle.com> |
|---|---|
| Date | 2017-01-20 21:50 +0100 |
| Message-ID | <t1Oie-3yD-9@gated-at.bofh.it> |
| In reply to | #1563880 |
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
[toc] | [prev] | [next] | [standalone]
| From | Colin Ian King <colin.king@canonical.com> |
|---|---|
| Date | 2017-01-21 00:10 +0100 |
| Message-ID | <t1QtH-55e-3@gated-at.bofh.it> |
| In reply to | #1563907 |
On 20/01/17 20:47, Darrick J. Wong wrote:
> 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?
I may step back on this if somebody else wants to fix this up properly.
>
> --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
[toc] | [prev] | [next] | [standalone]
| From | Bill O'Donnell <billodo@redhat.com> |
|---|---|
| Date | 2017-01-24 16:10 +0100 |
| Message-ID | <t3aTo-5Sx-29@gated-at.bofh.it> |
| In reply to | #1563986 |
On Fri, Jan 20, 2017 at 11:04:42PM +0000, Colin Ian King wrote:
> On 20/01/17 20:47, Darrick J. Wong wrote:
> > 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?
>
> I may step back on this if somebody else wants to fix this up properly.
I'll take it.
-Bill
>
> >
> > --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
>
> --
> 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
[toc] | [prev] | [next] | [standalone]
| From | "Darrick J. Wong" <darrick.wong@oracle.com> |
|---|---|
| Date | 2017-01-24 19:40 +0100 |
| Message-ID | <t3eaB-7My-3@gated-at.bofh.it> |
| In reply to | #1565926 |
On Tue, Jan 24, 2017 at 09:04:57AM -0600, Bill O'Donnell wrote:
> On Fri, Jan 20, 2017 at 11:04:42PM +0000, Colin Ian King wrote:
> > On 20/01/17 20:47, Darrick J. Wong wrote:
> > > 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?
> >
> > I may step back on this if somebody else wants to fix this up properly.
>
> I'll take it.
Acknowledged. :)
--D
> -Bill
>
>
> >
> > >
> > > --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
> >
> > --
> > 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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web