linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer
@ 2019-02-19 11:44 Colin King
  2019-02-19 14:02 ` Jan Kara
  0 siblings, 1 reply; 5+ messages in thread
From: Colin King @ 2019-02-19 11:44 UTC (permalink / raw)
  To: Jan Kara; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

There is a null check on the pointer bh to avoid a null pointer dereference
on bh->b_data however later bh is passed to mark_buffer_dirty that can also
cause a null pointer dereference on bh.  Avoid this potential null pointer
dereference by moving the call to mark_buffer_dirty inside the null checked
block.

Fixes: e8b4274735e4 ("udf: finalize integrity descriptor before writeback")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/udf/super.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index a6940d90bedd..b7e9a83d39db 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
 
 			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
 			udf_finalize_lvid(lvid);
-		}
 
-		/*
-		 * Blockdevice will be synced later so we don't have to submit
-		 * the buffer for IO
-		 */
-		mark_buffer_dirty(bh);
+			/*
+			 * Blockdevice will be synced later so we don't have
+			 * to submit the buffer for IO
+			 */
+			mark_buffer_dirty(bh);
+		}
 		sbi->s_lvid_dirty = 0;
 	}
 	mutex_unlock(&sbi->s_alloc_mutex);
-- 
2.20.1


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

* Re: [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer
  2019-02-19 11:44 [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer Colin King
@ 2019-02-19 14:02 ` Jan Kara
  2019-02-19 14:17   ` Steve Magnani
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2019-02-19 14:02 UTC (permalink / raw)
  To: Colin King; +Cc: Jan Kara, kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1610 bytes --]

On Tue 19-02-19 11:44:03, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> There is a null check on the pointer bh to avoid a null pointer dereference
> on bh->b_data however later bh is passed to mark_buffer_dirty that can also
> cause a null pointer dereference on bh.  Avoid this potential null pointer
> dereference by moving the call to mark_buffer_dirty inside the null checked
> block.
> 
> Fixes: e8b4274735e4 ("udf: finalize integrity descriptor before writeback")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks for the patch! In fact it is the 'if (bh)' check that's
unnecessarily defensive (we cannot have sbi->s_lvid_dirty and
!sbi->s_lvid_bh). So I'll just drop that check (attached patch).

								Honza

> ---
>  fs/udf/super.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index a6940d90bedd..b7e9a83d39db 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
>  
>  			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
>  			udf_finalize_lvid(lvid);
> -		}
>  
> -		/*
> -		 * Blockdevice will be synced later so we don't have to submit
> -		 * the buffer for IO
> -		 */
> -		mark_buffer_dirty(bh);
> +			/*
> +			 * Blockdevice will be synced later so we don't have
> +			 * to submit the buffer for IO
> +			 */
> +			mark_buffer_dirty(bh);
> +		}
>  		sbi->s_lvid_dirty = 0;
>  	}
>  	mutex_unlock(&sbi->s_alloc_mutex);
> -- 
> 2.20.1
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

[-- Attachment #2: 0001-udf-Drop-pointless-check-from-udf_sync_fs.patch --]
[-- Type: text/x-patch, Size: 1239 bytes --]

From a00eb52e3f2f815efa52a9e3bf1b730d86c05faa Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Tue, 19 Feb 2019 14:59:43 +0100
Subject: [PATCH] udf: Drop pointless check from udf_sync_fs()

The check if (bh) in udf_sync_fs() is pointless as we cannot have
sbi->s_lvid_dirty and !sbi->s_lvid_bh (as already asserted by
udf_updated_lvid()). So just drop the pointless check.

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/udf/super.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index a6940d90bedd..ffd8038ff728 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -2330,13 +2330,10 @@ static int udf_sync_fs(struct super_block *sb, int wait)
 	mutex_lock(&sbi->s_alloc_mutex);
 	if (sbi->s_lvid_dirty) {
 		struct buffer_head *bh = sbi->s_lvid_bh;
+		struct logicalVolIntegrityDesc *lvid;
 
-		if (bh) {
-			struct logicalVolIntegrityDesc *lvid;
-
-			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
-			udf_finalize_lvid(lvid);
-		}
+		lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
+		udf_finalize_lvid(lvid);
 
 		/*
 		 * Blockdevice will be synced later so we don't have to submit
-- 
2.16.4


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

* Re: [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer
  2019-02-19 14:02 ` Jan Kara
