Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

jffs2: fix use after free in jffs2_sum_write_data()

clang static analysis reports this problem

fs/jffs2/summary.c:794:31: warning: Use of memory after it is freed
c->summary->sum_list_head = temp->u.next;
^~~~~~~~~~~~

In jffs2_sum_write_data(), in a loop summary data is handles a node at
a time. When it has written out the node it is removed the summary list,
and the node is deleted. In the corner case when a
JFFS2_FEATURE_RWCOMPAT_COPY is seen, a call is made to
jffs2_sum_disable_collecting(). jffs2_sum_disable_collecting() deletes
the whole list which conflicts with the loop's deleting the list by parts.

To preserve the old behavior of stopping the write midway, bail out of
the loop after disabling summary collection.

Fixes: 6171586a7ae5 ("[JFFS2] Correct handling of JFFS2_FEATURE_RWCOMPAT_COPY nodes.")
Signed-off-by: Tom Rix <trix@redhat.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Tom Rix and committed by
Richard Weinberger
19646447 3b638f99

+3
+3
fs/jffs2/summary.c
··· 783 783 dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n", 784 784 je16_to_cpu(temp->u.nodetype)); 785 785 jffs2_sum_disable_collecting(c->summary); 786 + /* The above call removes the list, nothing more to do */ 787 + goto bail_rwcompat; 786 788 } else { 787 789 BUG(); /* unknown node in summary information */ 788 790 } ··· 796 794 797 795 c->summary->sum_num--; 798 796 } 797 + bail_rwcompat: 799 798 800 799 jffs2_sum_reset_collected(c->summary); 801 800