public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] ubifs: avoid memory corruption during ubifsmount
@ 2018-06-25 11:54 Patrice Chotard
  2018-06-25 20:47 ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Patrice Chotard @ 2018-06-25 11:54 UTC (permalink / raw)
  To: u-boot

Sometimes, at boot time, following issue appears:
Error reading superblock on volume 'ubi0:boot' errno=-22!

This error is coming from wrong ubi_num and wrong ubi_id in the superblock.
(ubi_num = -1 and vol_id = -1).
It appears that following line in sget function:
hlist_add_head(&s->s_instances, &type->fs_supers);
corrupts the superblock structure.

By checking ubifs source code, s_instances parameter is not used anymore.
So, by setting this parameter and the associated source code under
__UBOOT__ compilation switch solves this issue.

Signed-off-by: Christophe Kerello <christophe.kerello@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---

 fs/ubifs/super.c | 8 ++++----
 fs/ubifs/ubifs.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index abdef1e6ab8d..9603163d8a04 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -2360,7 +2360,9 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)
 		return ERR_PTR(err);
 	}
 
+#ifndef __UBOOT__
 	INIT_HLIST_NODE(&s->s_instances);
+#endif
 	INIT_LIST_HEAD(&s->s_inodes);
 	s->s_time_gran = 1000000000;
 	s->s_flags = flags;
@@ -2429,14 +2431,12 @@ retry:
 #ifndef __UBOOT__
 	strlcpy(s->s_id, type->name, sizeof(s->s_id));
 	list_add_tail(&s->s_list, &super_blocks);
-#else
-	strncpy(s->s_id, type->name, sizeof(s->s_id));
-#endif
 	hlist_add_head(&s->s_instances, &type->fs_supers);
-#ifndef __UBOOT__
 	spin_unlock(&sb_lock);
 	get_filesystem(type);
 	register_shrinker(&s->s_shrink);
+#else
+	strncpy(s->s_id, type->name, sizeof(s->s_id));
 #endif
 	return s;
 }
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 78c3a68216e1..512fdaa1444d 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -316,8 +316,8 @@ struct super_block {
 	struct backing_dev_info *s_bdi;
 #endif
 	struct mtd_info		*s_mtd;
-	struct hlist_node	s_instances;
 #ifndef __UBOOT__
+	struct hlist_node	s_instances;
 	struct quota_info	s_dquot;	/* Diskquota specific options */
 #endif
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] ubifs: avoid memory corruption during ubifsmount
@ 2018-06-11 13:22 Patrice Chotard
  0 siblings, 0 replies; 5+ messages in thread
From: Patrice Chotard @ 2018-06-11 13:22 UTC (permalink / raw)
  To: u-boot

From: Christophe Kerello <christophe.kerello@st.com>

Sometimes, at boot time, following issue appears:
Error reading superblock on volume 'ubi0:boot' errno=-22!

This error is coming from wrong ubi_num and wrong ubi_id in the superblock.
(ubi_num = -1 and vol_id = -1).
It appears that following line in sget function:
hlist_add_head(&s->s_instances, &type->fs_supers);
corrupts the superblock structure.

By checking ubifs source code, s_instances parameter is not used anymore.
So, by setting this parameter and the associated source code under
__UBOOT__ compilation switch solves this issue.

Signed-off-by: Christophe Kerello <christophe.kerello@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---

 fs/ubifs/super.c | 8 ++++----
 fs/ubifs/ubifs.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index abdef1e6ab8d..9603163d8a04 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -2360,7 +2360,9 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)
 		return ERR_PTR(err);
 	}
 
+#ifndef __UBOOT__
 	INIT_HLIST_NODE(&s->s_instances);
+#endif
 	INIT_LIST_HEAD(&s->s_inodes);
 	s->s_time_gran = 1000000000;
 	s->s_flags = flags;
@@ -2429,14 +2431,12 @@ retry:
 #ifndef __UBOOT__
 	strlcpy(s->s_id, type->name, sizeof(s->s_id));
 	list_add_tail(&s->s_list, &super_blocks);
-#else
-	strncpy(s->s_id, type->name, sizeof(s->s_id));
-#endif
 	hlist_add_head(&s->s_instances, &type->fs_supers);
-#ifndef __UBOOT__
 	spin_unlock(&sb_lock);
 	get_filesystem(type);
 	register_shrinker(&s->s_shrink);
+#else
+	strncpy(s->s_id, type->name, sizeof(s->s_id));
 #endif
 	return s;
 }
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 78c3a68216e1..512fdaa1444d 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -316,8 +316,8 @@ struct super_block {
 	struct backing_dev_info *s_bdi;
 #endif
 	struct mtd_info		*s_mtd;
-	struct hlist_node	s_instances;
 #ifndef __UBOOT__
+	struct hlist_node	s_instances;
 	struct quota_info	s_dquot;	/* Diskquota specific options */
 #endif
 
-- 
1.9.1

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

end of thread, other threads:[~2018-06-26 13:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-25 11:54 [U-Boot] [PATCH] ubifs: avoid memory corruption during ubifsmount Patrice Chotard
2018-06-25 20:47 ` Richard Weinberger
2018-06-26 13:01   ` Patrice CHOTARD
2018-06-26 13:18     ` Richard Weinberger
  -- strict thread matches above, loose matches on Subject: below --
2018-06-11 13:22 Patrice Chotard

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