All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs
@ 2022-03-15 13:28 ` Dongliang Mu
  0 siblings, 0 replies; 6+ messages in thread
From: Dongliang Mu @ 2022-03-15 13:28 UTC (permalink / raw)
  To: Gao Xiang, Chao Yu; +Cc: Dongliang Mu, linux-erofs, linux-kernel

From: Dongliang Mu <mudongliangabcd@gmail.com>

Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
is triggered by injecting fault in kobject_init_and_add of
erofs_unregister_sysfs.

Fix this by adding sanity check for kobject in erofs_unregister_sysfs

Note that I've tested the patch and the crash does not occur any more.

Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 fs/erofs/sysfs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index dac252bc9228..f3babf1e6608 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -221,9 +221,11 @@ void erofs_unregister_sysfs(struct super_block *sb)
 {
 	struct erofs_sb_info *sbi = EROFS_SB(sb);
 
-	kobject_del(&sbi->s_kobj);
-	kobject_put(&sbi->s_kobj);
-	wait_for_completion(&sbi->s_kobj_unregister);
+	if (sbi->s_kobj.state_in_sysfs) {
+		kobject_del(&sbi->s_kobj);
+		kobject_put(&sbi->s_kobj);
+		wait_for_completion(&sbi->s_kobj_unregister);
+	}
 }
 
 int __init erofs_init_sysfs(void)
-- 
2.25.1


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

* [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs
@ 2022-03-15 13:28 ` Dongliang Mu
  0 siblings, 0 replies; 6+ messages in thread
From: Dongliang Mu @ 2022-03-15 13:28 UTC (permalink / raw)
  To: Gao Xiang, Chao Yu; +Cc: linux-erofs, Dongliang Mu, linux-kernel

From: Dongliang Mu <mudongliangabcd@gmail.com>

Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
is triggered by injecting fault in kobject_init_and_add of
erofs_unregister_sysfs.

Fix this by adding sanity check for kobject in erofs_unregister_sysfs

Note that I've tested the patch and the crash does not occur any more.

Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 fs/erofs/sysfs.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index dac252bc9228..f3babf1e6608 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -221,9 +221,11 @@ void erofs_unregister_sysfs(struct super_block *sb)
 {
 	struct erofs_sb_info *sbi = EROFS_SB(sb);
 
-	kobject_del(&sbi->s_kobj);
-	kobject_put(&sbi->s_kobj);
-	wait_for_completion(&sbi->s_kobj_unregister);
+	if (sbi->s_kobj.state_in_sysfs) {
+		kobject_del(&sbi->s_kobj);
+		kobject_put(&sbi->s_kobj);
+		wait_for_completion(&sbi->s_kobj_unregister);
+	}
 }
 
 int __init erofs_init_sysfs(void)
-- 
2.25.1


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

