Skip to contentSkip to conversation

jffs2: fix double-free of f->target in jffs2_alloc_inode()

PATCH In review Deepanshu Kartikey 2 participants 7 messages Aug 23 – Sep 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jffs2: fix double-free of f->target in jffs2_alloc_inode()

jffs2_alloc_inode() does not initialize f->target before returning the new inode. It is normally cleared later by jffs2_init_inode_info(), called from jffs2_iget(), but that runs only after alloc_inode() has already returned successfully.

If inode_init_always() fails in between, alloc_inode() calls ->free_inode() directly on the half-initialized inode. jffs2_free_inode() then does kfree(f->target) on whatever stale value was left in the reused slab object, which can be a pointer that was already freed, causing a double-free.

Initialize f->target to NULL in jffs2_alloc_inode() to close this window, and clear it in jffs2_free_inode() after freeing it so a reused or re-freed object can never carry a dangling pointer.

Fixes 4fdcfab5b553 ("jffs2: fix use-after-free on symlink traversal")
Reported-by [email protected]
---
 fs/jffs2/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/jffs2/super.c +2 -0
index 81396a092ba8..30d753d4c263 100644
@@ -42,6 +42,7 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb)
 	f = alloc_inode_sb(sb, jffs2_inode_cachep, GFP_KERNEL);
 	if (!f)
 		return NULL;
+	f->target = NULL;
 	return &f->vfs_inode;
 }
 
@@ -50,6 +51,7 @@ static void jffs2_free_inode(struct inode *inode)
 	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 
 	kfree(f->target);
+	f->target = NULL;
 	kmem_cache_free(jffs2_inode_cachep, f);
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 45 lines · Deepanshu Kartikey

jffs2_alloc_inode() does not initialize f->target before returning the new inode. It is normally cleared later by jffs2_init_inode_info(), called from jffs2_iget(), but that runs only after alloc_inode() has already returned successfully.

If inode_init_always() fails in between, alloc_inode() calls ->free_inode() directly on the half-initialized inode. jffs2_free_inode() then does kfree(f->target) on whatever stale value was left in the reused slab object, which can be a pointer that was already freed, causing a double-free.

Initialize f->target to NULL in jffs2_alloc_inode() to close this window, and clear it in jffs2_free_inode() after freeing it so a reused or re-freed object can never carry a dangling pointer.

Fixes 4fdcfab5b553 ("jffs2: fix use-after-free on symlink traversal")
Reported-by [email protected]
---
 fs/jffs2/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/jffs2/super.c +2 -1
index 81396a092ba8..30d753d4c263 100644
@@ -42,6 +42,7 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb)
        f = alloc_inode_sb(sb, jffs2_inode_cachep, GFP_KERNEL);
        if (!f)
                return NULL;
+       f->target = NULL;
        return &f->vfs_inode;
 }
 
@@ -50,6 +51,7 @@ static void jffs2_free_inode(struct inode *inode)
        struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 
        kfree(f->target);
+       f->target = NULL;
        kmem_cache_free(jffs2_inode_cachep, f);
 }
 
--
Quoted 2 lines

2.34.1

Gentle Reminder. Please let me know the status of this patch.

Thanks

Deepanshu

#2 lore raw

Am Sat, Sep 12, 2026, 03:08 schrieb Deepanshu Kartikey <[email protected]>:

Quoted 46 lines
Quoted 44 lines · Deepanshu Kartikey

jffs2_alloc_inode() does not initialize f->target before returning the new inode. It is normally cleared later by jffs2_init_inode_info(), called from jffs2_iget(), but that runs only after alloc_inode() has already returned successfully.

If inode_init_always() fails in between, alloc_inode() calls ->free_inode() directly on the half-initialized inode. jffs2_free_inode() then does kfree(f->target) on whatever stale value was left in the reused slab object, which can be a pointer that was already freed, causing a double-free.

Initialize f->target to NULL in jffs2_alloc_inode() to close this window, and clear it in jffs2_free_inode() after freeing it so a reused or re-freed object can never carry a dangling pointer.

Fixes 4fdcfab5b553 ("jffs2: fix use-after-free on symlink traversal")
Reported-by [email protected]
---
 fs/jffs2/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/jffs2/super.c +2 -0
index 81396a092ba8..30d753d4c263 100644
@@ -42,6 +42,7 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb)
        f = alloc_inode_sb(sb, jffs2_inode_cachep, GFP_KERNEL);
        if (!f)
                return NULL;
