Linux-mtd Archive on
 help / color / Atom feed
From: Anmol Karn <>
Subject: [Linux-kernel-mentees] [PATCH] fs: jffs2: super: Fix null pointer dereference in jffs2_parse_param()
Date: Sun,  4 Oct 2020 02:03:10 +0530
Message-ID: <> (raw)

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 

Signed-off-by: Anmol Karn <>
 fs/jffs2/super.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 05d7878dfad1..f4ce67ac8486 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -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);

Linux MTD discussion mailing list

                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-mtd Archive on

Archives are clonable:
	git clone --mirror linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ \
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone