linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: reiserfs: Fix possible null-pointer dereferences in remove_from_transaction()
@ 2019-07-26  8:38 Jia-Ju Bai
  2019-07-26 22:54 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2019-07-26  8:38 UTC (permalink / raw)
  To: jack, akpm, arnd, linux.bhar, hariprasad.kelam
  Cc: reiserfs-devel, linux-kernel, Jia-Ju Bai

In remove_from_transaction(), there is an if statement on line 3447 to
check whether bh is NULL:
    if (bh)

When bh is NULL, it is used on line 3450:
    clear_buffer_journaled(bh);
and lines 3453-3456:
    clear_buffer_journal_dirty(bh);
    clear_buffer_dirty(bh);
    clear_buffer_journal_test(bh);
    put_bh(bh);

Thus, possible null-pointer dereferences may occur.

To fix these bugs, bh is checked before being used.

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

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 fs/reiserfs/journal.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 4517a1394c6f..d115578597b6 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -3444,12 +3444,13 @@ static int remove_from_transaction(struct super_block *sb,
 	if (cn == journal->j_last) {
 		journal->j_last = cn->prev;
 	}
-	if (bh)
+	if (bh) {
 		remove_journal_hash(sb, journal->j_hash_table, NULL,
 				    bh->b_blocknr, 0);
-	clear_buffer_journaled(bh);	/* don't log this one */
+		clear_buffer_journaled(bh);	/* don't log this one */
+	}
 
-	if (!already_cleaned) {
+	if (!already_cleaned && bh) {
 		clear_buffer_journal_dirty(bh);
 		clear_buffer_dirty(bh);
 		clear_buffer_journal_test(bh);
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs: reiserfs: Fix possible null-pointer dereferences in remove_from_transaction()
  2019-07-26  8:38 [PATCH] fs: reiserfs: Fix possible null-pointer dereferences in remove_from_transaction() Jia-Ju Bai
@ 2019-07-26 22:54 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2019-07-26 22:54 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: jack, arnd, linux.bhar, hariprasad.kelam, reiserfs-devel, linux-kernel

On Fri, 26 Jul 2019 16:38:38 +0800 Jia-Ju Bai <baijiaju1990@gmail.com> wrote:

> In remove_from_transaction(), there is an if statement on line 3447 to
> check whether bh is NULL:
>     if (bh)

We already know that bh != NULL here.

	cn = get_journal_hash_dev(sb, journal->j_hash_table, blocknr);
	if (!cn || !cn->bh) {
		return ret;
	}
	bh = cn->bh;


Please prepare a patch to remove the unneeded test?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-26 22:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-26  8:38 [PATCH] fs: reiserfs: Fix possible null-pointer dereferences in remove_from_transaction() Jia-Ju Bai
2019-07-26 22:54 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).