public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] fs: sysv: check sbi->s_firstdatazone in complete_read_super
@ 2022-03-30 10:42 Liu Shixin
  2022-03-30 15:42 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Shixin @ 2022-03-30 10:42 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel, Liu Shixin

sbi->s_firstinodezone is initialized to 2 and sbi->s_firstdatazone is read
from sbd. There's no guarantee that sbi->s_firstdatazone must bigger than
sbi->s_firstinodezone. If sbi->s_firstdatazone less than 2, the filesystem
can still be mounted unexpetly. At this point, sbi->s_ninodes flip to very
large value and this filesystem is broken. We can observe this by
executing 'df' command. When we execute, we will get an error message:
	"sysv_count_free_inodes: unable to read inode table"

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 fs/sysv/super.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/sysv/super.c b/fs/sysv/super.c
index d1def0771a40..3365a30dc1e0 100644
--- a/fs/sysv/super.c
+++ b/fs/sysv/super.c
@@ -312,7 +312,9 @@ static int complete_read_super(struct super_block *sb, int silent, int size)
 	sbi->s_firstinodezone = 2;
 
 	flavour_setup[sbi->s_type](sbi, &sb->s_max_links);
-	
+	if (sbi->s_firstdatazone < sbi->s_firstinodezone)
+		return 0;
+
 	sbi->s_ndatazones = sbi->s_nzones - sbi->s_firstdatazone;
 	sbi->s_inodes_per_block = bsize >> 6;
 	sbi->s_inodes_per_block_1 = (bsize >> 6)-1;
-- 
2.25.1


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

* Re: [PATCH -next] fs: sysv: check sbi->s_firstdatazone in complete_read_super
  2022-03-30 10:42 [PATCH -next] fs: sysv: check sbi->s_firstdatazone in complete_read_super Liu Shixin
@ 2022-03-30 15:42 ` Christoph Hellwig
  2022-03-31  3:49   ` Liu Shixin
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2022-03-30 15:42 UTC (permalink / raw)
  To: Liu Shixin; +Cc: Christoph Hellwig, linux-kernel

On Wed, Mar 30, 2022 at 06:42:15PM +0800, Liu Shixin wrote:
> sbi->s_firstinodezone is initialized to 2 and sbi->s_firstdatazone is read
> from sbd. There's no guarantee that sbi->s_firstdatazone must bigger than
> sbi->s_firstinodezone. If sbi->s_firstdatazone less than 2, the filesystem
> can still be mounted unexpetly. At this point, sbi->s_ninodes flip to very
> large value and this filesystem is broken. We can observe this by
> executing 'df' command. When we execute, we will get an error message:
> 	"sysv_count_free_inodes: unable to read inode table"

This looks fine.  Just curious: which variant of the sysv fs do you
use and what is the use case?

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

* Re: [PATCH -next] fs: sysv: check sbi->s_firstdatazone in complete_read_super
  2022-03-30 15:42 ` Christoph Hellwig
@ 2022-03-31  3:49   ` Liu Shixin
  0 siblings, 0 replies; 3+ messages in thread
From: Liu Shixin @ 2022-03-31  3:49 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel


The type I used is sysv v7.

I discovered this problem through a syzkaller use case. The use case first create a file
via memfd and bind it to loop0. Then mount it to a folder with type v7. No error is
reported for preceding operations. Finally when create a file, the warning in inc_nlink
is triggered. I want to look the filesystem information, so I execute 'df' command and
find this problem.

Btw, I think the warning may be a follow-up problem caused by the filesystem being
created or mounted incorrectly.

Thanks,

On 2022/3/30 23:42, Christoph Hellwig wrote:
> On Wed, Mar 30, 2022 at 06:42:15PM +0800, Liu Shixin wrote:
>> sbi->s_firstinodezone is initialized to 2 and sbi->s_firstdatazone is read
>> from sbd. There's no guarantee that sbi->s_firstdatazone must bigger than
>> sbi->s_firstinodezone. If sbi->s_firstdatazone less than 2, the filesystem
>> can still be mounted unexpetly. At this point, sbi->s_ninodes flip to very
>> large value and this filesystem is broken. We can observe this by
>> executing 'df' command. When we execute, we will get an error message:
>> 	"sysv_count_free_inodes: unable to read inode table"
> This looks fine.  Just curious: which variant of the sysv fs do you
> use and what is the use case?
> .
>


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

end of thread, other threads:[~2022-03-31  4:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-30 10:42 [PATCH -next] fs: sysv: check sbi->s_firstdatazone in complete_read_super Liu Shixin
2022-03-30 15:42 ` Christoph Hellwig
2022-03-31  3:49   ` Liu Shixin

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