public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] bcachefs: fix null-ptr-deref in have_stripes()
@ 2024-10-25 11:56 Jeongjun Park
  2024-10-25 16:54 ` Kent Overstreet
  0 siblings, 1 reply; 4+ messages in thread
From: Jeongjun Park @ 2024-10-25 11:56 UTC (permalink / raw)
  To: kent.overstreet
  Cc: linux-bcachefs, linux-kernel, syzbot+b468b9fef56949c3b528,
	Jeongjun Park

c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference
occurs, so you need to add code to check the variable.

Reported-by: syzbot+b468b9fef56949c3b528@syzkaller.appspotmail.com
Fixes: 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 fs/bcachefs/sb-downgrade.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/bcachefs/sb-downgrade.c b/fs/bcachefs/sb-downgrade.c
index ae715ff658e8..8767c33c2b51 100644
--- a/fs/bcachefs/sb-downgrade.c
+++ b/fs/bcachefs/sb-downgrade.c
@@ -143,6 +143,9 @@ UPGRADE_TABLE()
 
 static int have_stripes(struct bch_fs *c)
 {
+	if (IS_ERR_OR_NULL(c->btree_roots_known[BTREE_ID_stripes].b))
+		return 0;
+
 	return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
 }
 
--

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

* Re: [PATCH v2] bcachefs: fix null-ptr-deref in have_stripes()
  2024-10-25 11:56 [PATCH v2] bcachefs: fix null-ptr-deref in have_stripes() Jeongjun Park
@ 2024-10-25 16:54 ` Kent Overstreet
  2024-10-25 17:05   ` Alan Huang
  0 siblings, 1 reply; 4+ messages in thread
From: Kent Overstreet @ 2024-10-25 16:54 UTC (permalink / raw)
  To: Jeongjun Park; +Cc: linux-bcachefs, linux-kernel, syzbot+b468b9fef56949c3b528

On Fri, Oct 25, 2024 at 08:56:18PM +0900, Jeongjun Park wrote:
> c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference
> occurs, so you need to add code to check the variable.
> 
> Reported-by: syzbot+b468b9fef56949c3b528@syzkaller.appspotmail.com
> Fixes: 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>

This looks identical to the v1? It's already in my testing branch

(But it should be in my hotfix branch, doing that now)

> ---
>  fs/bcachefs/sb-downgrade.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/bcachefs/sb-downgrade.c b/fs/bcachefs/sb-downgrade.c
> index ae715ff658e8..8767c33c2b51 100644
> --- a/fs/bcachefs/sb-downgrade.c
> +++ b/fs/bcachefs/sb-downgrade.c
> @@ -143,6 +143,9 @@ UPGRADE_TABLE()
>  
>  static int have_stripes(struct bch_fs *c)
>  {
> +	if (IS_ERR_OR_NULL(c->btree_roots_known[BTREE_ID_stripes].b))
> +		return 0;
> +
>  	return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
>  }
>  
> --

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

* Re: [PATCH v2] bcachefs: fix null-ptr-deref in have_stripes()
  2024-10-25 16:54 ` Kent Overstreet
@ 2024-10-25 17:05   ` Alan Huang
  2024-10-25 17:17     ` Kent Overstreet
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Huang @ 2024-10-25 17:05 UTC (permalink / raw)
  To: Kent Overstreet
  Cc: Jeongjun Park, linux-bcachefs, LKML, syzbot+b468b9fef56949c3b528

On Oct 26, 2024, at 00:54, Kent Overstreet <kent.overstreet@linux.dev> wrote:
> 
> On Fri, Oct 25, 2024 at 08:56:18PM +0900, Jeongjun Park wrote:
>> c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference
>> occurs, so you need to add code to check the variable.
>> 
>> Reported-by: syzbot+b468b9fef56949c3b528@syzkaller.appspotmail.com
>> Fixes: 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
>> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> 
> This looks identical to the v1? It's already in my testing branch

This version fix the “Fixes" tag, the original one is:

"Fixes: ("bcachefs: metadata version bucket_stripe_sectors”)"

> 
> (But it should be in my hotfix branch, doing that now)
> 
>> ---
>> fs/bcachefs/sb-downgrade.c | 3 +++
>> 1 file changed, 3 insertions(+)
>> 
>> diff --git a/fs/bcachefs/sb-downgrade.c b/fs/bcachefs/sb-downgrade.c
>> index ae715ff658e8..8767c33c2b51 100644
>> --- a/fs/bcachefs/sb-downgrade.c
>> +++ b/fs/bcachefs/sb-downgrade.c
>> @@ -143,6 +143,9 @@ UPGRADE_TABLE()
>> 
>> static int have_stripes(struct bch_fs *c)
>> {
>> + if (IS_ERR_OR_NULL(c->btree_roots_known[BTREE_ID_stripes].b))
>> + return 0;
>> +
>> return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
>> }
>> 
>> --
> 


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

* Re: [PATCH v2] bcachefs: fix null-ptr-deref in have_stripes()
  2024-10-25 17:05   ` Alan Huang
@ 2024-10-25 17:17     ` Kent Overstreet
  0 siblings, 0 replies; 4+ messages in thread
From: Kent Overstreet @ 2024-10-25 17:17 UTC (permalink / raw)
  To: Alan Huang
  Cc: Jeongjun Park, linux-bcachefs, LKML, syzbot+b468b9fef56949c3b528

On Sat, Oct 26, 2024 at 01:05:50AM +0800, Alan Huang wrote:
> On Oct 26, 2024, at 00:54, Kent Overstreet <kent.overstreet@linux.dev> wrote:
> > 
> > On Fri, Oct 25, 2024 at 08:56:18PM +0900, Jeongjun Park wrote:
> >> c->btree_roots_known[i].b can be NULL. In this case, a NULL pointer dereference
> >> occurs, so you need to add code to check the variable.
> >> 
> >> Reported-by: syzbot+b468b9fef56949c3b528@syzkaller.appspotmail.com
> >> Fixes: 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
> >> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> > 
> > This looks identical to the v1? It's already in my testing branch
> 
> This version fix the “Fixes" tag, the original one is:
> 
> "Fixes: ("bcachefs: metadata version bucket_stripe_sectors”)"

thanks

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

end of thread, other threads:[~2024-10-25 17:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 11:56 [PATCH v2] bcachefs: fix null-ptr-deref in have_stripes() Jeongjun Park
2024-10-25 16:54 ` Kent Overstreet
2024-10-25 17:05   ` Alan Huang
2024-10-25 17:17     ` Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox