]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
jffs2: Fix possible null-pointer dereferences in jffs2_add_frag_to_fragtree()
authorJia-Ju Bai <baijiaju1990@gmail.com>
Wed, 24 Jul 2019 02:46:58 +0000 (10:46 +0800)
committerRichard Weinberger <richard@nod.at>
Sun, 15 Sep 2019 20:42:10 +0000 (22:42 +0200)
In jffs2_add_frag_to_fragtree(), there is an if statement on line 223 to
check whether "this" is NULL:
    if (this)

When "this" is NULL, it is used at several places, such as on line 249:
    if (this->node)
and on line 260:
    if (newfrag->ofs > this->ofs)

Thus possible null-pointer dereferences may occur.

To fix these bugs, -EINVAL is returned when "this" is NULL.

These bugs are found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/jffs2/nodelist.c

index b86c78d178c60a3af10f6ae4c688d6acce8f8dbf..021a4a2190eeb2a1500610b1f8e74a09e83787c4 100644 (file)
@@ -226,7 +226,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
                lastend = this->ofs + this->size;
        } else {
                dbg_fragtree2("lookup gave no frag\n");
-               lastend = 0;
+               return -EINVAL;
        }
 
        /* See if we ran off the end of the fragtree */