@ 2019-02-19 14:17   ` Steve Magnani
  2019-02-20  9:50     ` Jan Kara
  0 siblings, 1 reply; 5+ messages in thread
From: Steve Magnani @ 2019-02-19 14:17 UTC (permalink / raw)
  To: Jan Kara, Colin King; +Cc: Jan Kara, kernel-janitors, linux-kernel

On 2/19/19 8:02 AM, Jan Kara wrote:
> On Tue 19-02-19 11:44:03, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> There is a null check on the pointer bh to avoid a null pointer dereference
>> on bh->b_data however later bh is passed to mark_buffer_dirty that can also
>> cause a null pointer dereference on bh.  Avoid this potential null pointer
>> dereference by moving the call to mark_buffer_dirty inside the null checked
>> block.
>>
>> Fixes: e8b4274735e4 ("udf: finalize integrity descriptor before writeback")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> Thanks for the patch! In fact it is the 'if (bh)' check that's
> unnecessarily defensive (we cannot have sbi->s_lvid_dirty and
> !sbi->s_lvid_bh). So I'll just drop that check (attached patch).
>
> 								Honza
>
>> ---
>>   fs/udf/super.c | 12 ++++++------
>>   1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/udf/super.c b/fs/udf/super.c
>> index a6940d90bedd..b7e9a83d39db 100644
>> --- a/fs/udf/super.c
>> +++ b/fs/udf/super.c
>> @@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
>>   
>>   			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
>>   			udf_finalize_lvid(lvid);
>> -		}
>>   
>> -		/*
>> -		 * Blockdevice will be synced later so we don't have to submit
>> -		 * the buffer for IO
>> -		 */
>> -		mark_buffer_dirty(bh);
>> +			/*
>> +			 * Blockdevice will be synced later so we don't have
>> +			 * to submit the buffer for IO
>> +			 */
>> +			mark_buffer_dirty(bh);
>> +		}
>>   		sbi->s_lvid_dirty = 0;
>>   	}
>>   	mutex_unlock(&sbi->s_alloc_mutex);
>> -- 
>> 2.20.1
>>
Reviewed-by: Steven J. Magnani <steve@digidescorp.com>

Doh! Thanks for the catch Colin.

------------------------------------------------------------------------
  Steven J. Magnani               "I claim this network for MARS!
  www.digidescorp.com              Earthling, return my space modulator!"

  #include <standard.disclaimer>


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

