linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting
@ 2020-10-14  6:54 Zhe Li
  2020-10-14  6:54 ` [PATCH 2/2] jffs2: fix can't set rp_size to zero " Zhe Li
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Zhe Li @ 2020-10-14  6:54 UTC (permalink / raw)
  To: dwmw2, richard
  Cc: lizhe67, wangfangpeng1, zhongjubin, linux-kernel, linux-mtd,
	qiuxi1, chenjie6

From: lizhe <lizhe67@huawei.com>

The jffs2 mount options will be ignored when remounting jffs2.
It can be easily reproduced with the steps listed below.
1. mount -t jffs2 -o compr=none /dev/mtdblockx /mnt
2. mount -o remount compr=zlib /mnt

Since ec10a24f10c8, the option parsing happens before fill_super and
then pass fc, which contains the options parsing results, to function
jffs2_reconfigure during remounting. But function jffs2_reconfigure do
not update c->mount_opts.

This patch add a function jffs2_update_mount_opts to fix this problem.

By the way, I notice that tmpfs use the same way to update remounting
options. If it is necessary to unify them?

Signed-off-by: lizhe <lizhe67@huawei.com>
---
 fs/jffs2/super.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 05d7878dfad1..4fd297bdf0f3 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -215,11 +215,28 @@ static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	return 0;
 }
 
+static inline void jffs2_update_mount_opts(struct fs_context *fc)
+{
+	struct jffs2_sb_info *new_c = fc->s_fs_info;
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(fc->root->d_sb);
+
+	mutex_lock(&c->alloc_sem);
+	if (new_c->mount_opts.override_compr) {
+		c->mount_opts.override_compr = new_c->mount_opts.override_compr;
+		c->mount_opts.compr = new_c->mount_opts.compr;
+	}
+	if (new_c->mount_opts.rp_size)
+		c->mount_opts.rp_size = new_c->mount_opts.rp_size;
+	mutex_unlock(&c->alloc_sem);
+}
+
 static int jffs2_reconfigure(struct fs_context *fc)
 {
 	struct super_block *sb = fc->root->d_sb;
 
 	sync_filesystem(sb);
+	jffs2_update_mount_opts(fc);
+
 	return jffs2_do_remount_fs(sb, fc);
 }
 
-- 
2.12.3


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH 2/2] jffs2: fix can't set rp_size to zero during remounting
  2020-10-14  6:54 [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting Zhe Li
@ 2020-10-14  6:54 ` Zhe Li
  2020-11-19  2:50   ` Zhe Li
  2020-11-06  2:30 ` [PATCH 1/2] jffs2: fix ignoring mounting options problem " Zhe Li
  2020-11-10 21:34 ` Richard Weinberger
  2 siblings, 1 reply; 6+ messages in thread
From: Zhe Li @ 2020-10-14  6:54 UTC (permalink / raw)
  To: dwmw2, richard
  Cc: lizhe67, wangfangpeng1, zhongjubin, linux-kernel, linux-mtd,
	qiuxi1, chenjie6

From: lizhe <lizhe67@huawei.com>

Set rp_size to zero will be ignore during remounting.

The method to identify whether we input a remounting option of
rp_size is to check if the rp_size input is zero. It can not work
well if we pass "rp_size=0".

This patch add a bool variable "set_rp_size" to fix this problem.

By the way, the problem of NULL pointer dereference in rp_size
fs option parsing showed at
https://lore.kernel.org/linux-mtd/20201012131204.59102-1-jamie@nuviainc.com/T/#u
should be applyed before this patch to make sure it works well.

Reported-by: Jubin Zhong <zhongjubin@huawei.com>
Signed-off-by: lizhe <lizhe67@huawei.com>
---
 fs/jffs2/jffs2_fs_sb.h | 1 +
 fs/jffs2/super.c       | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/jffs2/jffs2_fs_sb.h b/fs/jffs2/jffs2_fs_sb.h
index 778275f48a87..5a7091746f68 100644
--- a/fs/jffs2/jffs2_fs_sb.h
+++ b/fs/jffs2/jffs2_fs_sb.h
@@ -38,6 +38,7 @@ struct jffs2_mount_opts {
 	 * users. This is implemented simply by means of not allowing the
 	 * latter users to write to the file system if the amount if the
 	 * available space is less then 'rp_size'. */
+	bool set_rp_size;
 	unsigned int rp_size;
 };
 
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 4fd297bdf0f3..c523adaca79f 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -88,7 +88,7 @@ static int jffs2_show_options(struct seq_file *s, struct dentry *root)
 
 	if (opts->override_compr)
 		seq_printf(s, ",compr=%s", jffs2_compr_name(opts->compr));
-	if (opts->rp_size)
+	if (opts->set_rp_size)
 		seq_printf(s, ",rp_size=%u", opts->rp_size / 1024);
 
 	return 0;
@@ -206,6 +206,7 @@ static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		if (opt > c->mtd->size)
 			return invalf(fc, "jffs2: Too large reserve pool specified, max is %llu KB",
 				      c->mtd->size / 1024);
+		c->mount_opts.set_rp_size = true;
 		c->mount_opts.rp_size = opt;
 		break;
 	default:
@@ -225,8 +226,10 @@ static inline void jffs2_update_mount_opts(struct fs_context *fc)
 		c->mount_opts.override_compr = new_c->mount_opts.override_compr;
 		c->mount_opts.compr = new_c->mount_opts.compr;
 	}
-	if (new_c->mount_opts.rp_size)
+	if (new_c->mount_opts.set_rp_size) {
+		c->mount_opts.set_rp_size = new_c->mount_opts.set_rp_size;
 		c->mount_opts.rp_size = new_c->mount_opts.rp_size;
+	}
 	mutex_unlock(&c->alloc_sem);
 }
 
-- 
2.12.3


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting
  2020-10-14  6:54 [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting Zhe Li
  2020-10-14  6:54 ` [PATCH 2/2] jffs2: fix can't set rp_size to zero " Zhe Li
