linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Logan Gunthorpe <logang@deltatee.com>
To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
	Song Liu <song@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	Donald Buczek <buczek@molgen.mpg.de>,
	Guoqing Jiang <guoqing.jiang@linux.dev>, Xiao Ni <xni@redhat.com>,
	Stephen Bates <sbates@raithlin.com>,
	Martin Oliveira <Martin.Oliveira@eideticom.com>,
	David Sloan <David.Sloan@eideticom.com>,
	Logan Gunthorpe <logang@deltatee.com>
Subject: [PATCH v3 06/11] md/raid5-cache: Clear conf->log after finishing work
Date: Thu,  2 Jun 2022 12:18:12 -0600	[thread overview]
Message-ID: <20220602181818.50729-7-logang@deltatee.com> (raw)
In-Reply-To: <20220602181818.50729-1-logang@deltatee.com>

A NULL pointer dereferlence on conf->log is seen randomly with
the mdadm test 21raid5cache. Kasan reporst:

BUG: KASAN: null-ptr-deref in r5l_reclaimable_space+0xf5/0x140
Read of size 8 at addr 0000000000000860 by task md0_reclaim/3086

Call Trace:
  dump_stack_lvl+0x5a/0x74
  kasan_report.cold+0x5f/0x1a9
  __asan_load8+0x69/0x90
  r5l_reclaimable_space+0xf5/0x140
  r5l_do_reclaim+0xf4/0x5e0
  r5l_reclaim_thread+0x69/0x3b0
  md_thread+0x1a2/0x2c0
  kthread+0x177/0x1b0
  ret_from_fork+0x22/0x30

This is caused by conf->log being cleared in r5l_exit_log() before
stopping the reclaim thread.

To fix this, clear conf->log after the reclaim_thread is unregistered
and after flushing disable_writeback_work.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
 drivers/md/raid5-cache.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
index 48020d36b334..d6461d4814ab 100644
--- a/drivers/md/raid5-cache.c
+++ b/drivers/md/raid5-cache.c
@@ -3167,12 +3167,13 @@ void r5l_exit_log(struct r5conf *conf)
 
 	lockdep_assert_held(&conf->mddev->reconfig_mutex);
 
-	conf->log = NULL;
-
 	/* Ensure disable_writeback_work wakes up and exits */
 	wake_up(&conf->mddev->sb_wait);
 	flush_work(&log->disable_writeback_work);
 	md_unregister_thread(&log->reclaim_thread);
+
+	conf->log = NULL;
+
 	mempool_exit(&log->meta_pool);
 	bioset_exit(&log->bs);
 	mempool_exit(&log->io_pool);
-- 
2.30.2


  parent reply	other threads:[~2022-06-02 18:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-02 18:18 [PATCH v3 00/11] Bug fixes for mdadm tests Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 01/11] md/raid5-log: Drop extern decorators for function prototypes Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 02/11] md/raid5-ppl: Drop unused argument from ppl_handle_flush_request() Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 03/11] md/raid5: Ensure array is suspended for calls to log_exit() Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 04/11] md/raid5-cache: Take mddev_lock in r5c_journal_mode_show() Logan Gunthorpe
2022-06-03  6:39   ` Christoph Hellwig
2022-06-03 21:47     ` Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 05/11] md/raid5-cache: Drop RCU usage of conf->log Logan Gunthorpe
2022-06-03  6:43   ` Christoph Hellwig
2022-06-02 18:18 ` Logan Gunthorpe [this message]
2022-06-03  6:43   ` [PATCH v3 06/11] md/raid5-cache: Clear conf->log after finishing work Christoph Hellwig
2022-06-02 18:18 ` [PATCH v3 07/11] md/raid5-cache: Annotate pslot with __rcu notation Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 08/11] md: Use enum for overloaded magic numbers used by mddev->curr_resync Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 09/11] md: Ensure resync is reported after it starts Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 10/11] md: Notify sysfs sync_completed in md_reap_sync_thread() Logan Gunthorpe
2022-06-02 18:18 ` [PATCH v3 11/11] md/raid5-ppl: Fix argument order in bio_alloc_bioset() Logan Gunthorpe
2022-06-03  6:45   ` Christoph Hellwig

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=20220602181818.50729-7-logang@deltatee.com \
    --to=logang@deltatee.com \
    --cc=David.Sloan@eideticom.com \
    --cc=Martin.Oliveira@eideticom.com \
    --cc=buczek@molgen.mpg.de \
    --cc=guoqing.jiang@linux.dev \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=sbates@raithlin.com \
    --cc=song@kernel.org \
    --cc=xni@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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).