Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp7729774ioo; Fri, 3 Jun 2022 12:13:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiQnCZLZG0LB+K7TYmuFWn9GEcn2FGWE+wPsyOl/AaVSmwAUMlcd8SOuWpfyQK9qtwMlC0 X-Received: by 2002:a17:90b:3e8a:b0:1e0:51fa:516b with SMTP id rj10-20020a17090b3e8a00b001e051fa516bmr47630705pjb.151.1654283582179; Fri, 03 Jun 2022 12:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654283582; cv=none; d=google.com; s=arc-20160816; b=QmnQCEe0d7hvHRx3HFKJybcSvhmwCcVf3wGgQI3M5uCRQAlLzFQo7FU1bTH4vz933A chGtEJxRqGmB6wBNW6T5AErmeYSCVvcGAdaKsclG37uTlloIUFpXv5PyLcYLjZKmCWCG uoxer8BToYjlSrAEefvjQIi58XeSY3rvH/ArzyanJH/zuY9JzLzH2GbDLyqmmX3H/FQj xk4mnIBAzUusDCwwKol6RNGnAO6Lz2hxPQfn9LnXGW8KHIzgiUHmOocW4tz0upGENApk 4ysj5EpYKvX9Fjxsl4Vm/MecBggj96eCX6ddS556W/FHZomC5kh+xAdR5XB9dN0q+a5M MhFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=YM20HAJdOXoRL1faWOIVlFFFqomMZGpBCaDU6mKZzz8=; b=kvy/oV9h8FfcfBnM7Ook2U1p4b+wpmA8LaxqT/WDBPySeDyFBWlCyVyBZi5dxVdnhZ TUCDTxl6+D0TxEBmdwp9QUMBCHsQ+DukCn096T+JsevzlkWJxxD7AXt+G/3TY8DYOmwV mKGxMJbPxwoUr9+XtsxmuY2UrOswvPQdOXAokQjnUUuSi7IBNi8PLLGezKDmzIg3JtIV OAYGmNYsHcqSv23xEdJAVAsnGTWzut1cE7QU/TJn0ZumhJQDhMiKyMHhI2KNS8V2Y/S3 ppPZ6DO2JgZsN0OEWYApQ9nzF9944M2KEel2U4hQZd6GqM+MsSxhGmILtD3uXPY6YP+9 cmzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=IAE4jJ0n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f2-20020a170902f38200b001562b0bf47bsi9335536ple.58.2022.06.03.12.12.48; Fri, 03 Jun 2022 12:13:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=IAE4jJ0n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234347AbiFBSTS (ORCPT + 99 others); Thu, 2 Jun 2022 14:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237946AbiFBSSg (ORCPT ); Thu, 2 Jun 2022 14:18:36 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA4614E3A1; Thu, 2 Jun 2022 11:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=YM20HAJdOXoRL1faWOIVlFFFqomMZGpBCaDU6mKZzz8=; b=IAE4jJ0nvde/H8qIAL+0S9Ao8+ 2Lnf1dQ/nMGqRZbvwcyOq9Vg75GbemZaZ+JUX21lfqfIqsUUaA9gNJ7PP5NtspPcI9OUO/FQLLQS/ Fy2iz3J1rgDTK3dD82/5iFGDzJisK2AeTNe5o2Q9p/6fiqEh4Z+LOhPM2sWhfNxVEk4fsoOKSQsY4 KVvl1KpaYKlD52bcBjnXSY/5BkC+IaDmAJv4DXuFfPfTn7nserWen+bljsbBdExlCzTbrywZzeUkq Wn+KDFbk7FFHLrdMrMg0r2LyhyXV5Ayxz0lUyfxZnSZh2KNEGgyYy4+ykUG3h4X9UDaYGTMT45RDC C15E//5Q==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nwpOo-00EPmY-IO; Thu, 02 Jun 2022 12:18:23 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1nwpOm-000DDS-9d; Thu, 02 Jun 2022 12:18:20 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu Cc: Christoph Hellwig , Donald Buczek , Guoqing Jiang , Xiao Ni , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe Date: Thu, 2 Jun 2022 12:18:12 -0600 Message-Id: <20220602181818.50729-7-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220602181818.50729-1-logang@deltatee.com> References: <20220602181818.50729-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, song@kernel.org, hch@infradead.org, buczek@molgen.mpg.de, guoqing.jiang@linux.dev, xni@redhat.com, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 06/11] md/raid5-cache: Clear conf->log after finishing work X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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