linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix list_del corruption if compressors initialized failed
@ 2022-10-27 12:49 Zhang Xiaoxu
  2022-10-27 12:49 ` [PATCH 1/2] jffs2: Use function instead of macro when initialize compressors Zhang Xiaoxu
  2022-10-27 12:49 ` [PATCH 2/2] jffs2: Fix list_del corruption if compressors initialized failed Zhang Xiaoxu
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Xiaoxu @ 2022-10-27 12:49 UTC (permalink / raw)
  To: zhangxiaoxu5, linux-mtd, richard, dwmw2


Zhang Xiaoxu (2):
  jffs2: Use function instead of macro when initialize compressors
  jffs2: Fix list_del corruption if compressors initialized failed

 fs/jffs2/compr.c | 50 ++++++++++++++++++++++++++++--------------------
 fs/jffs2/compr.h | 26 +++++++++++++++++++------
 2 files changed, 49 insertions(+), 27 deletions(-)

-- 
2.31.1


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

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

* [PATCH 1/2] jffs2: Use function instead of macro when initialize compressors
  2022-10-27 12:49 [PATCH 0/2] Fix list_del corruption if compressors initialized failed Zhang Xiaoxu
@ 2022-10-27 12:49 ` Zhang Xiaoxu
  2022-10-27 12:49 ` [PATCH 2/2] jffs2: Fix list_del corruption if compressors initialized failed Zhang Xiaoxu
  1 sibling, 0 replies; 3+ messages in thread
From: Zhang Xiaoxu @ 2022-10-27 12:49 UTC (permalink / raw)
  To: zhangxiaoxu5, linux-mtd, richard, dwmw2

The initialized compressors should be released if one of them
initialize fail, this is the pre-patch for fix the problem, use
function instead of the macro in jffs2_compressors_init() to
simplify the codes, no functional change intended.

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 fs/jffs2/compr.c | 17 +----------------
 fs/jffs2/compr.h | 26 ++++++++++++++++++++------
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c
index 4849a4c9a0e2..afe74c65f1e4 100644
--- a/fs/jffs2/compr.c
+++ b/fs/jffs2/compr.c
@@ -365,19 +365,12 @@ void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig)
 int __init jffs2_compressors_init(void)
 {
 /* Registering compressors */
-#ifdef CONFIG_JFFS2_ZLIB
 	jffs2_zlib_init();
-#endif
-#ifdef CONFIG_JFFS2_RTIME
 	jffs2_rtime_init();
-#endif
-#ifdef CONFIG_JFFS2_RUBIN
 	jffs2_rubinmips_init();
 	jffs2_dynrubin_init();
-#endif
-#ifdef CONFIG_JFFS2_LZO
 	jffs2_lzo_init();
-#endif
+
 /* Setting default compression mode */
 #ifdef CONFIG_JFFS2_CMODE_NONE
 	jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
@@ -401,18 +394,10 @@ int __init jffs2_compressors_init(void)
 int jffs2_compressors_exit(void)
 {
 /* Unregistering compressors */
-#ifdef CONFIG_JFFS2_LZO
 	jffs2_lzo_exit();
-#endif
-#ifdef CONFIG_JFFS2_RUBIN
 	jffs2_dynrubin_exit();
 	jffs2_rubinmips_exit();
-#endif
-#ifdef CONFIG_JFFS2_RTIME
 	jffs2_rtime_exit();
-#endif
-#ifdef CONFIG_JFFS2_ZLIB
 	jffs2_zlib_exit();
-#endif
 	return 0;
 }
diff --git a/fs/jffs2/compr.h b/fs/jffs2/compr.h
index 5e91d578f4ed..3716b6b7924c 100644
--- a/fs/jffs2/compr.h
+++ b/fs/jffs2/compr.h
@@ -88,18 +88,32 @@ int jffs2_rubinmips_init(void);
 void jffs2_rubinmips_exit(void);
 int jffs2_dynrubin_init(void);
 void jffs2_dynrubin_exit(void);
+#else
+static inline int jffs2_rubinmips_init(void) { return 0; }
+static inline void jffs2_rubinmips_exit(void) {}
+static inline int jffs2_dynrubin_init(void) { return 0; }
+static inline void jffs2_dynrubin_exit(void) {}
 #endif
 #ifdef CONFIG_JFFS2_RTIME
-int jffs2_rtime_init(void);
-void jffs2_rtime_exit(void);
+extern int jffs2_rtime_init(void);
+extern void jffs2_rtime_exit(void);
+#else
+static inline int jffs2_rtime_init(void) { return 0; }
+static inline void jffs2_rtime_exit(void) {}
 #endif
 #ifdef CONFIG_JFFS2_ZLIB
-int jffs2_zlib_init(void);
-void jffs2_zlib_exit(void);
+extern int jffs2_zlib_init(void);
+extern void jffs2_zlib_exit(void);
+#else
+static inline int jffs2_zlib_init(void) { return 0; }
+static inline void jffs2_zlib_exit(void) {}
 #endif
 #ifdef CONFIG_JFFS2_LZO
-int jffs2_lzo_init(void);
-void jffs2_lzo_exit(void);
+extern int jffs2_lzo_init(void);
+extern void jffs2_lzo_exit(void);
+#else
+static inline int jffs2_lzo_init(void) { return 0; }
+static inline void jffs2_lzo_exit(void) {}
 #endif
 
 #endif /* __JFFS2_COMPR_H__ */
-- 
2.31.1


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

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

* [PATCH 2/2] jffs2: Fix list_del corruption if compressors initialized failed
  2022-10-27 12:49 [PATCH 0/2] Fix list_del corruption if compressors initialized failed Zhang Xiaoxu
  2022-10-27 12:49 ` [PATCH 1/2] jffs2: Use function instead of macro when initialize compressors Zhang Xiaoxu
@ 2022-10-27 12:49 ` Zhang Xiaoxu
  1 sibling, 0 replies; 3+ messages in thread
From: Zhang Xiaoxu @ 2022-10-27 12:49 UTC (permalink / raw)
  To: zhangxiaoxu5, linux-mtd, richard, dwmw2

There is a list_del corruption when remove the jffs2 module:

  list_del corruption, ffffffffa0623e60->next is NULL
  WARNING: CPU: 6 PID: 6332 at lib/list_debug.c:49 __list_del_entry_valid+0x98/0x130
  Modules linked in: jffs2(-) ]
  CPU: 6 PID: 6332 Comm: rmmod Tainted: G        W          6.1.0-rc2+ #5
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 04/01/2014
  RIP: 0010:__list_del_entry_valid+0x98/0x130
  ...
  Call Trace:
   <TASK>
   jffs2_unregister_compressor+0x3e/0xe0 [jffs2]
   jffs2_zlib_exit+0x11/0x30 [jffs2]
   jffs2_compressors_exit+0x1e/0x30 [jffs2]
   exit_jffs2_fs+0x16/0x44f [jffs2]
   __do_sys_delete_module.constprop.0+0x244/0x370
   do_syscall_64+0x35/0x80
   entry_SYSCALL_64_after_hwframe+0x46/0xb0

