From: Nathan Chancellor <natechancellor@gmail.com> To: trix@redhat.com Cc: dwmw2@infradead.org, richard@nod.at, ndesaulniers@google.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] jffs2: fix use after free in jffs2_sum_write_data() Date: Mon, 4 Jan 2021 15:16:07 -0700 [thread overview] Message-ID: <20210104221607.GA1985645@ubuntu-m3-large-x86> (raw) In-Reply-To: <20201230145604.1586486-1-trix@redhat.com> On Wed, Dec 30, 2020 at 06:56:04AM -0800, trix@redhat.com wrote: > From: Tom Rix <trix@redhat.com> > > 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> > --- > fs/jffs2/summary.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c > index be7c8a6a5748..4fe64519870f 100644 > --- a/fs/jffs2/summary.c > +++ b/fs/jffs2/summary.c > @@ -783,6 +783,8 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock > dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n", > je16_to_cpu(temp->u.nodetype)); > jffs2_sum_disable_collecting(c->summary); > + /* The above call removes the list, nothing more to do */ > + goto bail_rwcompat; > } else { > BUG(); /* unknown node in summary information */ > } > @@ -794,6 +796,7 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock > > c->summary->sum_num--; > } > + bail_rwcompat: > > jffs2_sum_reset_collected(c->summary); > > -- > 2.27.0 >
WARNING: multiple messages have this Message-ID (diff)
From: Nathan Chancellor <natechancellor@gmail.com> To: trix@redhat.com Cc: richard@nod.at, ndesaulniers@google.com, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, linux-mtd@lists.infradead.org, dwmw2@infradead.org Subject: Re: [PATCH] jffs2: fix use after free in jffs2_sum_write_data() Date: Mon, 4 Jan 2021 15:16:07 -0700 [thread overview] Message-ID: <20210104221607.GA1985645@ubuntu-m3-large-x86> (raw) In-Reply-To: <20201230145604.1586486-1-trix@redhat.com> On Wed, Dec 30, 2020 at 06:56:04AM -0800, trix@redhat.com wrote: > From: Tom Rix <trix@redhat.com> > > 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> > --- > fs/jffs2/summary.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c > index be7c8a6a5748..4fe64519870f 100644 > --- a/fs/jffs2/summary.c > +++ b/fs/jffs2/summary.c > @@ -783,6 +783,8 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock > dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n", > je16_to_cpu(temp->u.nodetype)); > jffs2_sum_disable_collecting(c->summary); > + /* The above call removes the list, nothing more to do */ > + goto bail_rwcompat; > } else { > BUG(); /* unknown node in summary information */ > } > @@ -794,6 +796,7 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock > > c->summary->sum_num--; > } > + bail_rwcompat: > > jffs2_sum_reset_collected(c->summary); > > -- > 2.27.0 > ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2021-01-04 23:13 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-30 14:56 [PATCH] jffs2: fix use after free in jffs2_sum_write_data() trix 2020-12-30 14:56 ` trix 2021-01-04 22:16 ` Nathan Chancellor [this message] 2021-01-04 22:16 ` Nathan Chancellor
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: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210104221607.GA1985645@ubuntu-m3-large-x86 \ --to=natechancellor@gmail.com \ --cc=clang-built-linux@googlegroups.com \ --cc=dwmw2@infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=ndesaulniers@google.com \ --cc=richard@nod.at \ --cc=trix@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.