Skip to contentSkip to conversation

fs: jffs2: super: Fix null pointer dereference in jffs2_parse_param()

PATCH New Anmol Karn 1 participant 1 message Oct 3, 2020

Subsystems (2)
lore
Share & tools
lore

Anmol Karn

author
#0 lore raw

PATCH 1/1 fs: jffs2: super: Fix null pointer dereference in jffs2_parse_param()

mtd is getting NULL dereferenced in jffs2_parse_param(), while checking condition for pool size when, case: opt is Opt_rp_size hits.

- fs/jffs2/super.c
The bug seems to get triggered in this line:

if (opt > c->mtd->size)

	return invalf(fc, "jffs2: Too large reserve pool specified, max is %llu KB",
				      c->mtd->size / 1024);

Fix this by adding a NULL check for 'c->mtd' device and return invalf(); which wraps errorf() and returns -EINVAL for convenience, which allows userspace to collect them directly.

---
 fs/jffs2/super.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/jffs2/super.c +4 -0
index 05d7878dfad1..f4ce67ac8486 100644
@@ -203,6 +203,10 @@ static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		if (result.uint_32 > UINT_MAX / 1024)
 			return invalf(fc, "jffs2: rp_size unrepresentable");
 		opt = result.uint_32 * 1024;
+
+		if (!c->mtd)
+			return invalf(fc, "jffs2: mtd device is NULL");
+
 		if (opt > c->mtd->size)
 			return invalf(fc, "jffs2: Too large reserve pool specified, max is %llu KB",
 				      c->mtd->size / 1024);
Signature · 1 line
2.28.0