* Re: [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer
  2019-02-19 14:17   ` Steve Magnani
@ 2019-02-20  9:50     ` Jan Kara
  2019-02-20 11:27       ` Steve Magnani
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2019-02-20  9:50 UTC (permalink / raw)
  To: Steve Magnani
  Cc: Jan Kara, Colin King, Jan Kara, kernel-janitors, linux-kernel

On Tue 19-02-19 08:17:09, Steve Magnani wrote:
> On 2/19/19 8:02 AM, Jan Kara wrote:
> > On Tue 19-02-19 11:44:03, Colin King wrote:
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > There is a null check on the pointer bh to avoid a null pointer dereference
> > > on bh->b_data however later bh is passed to mark_buffer_dirty that can also
> > > cause a null pointer dereference on bh.  Avoid this potential null pointer
> > > dereference by moving the call to mark_buffer_dirty inside the null checked
> > > block.
> > > 
> > > Fixes: e8b4274735e4 ("udf: finalize integrity descriptor before writeback")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > Thanks for the patch! In fact it is the 'if (bh)' check that's
> > unnecessarily defensive (we cannot have sbi->s_lvid_dirty and
> > !sbi->s_lvid_bh). So I'll just drop that check (attached patch).
> > 
> > 								Honza
> > 
> > > ---
> > >   fs/udf/super.c | 12 ++++++------
> > >   1 file changed, 6 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/fs/udf/super.c b/fs/udf/super.c
> > > index a6940d90bedd..b7e9a83d39db 100644
> > > --- a/fs/udf/super.c
> > > +++ b/fs/udf/super.c
> > > @@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
> > >   			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
> > >   			udf_finalize_lvid(lvid);
> > > -		}
> > > -		/*
> > > -		 * Blockdevice will be synced later so we don't have to submit
> > > -		 * the buffer for IO
> > > -		 */
> > > -		mark_buffer_dirty(bh);
> > > +			/*
> > > +			 * Blockdevice will be synced later so we don't have
> > > +			 * to submit the buffer for IO
> > > +			 */
> > > +			mark_buffer_dirty(bh);
> > > +		}
> > >   		sbi->s_lvid_dirty = 0;
> > >   	}
> > >   	mutex_unlock(&sbi->s_alloc_mutex);
> > > -- 
> > > 2.20.1
> > > 
> Reviewed-by: Steven J. Magnani <steve@digidescorp.com>

Is this Reviewed-by for my fixup or the Colin's? Because I've decided to
rather remove the 'if (bh)' check completely since it is pointless...

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer
  2019-02-20  9:50     ` Jan Kara
@ 2019-02-20 11:27       ` Steve Magnani
  0 siblings, 0 replies; 5+ messages in thread
From: Steve Magnani @ 2019-02-20 11:27 UTC (permalink / raw)
  To: Jan Kara; +Cc: Colin King, Jan Kara, kernel-janitors, linux-kernel


> On Feb 20, 2019, at 3:50 AM, Jan Kara <jack@suse.cz> wrote:
> 
>> On Tue 19-02-19 08:17:09, Steve Magnani wrote:
>>> On 2/19/19 8:02 AM, Jan Kara wrote:
>>>> On Tue 19-02-19 11:44:03, Colin King wrote:
>>>> From: Colin Ian King <colin.king@canonical.com>
>>>> 
>>>> There is a null check on the pointer bh to avoid a null pointer dereference
>>>> on bh->b_data however later bh is passed to mark_buffer_dirty that can also
>>>> cause a null pointer dereference on bh.  Avoid this potential null pointer
>>>> dereference by moving the call to mark_buffer_dirty inside the null checked
>>>> block.
>>>> 
>>>> Fixes: e8b4274735e4 ("udf: finalize integrity descriptor before writeback")
>>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>> Thanks for the patch! In fact it is the 'if (bh)' check that's
>>> unnecessarily defensive (we cannot have sbi->s_lvid_dirty and
>>> !sbi->s_lvid_bh). So I'll just drop that check (attached patch).
>>> 
>>>                                Honza
>>> 
>>>> ---
>>>>  fs/udf/super.c | 12 ++++++------
>>>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>>> 
>>>> diff --git a/fs/udf/super.c b/fs/udf/super.c
>>>> index a6940d90bedd..b7e9a83d39db 100644
>>>> --- a/fs/udf/super.c
>>>> +++ b/fs/udf/super.c
>>>> @@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
>>>>              lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
>>>>              udf_finalize_lvid(lvid);
>>>> -        }
>>>> -        /*
>>>> -         * Blockdevice will be synced later so we don't have to submit
>>>> -         * the buffer for IO
>>>> -         */
>>>> -        mark_buffer_dirty(bh);
>>>> +            /*
>>>> +             * Blockdevice will be synced later so we don't have
>>>> +             * to submit the buffer for IO
>>>> +             */
>>>> +            mark_buffer_dirty(bh);
>>>> +        }
>>>>          sbi->s_lvid_dirty = 0;
>>>>      }
>>>>      mutex_unlock(&sbi->s_alloc_mutex);
>>>> -- 
>>>> 2.20.1
>>>> 
>> Reviewed-by: Steven J. Magnani <steve@digidescorp.com>
> 
> Is this Reviewed-by for my fixup or the Colin's? Because I've decided to
> rather remove the 'if (bh)' check completely since it is pointless...
> 
>                                Honza
> -- 

Sorry, I realized on rereading that this could be ambiguous. The R-B is for your patch.

Steve

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

end of thread, other threads:[~2019-02-20 11:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-19 11:44 [PATCH][udf-next] udf: don't call mark_buffer_dirty on a null bh pointer Colin King
2019-02-19 14:02 ` Jan Kara
2019-02-19 14:17   ` Steve Magnani
2019-02-20  9:50     ` Jan Kara
2019-02-20 11:27       ` Steve Magnani

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).