+       f->target = NULL;
        return &f->vfs_inode;
 }
 
@@ -50,6 +51,7 @@ static void jffs2_free_inode(struct inode *inode)
        struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 
        kfree(f->target);
+       f->target = NULL;
        kmem_cache_free(jffs2_inode_cachep, f);
 }
 
Quoted 5 lines
Quoted 3 lines

--
2.34.1

Gentle Reminder. Please let me know the status of this patch.

We got lot's of identical fixes this issue.
I had no time yet to sort out who was the first.
This is maybe the first report with fix suggestions, but the reporter vanished:
https://lore.kernel.org/linux-mtd/CAFLxGvyZO_EDo-YM_EybZG3u7aNUoNiThhvbhQCrOPD7mPV6GA@mail.gmail.com/

Thanks,
//richard

#3 lore raw
Quoted 55 lines · Richard Weinberger

Am Sat, Sep 12, 2026, 03:08 schrieb Deepanshu Kartikey <[email protected]>:

Quoted 46 lines
Quoted 44 lines · Deepanshu Kartikey

jffs2_alloc_inode() does not initialize f->target before returning the new inode. It is normally cleared later by jffs2_init_inode_info(), called from jffs2_iget(), but that runs only after alloc_inode() has already returned successfully.

If inode_init_always() fails in between, alloc_inode() calls ->free_inode() directly on the half-initialized inode. jffs2_free_inode() then does kfree(f->target) on whatever stale value was left in the reused slab object, which can be a pointer that was already freed, causing a double-free.

Initialize f->target to NULL in jffs2_alloc_inode() to close this window, and clear it in jffs2_free_inode() after freeing it so a reused or re-freed object can never carry a dangling pointer.

Fixes 4fdcfab5b553 ("jffs2: fix use-after-free on symlink traversal")
Reported-by [email protected]
---
 fs/jffs2/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/jffs2/super.c +2 -0
index 81396a092ba8..30d753d4c263 100644
@@ -42,6 +42,7 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb)
        f = alloc_inode_sb(sb, jffs2_inode_cachep, GFP_KERNEL);
        if (!f)
                return NULL;
+       f->target = NULL;
        return &f->vfs_inode;
 }
 
@@ -50,6 +51,7 @@ static void jffs2_free_inode(struct inode *inode)
        struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 
        kfree(f->target);
+       f->target = NULL;
        kmem_cache_free(jffs2_inode_cachep, f);
 }
 
Quoted 5 lines
Quoted 3 lines

--
2.34.1

Gentle Reminder. Please let me know the status of this patch.

Quoted 9 lines

We got lot's of identical fixes this issue.
I had no time yet to sort out who was the first.
This is maybe the first report with fix suggestions, but the reporter vanished:
https://lore.kernel.org/linux-mtd/CAFLxGvyZO_EDo-YM_EybZG3u7aNUoNiThhvbhQCrOPD7mPV6GA@mail.gmail.com/

Thanks,
//richard

I feel the patch you are pointing at fixes a different kind of issue ?

#4 lore raw

Am Sat, Sep 12, 2026, 10:00 schrieb Deepanshu Kartikey <[email protected]>:

Quoted 2 lines · Richard Weinberger

I feel the patch you are pointing at fixes a different kind of issue ?

Well, different symptoms of a common root cause.

Thanks,
//richard

#5 lore raw
Quoted 9 lines · Richard Weinberger

Am Sat, Sep 12, 2026, 10:00 schrieb Deepanshu Kartikey <[email protected]>:

Quoted 2 lines · Richard Weinberger

I feel the patch you are pointing at fixes a different kind of issue ?

Well, different symptoms of a common root cause.

Thanks,
//richard

Totally understood this. But it is good to have a defensive check so that there is no dangling pointer. It will prevent future [UAF, double free bugs].

Thanks

Deepanshu

#6 lore raw
Quoted 12 lines · Deepanshu Kartikey
Quoted 9 lines · Richard Weinberger

Am Sat, Sep 12, 2026, 10:00 schrieb Deepanshu Kartikey <[email protected]>:

Quoted 2 lines · Richard Weinberger

I feel the patch you are pointing at fixes a different kind of issue ?

Well, different symptoms of a common root cause.

Thanks,
//richard

Quoted 6 lines

Totally understood this. But it is good to have a defensive check so that there is no dangling pointer. It will prevent future [UAF, double free bugs].

Thanks

Deepanshu

Let me know the status of this patch

Thanks

Deepanshu