If one of the compressor initialize failed, the module always insert
success since jffs2_compressors_init() always return success, then
something bad may happen during remove the module.

For this scenario, let's insmod failed.

Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 fs/jffs2/compr.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c
index afe74c65f1e4..764f19dec3f0 100644
--- a/fs/jffs2/compr.c
+++ b/fs/jffs2/compr.c
@@ -364,12 +364,24 @@ void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig)
 
 int __init jffs2_compressors_init(void)
 {
+	int ret = 0;
 /* Registering compressors */
-	jffs2_zlib_init();
-	jffs2_rtime_init();
-	jffs2_rubinmips_init();
-	jffs2_dynrubin_init();
-	jffs2_lzo_init();
+	ret = jffs2_zlib_init();
+	if (ret)
+		goto exit;
+	ret = jffs2_rtime_init();
+	if (ret)
+		goto exit_zlib;
+	ret = jffs2_rubinmips_init();
+	if (ret)
+		goto exit_rtime;
+	ret = jffs2_dynrubin_init();
+	if (ret)
+		goto exit_runinmips;
+	ret = jffs2_lzo_init();
+	if (ret)
+		goto exit_dynrubin;
+
 
 /* Setting default compression mode */
 #ifdef CONFIG_JFFS2_CMODE_NONE
@@ -389,6 +401,17 @@ int __init jffs2_compressors_init(void)
 #endif
 #endif
 	return 0;
+
+exit_dynrubin:
+	jffs2_dynrubin_exit();
+exit_runinmips:
+	jffs2_rubinmips_exit();
+exit_rtime:
+	jffs2_rtime_exit();
+exit_zlib:
+	jffs2_zlib_exit();
+exit:
+	return ret;
 }
 
 int jffs2_compressors_exit(void)
-- 
2.31.1


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

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

end of thread, other threads:[~2022-10-27 11:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 12:49 [PATCH 0/2] Fix list_del corruption if compressors initialized failed Zhang Xiaoxu
2022-10-27 12:49 ` [PATCH 1/2] jffs2: Use function instead of macro when initialize compressors Zhang Xiaoxu
2022-10-27 12:49 ` [PATCH 2/2] jffs2: Fix list_del corruption if compressors initialized failed Zhang Xiaoxu

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).