* Re: [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs
  2022-03-15 13:28 ` Dongliang Mu
@ 2022-03-15 13:34   ` Gao Xiang
  -1 siblings, 0 replies; 6+ messages in thread
From: Gao Xiang @ 2022-03-15 13:34 UTC (permalink / raw)
  To: Dongliang Mu; +Cc: Gao Xiang, Chao Yu, Dongliang Mu, linux-erofs, linux-kernel

On Tue, Mar 15, 2022 at 09:28:14PM +0800, Dongliang Mu wrote:
> From: Dongliang Mu <mudongliangabcd@gmail.com>
> 
> Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
> is triggered by injecting fault in kobject_init_and_add of
> erofs_unregister_sysfs.
> 
> Fix this by adding sanity check for kobject in erofs_unregister_sysfs
> 
> Note that I've tested the patch and the crash does not occur any more.
> 
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

> ---
>  fs/erofs/sysfs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
> index dac252bc9228..f3babf1e6608 100644
> --- a/fs/erofs/sysfs.c
> +++ b/fs/erofs/sysfs.c
> @@ -221,9 +221,11 @@ void erofs_unregister_sysfs(struct super_block *sb)
>  {
>  	struct erofs_sb_info *sbi = EROFS_SB(sb);
>  
> -	kobject_del(&sbi->s_kobj);
> -	kobject_put(&sbi->s_kobj);
> -	wait_for_completion(&sbi->s_kobj_unregister);
> +	if (sbi->s_kobj.state_in_sysfs) {
> +		kobject_del(&sbi->s_kobj);
> +		kobject_put(&sbi->s_kobj);
> +		wait_for_completion(&sbi->s_kobj_unregister);
> +	}
>  }
>  
>  int __init erofs_init_sysfs(void)
> -- 
> 2.25.1

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

* Re: [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs
@ 2022-03-15 13:34   ` Gao Xiang
  0 siblings, 0 replies; 6+ messages in thread
From: Gao Xiang @ 2022-03-15 13:34 UTC (permalink / raw)
  To: Dongliang Mu; +Cc: linux-erofs, Dongliang Mu, linux-kernel

On Tue, Mar 15, 2022 at 09:28:14PM +0800, Dongliang Mu wrote:
> From: Dongliang Mu <mudongliangabcd@gmail.com>
> 
> Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
> is triggered by injecting fault in kobject_init_and_add of
> erofs_unregister_sysfs.
> 
> Fix this by adding sanity check for kobject in erofs_unregister_sysfs
> 
> Note that I've tested the patch and the crash does not occur any more.
> 
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

> ---
>  fs/erofs/sysfs.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
> index dac252bc9228..f3babf1e6608 100644
> --- a/fs/erofs/sysfs.c
> +++ b/fs/erofs/sysfs.c
> @@ -221,9 +221,11 @@ void erofs_unregister_sysfs(struct super_block *sb)
>  {
>  	struct erofs_sb_info *sbi = EROFS_SB(sb);
>  
> -	kobject_del(&sbi->s_kobj);
> -	kobject_put(&sbi->s_kobj);
> -	wait_for_completion(&sbi->s_kobj_unregister);
> +	if (sbi->s_kobj.state_in_sysfs) {
> +		kobject_del(&sbi->s_kobj);
> +		kobject_put(&sbi->s_kobj);
> +		wait_for_completion(&sbi->s_kobj_unregister);
> +	}
>  }
>  
>  int __init erofs_init_sysfs(void)
> -- 
> 2.25.1

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

* Re: [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs
  2022-03-15 13:28 ` Dongliang Mu
@ 2022-03-16  1:45   ` Chao Yu
  -1 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-03-16  1:45 UTC (permalink / raw)
  To: Dongliang Mu, Gao Xiang; +Cc: Dongliang Mu, linux-erofs, linux-kernel

On 2022/3/15 21:28, Dongliang Mu wrote:
> From: Dongliang Mu <mudongliangabcd@gmail.com>
> 
> Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
> is triggered by injecting fault in kobject_init_and_add of
> erofs_unregister_sysfs.
> 
> Fix this by adding sanity check for kobject in erofs_unregister_sysfs
> 
> Note that I've tested the patch and the crash does not occur any more.
> 
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

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

* Re: [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs
@ 2022-03-16  1:45   ` Chao Yu
  0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2022-03-16  1:45 UTC (permalink / raw)
  To: Dongliang Mu, Gao Xiang; +Cc: linux-erofs, Dongliang Mu, linux-kernel

On 2022/3/15 21:28, Dongliang Mu wrote:
> From: Dongliang Mu <mudongliangabcd@gmail.com>
> 
> Syzkaller hit 'WARNING: kobject bug in erofs_unregister_sysfs'. This bug
> is triggered by injecting fault in kobject_init_and_add of
> erofs_unregister_sysfs.
> 
> Fix this by adding sanity check for kobject in erofs_unregister_sysfs
> 
> Note that I've tested the patch and the crash does not occur any more.
> 
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

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

end of thread, other threads:[~2022-03-16  1:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15 13:28 [PATCH] fs: erofs: add sanity check for kobject in erofs_unregister_sysfs Dongliang Mu
2022-03-15 13:28 ` Dongliang Mu
2022-03-15 13:34 ` Gao Xiang
2022-03-15 13:34   ` Gao Xiang
2022-03-16  1:45 ` Chao Yu
2022-03-16  1:45   ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.