All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tigran Aivazian <aivazian.tigran@gmail.com>
To: torvalds@linux-foundation.org,
	LKML <linux-kernel@vger.kernel.org>,
	stable@vger.kernel.org, gregkh@linuxfoundation.org
Subject: Re: [patch set 4.19.6] BFS updates
Date: Mon, 3 Dec 2018 09:55:23 +0000	[thread overview]
Message-ID: <CAK+_RLmJTrc3P0q0rzjoo4LD=g2cyA0eRwoVUtg-V8kPYEg7eg@mail.gmail.com> (raw)
In-Reply-To: <CAK+_RLk=WL1SxtNF7YRw5eLGjcCc9o2dcHodgFw7SoFPSm25Xw@mail.gmail.com>

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

Re-sending the patches with the "Cc: stable@vger.kernel.org" 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@gmail.com> 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@gmail.com> 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

[-- Attachment #2: bfs-4.19.6-1-of-2-static-inode-bitmap.patch --]
[-- Type: text/x-patch, Size: 3506 bytes --]

From: Tigran Aivazian <aivazian.tigran@gmail.com>
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@gmail.com>
Cc: stable@vger.kernel.org
---

 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:

[-- Attachment #3: bfs-4.19.6-2-of-2-strengthen-sanity-checking.patch --]
[-- Type: text/x-patch, Size: 771 bytes --]

From: Tigran Aivazian <aivazian.tigran@gmail.com>
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@gmail.com>
Cc: stable@vger.kernel.org
---

 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;
 	}

  reply	other threads:[~2018-12-03  9:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-02 21:01 [patch set 4.19.6] BFS updates Tigran Aivazian
2018-12-02 21:42 ` Tigran Aivazian
2018-12-03  9:55   ` Tigran Aivazian [this message]
2018-12-03 10:26     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK+_RLmJTrc3P0q0rzjoo4LD=g2cyA0eRwoVUtg-V8kPYEg7eg@mail.gmail.com' \
    --to=aivazian.tigran@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.