Re: [patch set 4.19.6] BFS updates
From: Tigran Aivazian
Date: Mon Dec 03 2018 - 04:55:41 EST
Re-sending the patches with the "Cc: stable@xxxxxxxxxxxxxxx" included
in the sign-off area, as per Option 1 of the rules Greg referred me
to. I hope that now I have done everything by the rules.
On Sun, 2 Dec 2018 at 21:42, Tigran Aivazian <aivazian.tigran@xxxxxxxxx> wrote:
>
> just wanted to add: although the subject says "4.19.6" the patches
> apply perfectly to the top of "torvalds/linux" tree from github.
> On Sun, 2 Dec 2018 at 21:01, Tigran Aivazian <aivazian.tigran@xxxxxxxxx> wrote:
> >
> > Hi Linus,
> >
> > I attached two incremental patches for BFS:
> >
> > 1. Make inode bitmap allocation static (applies on top of 4.19.6)
> > 2. Strengthen the superblock sanity checking code (applies on top of 1. above)
> >
> > Kind regards,
> > Tigran
From: Tigran Aivazian <aivazian.tigran@xxxxxxxxx>
Subject: [PATCH 4.19.6 1/2] BFS updates
Make in-core inode bitmap static part of superblock info structure an.
print a warning when mounting a BFS filesystem created with "-N 512"
option as only 510 files can be created in the root directory.
Signed-off-by: Tigran Aivazian <aivazian.tigran@xxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
bfs.h | 9 ++++++++-
inode.c | 27 +++++++++++----------------
2 files changed, 19 insertions(+), 17 deletions(-)
--- fs/bfs/bfs.h.0 2018-12-02 20:33:02.252710291 +0000
+++ fs/bfs/bfs.h 2018-12-02 20:34:34.041246489 +0000
@@ -8,6 +8,13 @@
#include <linux/bfs_fs.h>
+/* In theory BFS supports up to 512 inodes, numbered from 2 (for /) up to 513 inclusive.
+ In actual fact, attempting to create the 512th inode (i.e. inode No. 513 or file No. 511)
+ will fail with ENOSPC in bfs_add_entry(): the root directory cannot contain so many entries, counting '..'.
+ So, mkfs.bfs(8) should really limit its -N option to 511 and not 512. For now, we just print a warning
+ if a filesystem is mounted with such "impossible to fill up" number of inodes */
+#define BFS_MAX_LASTI 513
+
/*
* BFS file system in-core superblock info
*/
@@ -17,7 +24,7 @@
unsigned long si_freei;
unsigned long si_lf_eblk;
unsigned long si_lasti;
- unsigned long *si_imap;
+ DECLARE_BITMAP(si_imap, BFS_MAX_LASTI+1);
struct mutex bfs_lock;
};
--- fs/bfs/inode.c.0 2018-12-02 20:34:03.211740877 +0000
+++ fs/bfs/inode.c 2018-12-02 20:36:54.508963813 +0000
@@ -214,7 +214,6 @@
return;
mutex_destroy(&info->bfs_lock);
- kfree(info->si_imap);
kfree(info);
s->s_fs_info = NULL;
}
@@ -322,7 +321,7 @@
struct buffer_head *bh, *sbh;
struct bfs_super_block *bfs_sb;
struct inode *inode;
- unsigned i, imap_len;
+ unsigned i;
struct bfs_sb_info *info;
int ret = -EINVAL;
unsigned long i_sblock, i_eblock, i_eoff, s_size;
@@ -356,13 +355,11 @@
goto out1;
}
- info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) /
- sizeof(struct bfs_inode)
- + BFS_ROOT_INO - 1;
- imap_len = (info->si_lasti / 8) + 1;
- info->si_imap = kzalloc(imap_len, GFP_KERNEL | __GFP_NOWARN);
- if (!info->si_imap) {
- printf("Cannot allocate %u bytes\n", imap_len);
+ info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) / sizeof(struct bfs_inode) + BFS_ROOT_INO - 1;
+ if (info->si_lasti == BFS_MAX_LASTI)
+ printf("WARNING: filesystem %s was created with 512 inodes, the real maximum is 511, mounting anyway\n", s->s_id);
+ else if (info->si_lasti > BFS_MAX_LASTI) {
+ printf("Impossible last inode number %lu > %d on %s\n", info->si_lasti, BFS_MAX_LASTI, s->s_id);
goto out1;
}
for (i = 0; i < BFS_ROOT_INO; i++)
@@ -372,12 +369,12 @@
inode = bfs_iget(s, BFS_ROOT_INO);
if (IS_ERR(inode)) {
ret = PTR_ERR(inode);
- goto out2;
+ goto out1;
}
s->s_root = d_make_root(inode);
if (!s->s_root) {
ret = -ENOMEM;
- goto out2;
+ goto out1;
}
info->si_blocks = (le32_to_cpu(bfs_sb->s_end) + 1) >> BFS_BSIZE_BITS;
@@ -391,7 +388,7 @@
if (!bh) {
printf("Last block not available: %lu\n", info->si_blocks - 1);
ret = -EIO;
- goto out3;
+ goto out2;
}
brelse(bh);
@@ -429,7 +426,7 @@
brelse(bh);
ret = -EIO;
- goto out3;
+ goto out2;
}
if (!di->i_ino) {
@@ -448,11 +445,9 @@
bfs_dump_imap("read_super", s);
return 0;
-out3:
+out2:
dput(s->s_root);
s->s_root = NULL;
-out2:
- kfree(info->si_imap);
out1:
brelse(sbh);
out:
From: Tigran Aivazian <aivazian.tigran@xxxxxxxxx>
Subject: [PATCH 4.19.6 2/2] BFS updates
Strengthen the superblock sanity checking (supersedes the code
that went into 4.19.6).
Signed-off-by: Tigran Aivazian <aivazian.tigran@xxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- fs/bfs/inode.c.0 2018-12-02 20:49:00.525461354 +0000
+++ fs/bfs/inode.c 2018-12-02 20:49:51.054686779 +0000
@@ -350,7 +350,7 @@
s->s_magic = BFS_MAGIC;
if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end) ||
- le32_to_cpu(bfs_sb->s_start) < BFS_BSIZE) {
+ le32_to_cpu(bfs_sb->s_start) < sizeof(struct bfs_super_block) + sizeof(struct bfs_dirent)) {
printf("Superblock is corrupted\n");
goto out1;
}