@ 2020-11-06  2:30 ` Zhe Li
  2020-11-10 21:34 ` Richard Weinberger
  2 siblings, 0 replies; 6+ messages in thread
From: Zhe Li @ 2020-11-06  2:30 UTC (permalink / raw)
  To: linux-mtd, lizhe67, dwmw2, richard
  Cc: zhongjubin, wangfangpeng1, linux-kernel, qiuxi1, chenjie6

Maintainer ping?

	Zhe

On Tue, 13 Oct 2020 15:22:37 +0800, Zhe Li wrote:
>
>The jffs2 mount options will be ignored when remounting jffs2.
>It can be easily reproduced with the steps listed below.
>1. mount -t jffs2 -o compr=none /dev/mtdblockx /mnt
>2. mount -o remount compr=zlib /mnt
>
>Since ec10a24f10c8, the option parsing happens before fill_super and
>then pass fc, which contains the options parsing results, to function
>jffs2_reconfigure during remounting. But function jffs2_reconfigure do
>not update c->mount_opts.
>
>This patch add a function jffs2_update_mount_opts to fix this problem.
>
>By the way, I notice that tmpfs use the same way to update remounting
>options. If it is necessary to unify them?
>
>Signed-off-by: lizhe <lizhe67@huawei.com>
>---
> fs/jffs2/super.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
>diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
>index 05d7878dfad1..4fd297bdf0f3 100644
>--- a/fs/jffs2/super.c
>+++ b/fs/jffs2/super.c
>@@ -215,11 +215,28 @@ static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param)
> 	return 0;
> }
> 
>+static inline void jffs2_update_mount_opts(struct fs_context *fc)
>+{
>+	struct jffs2_sb_info *new_c = fc->s_fs_info;
>+	struct jffs2_sb_info *c = JFFS2_SB_INFO(fc->root->d_sb);
>+
>+	mutex_lock(&c->alloc_sem);
>+	if (new_c->mount_opts.override_compr) {
>+		c->mount_opts.override_compr = new_c->mount_opts.override_compr;
>+		c->mount_opts.compr = new_c->mount_opts.compr;
>+	}
>+	if (new_c->mount_opts.rp_size)
>+		c->mount_opts.rp_size = new_c->mount_opts.rp_size;
>+	mutex_unlock(&c->alloc_sem);
>+}
>+
> static int jffs2_reconfigure(struct fs_context *fc)
> {
> 	struct super_block *sb = fc->root->d_sb;
> 
> 	sync_filesystem(sb);
>+	jffs2_update_mount_opts(fc);
>+
> 	return jffs2_do_remount_fs(sb, fc);
> }
> 
>-- 
>2.12.3
>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting
  2020-10-14  6:54 [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting Zhe Li
  2020-10-14  6:54 ` [PATCH 2/2] jffs2: fix can't set rp_size to zero " Zhe Li
  2020-11-06  2:30 ` [PATCH 1/2] jffs2: fix ignoring mounting options problem " Zhe Li
@ 2020-11-10 21:34 ` Richard Weinberger
  2 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2020-11-10 21:34 UTC (permalink / raw)
  To: Zhe Li
  Cc: qiuxi1, Richard Weinberger, LKML, linux-mtd, wangfangpeng1,
	zhongjubin, David Woodhouse, chenjie6

On Wed, Oct 14, 2020 at 9:01 AM Zhe Li <lizhe67@huawei.com> wrote:
>
> From: lizhe <lizhe67@huawei.com>
>
> The jffs2 mount options will be ignored when remounting jffs2.
> It can be easily reproduced with the steps listed below.
> 1. mount -t jffs2 -o compr=none /dev/mtdblockx /mnt
> 2. mount -o remount compr=zlib /mnt
>
> Since ec10a24f10c8, the option parsing happens before fill_super and
> then pass fc, which contains the options parsing results, to function
> jffs2_reconfigure during remounting. But function jffs2_reconfigure do
> not update c->mount_opts.
>
> This patch add a function jffs2_update_mount_opts to fix this problem.

Oh, a regression. Thanks for fixing.

> By the way, I notice that tmpfs use the same way to update remounting
> options. If it is necessary to unify them?

If possible, sure. Maybe you can find a way to put the logic into fs/libfs.c

-- 
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH 2/2] jffs2: fix can't set rp_size to zero during remounting
  2020-10-14  6:54 ` [PATCH 2/2] jffs2: fix can't set rp_size to zero " Zhe Li
@ 2020-11-19  2:50   ` Zhe Li
  2020-11-23  8:18     ` Richard Weinberger
  0 siblings, 1 reply; 6+ messages in thread
From: Zhe Li @ 2020-11-19  2:50 UTC (permalink / raw)
  To: lizhe67, richard, dwmw2
  Cc: qiuxi1, zhongjubin, linux-kernel, linux-mtd, wangfangpeng1, chenjie6

Maintainer ping?

	Zhe

On Tue, 13 Oct 2020 19:41:30 +0800, Zhe Li wrote:
>
>Set rp_size to zero will be ignore during remounting.
>
>The method to identify whether we input a remounting option of
>rp_size is to check if the rp_size input is zero. It can not work
>well if we pass "rp_size=0".
>
>This patch add a bool variable "set_rp_size" to fix this problem.
>
>By the way, the problem of NULL pointer dereference in rp_size
>fs option parsing showed at
>https://lore.kernel.org/linux-mtd/20201012131204.59102-1-jamie@nuviainc.com/T/#u
>should be applyed before this patch to make sure it works well.
>
>Reported-by: Jubin Zhong <zhongjubin@huawei.com>
>Signed-off-by: lizhe <lizhe67@huawei.com>
>---
> fs/jffs2/jffs2_fs_sb.h | 1 +
> fs/jffs2/super.c       | 7 +++++--
> 2 files changed, 6 insertions(+), 2 deletions(-)
>
>diff --git a/fs/jffs2/jffs2_fs_sb.h b/fs/jffs2/jffs2_fs_sb.h
>index 778275f48a87..5a7091746f68 100644
>--- a/fs/jffs2/jffs2_fs_sb.h
>+++ b/fs/jffs2/jffs2_fs_sb.h
>@@ -38,6 +38,7 @@ struct jffs2_mount_opts {
> 	 * users. This is implemented simply by means of not allowing the
> 	 * latter users to write to the file system if the amount if the
> 	 * available space is less then 'rp_size'. */
>+	bool set_rp_size;
> 	unsigned int rp_size;
> };
> 
>diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
>index 4fd297bdf0f3..c523adaca79f 100644
>--- a/fs/jffs2/super.c
>+++ b/fs/jffs2/super.c
>@@ -88,7 +88,7 @@ static int jffs2_show_options(struct seq_file *s, struct dentry *root)
> 
> 	if (opts->override_compr)
> 		seq_printf(s, ",compr=%s", jffs2_compr_name(opts->compr));
>-	if (opts->rp_size)
>+	if (opts->set_rp_size)
> 		seq_printf(s, ",rp_size=%u", opts->rp_size / 1024);
> 
> 	return 0;
>@@ -206,6 +206,7 @@ static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param)
> 		if (opt > c->mtd->size)
> 			return invalf(fc, "jffs2: Too large reserve pool specified, max is %llu KB",
> 				      c->mtd->size / 1024);
>+		c->mount_opts.set_rp_size = true;
> 		c->mount_opts.rp_size = opt;
> 		break;
> 	default:
>@@ -225,8 +226,10 @@ static inline void jffs2_update_mount_opts(struct fs_context *fc)
> 		c->mount_opts.override_compr = new_c->mount_opts.override_compr;
> 		c->mount_opts.compr = new_c->mount_opts.compr;
> 	}
>-	if (new_c->mount_opts.rp_size)
>+	if (new_c->mount_opts.set_rp_size) {
>+		c->mount_opts.set_rp_size = new_c->mount_opts.set_rp_size;
> 		c->mount_opts.rp_size = new_c->mount_opts.rp_size;
>+	}
> 	mutex_unlock(&c->alloc_sem);
> }
> 
>-- 
>2.12.3
>

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH 2/2] jffs2: fix can't set rp_size to zero during remounting
  2020-11-19  2:50   ` Zhe Li
@ 2020-11-23  8:18     ` Richard Weinberger
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2020-11-23  8:18 UTC (permalink / raw)
  To: Zhe Li
  Cc: wangfangpeng1, Richard Weinberger, LKML, linux-mtd, qiuxi1,
	zhongjubin, David Woodhouse, chenjie6

On Thu, Nov 19, 2020 at 3:59 AM Zhe Li <lizhe67@huawei.com> wrote:
>
> Maintainer ping?

Didn't I reply to this series?
/me double checks sent folder.

-- 
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2020-11-23  8:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14  6:54 [PATCH 1/2] jffs2: fix ignoring mounting options problem during remounting Zhe Li
2020-10-14  6:54 ` [PATCH 2/2] jffs2: fix can't set rp_size to zero " Zhe Li
2020-11-19  2:50   ` Zhe Li
2020-11-23  8:18     ` Richard Weinberger
2020-11-06  2:30 ` [PATCH 1/2] jffs2: fix ignoring mounting options problem " Zhe Li
2020-11-10 21:34 ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).