]> git.baikalelectronics.ru Git - kernel.git/commit
jffs2: fix use after free in jffs2_sum_write_data()
authorTom Rix <trix@redhat.com>
Wed, 30 Dec 2020 14:56:04 +0000 (06:56 -0800)
committerRichard Weinberger <richard@nod.at>
Fri, 12 Feb 2021 20:53:22 +0000 (21:53 +0100)
commit0a84d08c27f947616cb8af103a2ac8a588978302
tree4a0bf44a6db2070ca475fbc5de4b8b36d7dc37b0
parent7e7c13ee15d57775c3fa0b8ce59948c8fc3b370b
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: 03a91e90382f ("[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>
fs/jffs2/summary.c