Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2690045iof; Wed, 8 Jun 2022 10:00:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1B5AuOBdLrTIlLkmGx4WJZpsAABKnvhizkAwNUWZZM1oepeC24mXn2zPCtrz1tP7CZNQX X-Received: by 2002:a05:6a00:1146:b0:4c9:ede0:725a with SMTP id b6-20020a056a00114600b004c9ede0725amr35611592pfm.35.1654707629061; Wed, 08 Jun 2022 10:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707629; cv=none; d=google.com; s=arc-20160816; b=F1Oq4vNyoXkhDLBDj/aynEox+cT5uQNqaZoaWh0ADhu0xBGY3OU3kN0vCTtnG8lMnh jndWvJ4PhUmTITR0SRs0ateypX8392YwBvencAiSZ8wbdW2m/QmQklLRWw3Uaw3LSgVn ywCrBRKDkmiSeHdOFS5wwy9baxj/KT8H/64wiPYh+YYyWPhmDjcBkbCqkf4oB27z13v+ 7AN5wGBIpAovviOSmBtu4zpbaguhO6R46Dm3x50dupqaL9wiuo5HiARFQCqrfde2VNYH 9V4sRmm1onTfM7dwmq9TNHuFrFTn4qsOE0c1pNjApmpdoZify3xuSTj6EioPTDra9UNr jdUg== 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=fV9XINkH2x8RoRhm2xmZEp8mea1e9p3OgesPwBu10Vo=; b=bpC/dpLfOLvLbR7Cs4VfKiZLNSegs1QGI+yA95+hwkU5G1YRhQfQwx7bARppIaSRdd 1jEBBY7B4UMBd39jrIhPRN3zcZEj2jtARTG5Jrg09ogEOWRpq2/bxyJd0ITM0nkgj+2d CzOshaDIpZM0a633wq+EbvuWVDzmE/5wpnFLAgeYVs56omJIcJqRZTcFlo7FUE8Nw8IU e9cVtJly0BA8A9aEj5q7IhoWfzwANXruQoRQdvac7vdPtzcKHZJEtN60xj9m150wZqdk uO3OxOK76T3qXMdoFjWxvqc5YVaYD2eSCrUN8Py2BeQmG3mjCb9I1cRsiaAzQC+dYcTQ nJbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=XmaaqdTo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x2-20020a170902ec8200b0015d093f3891si30879472plg.584.2022.06.08.10.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 10:00:29 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=XmaaqdTo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 35985275596; Wed, 8 Jun 2022 09:30:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245542AbiFHQ2z (ORCPT + 99 others); Wed, 8 Jun 2022 12:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245177AbiFHQ2I (ORCPT ); Wed, 8 Jun 2022 12:28:08 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F256D1FE4FD; Wed, 8 Jun 2022 09:28:06 -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=fV9XINkH2x8RoRhm2xmZEp8mea1e9p3OgesPwBu10Vo=; b=XmaaqdToytFNNjqVfr2LudrrDI hczTzpRW7eQwnjYH8Fk1qtFM7NgXp3rMnSyXGHcE3gnuM2FMHD1WbxFkJ0DfeScjJNQdGCvkm0vXO luDLw9zMsYMd65KUJJceKnUKQ0RcdOFhbRnZs4uT6DmyLZeq9qvsJbNBFwMWa8aEqZVCozab+DYd+ 0q4hT+vFdKDk9/vhC3NLd5RwM4kd4d1RRLB1ehIhJLxqv1kNUJi6X5OhSO3h/p8hEVfXS5BIDclTD MNQPHr9FfWyzldcm3Je4vFfNdYm2WZDNXJETkvf+GMlC3ModbfZUXn5URmgLgAI8MDS/8f3iHNFwz koYl3evw==; 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 1nyyXN-0026n6-Fr; Wed, 08 Jun 2022 10:28:06 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1nyyXH-000bdY-7u; Wed, 08 Jun 2022 10:27:59 -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 , Christoph Hellwig Date: Wed, 8 Jun 2022 10:27:52 -0600 Message-Id: <20220608162756.144600-8-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220608162756.144600-1-logang@deltatee.com> References: <20220608162756.144600-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, hch@lst.de 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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Subject: [PATCH v4 07/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 Reviewed-by: Christoph Hellwig --- 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 b1fc65e113f8..ca57b5fac599 100644 --- a/drivers/md/raid5-cache.c +++ b/drivers/md/raid5-cache.c @@ -3165,12 +3165,13 @@ void r5l_exit_log(struct r5conf *conf) { struct r5l_log *log = conf->log; - 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