Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp576857iog; Mon, 13 Jun 2022 08:27:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKyGAaRH5lINuXo/FiqrHbTKEMsqQtg2fbn+KD9RT+K4XM03pV4mWlbn90Vt8ak5oXH/Ta X-Received: by 2002:a17:902:8488:b0:167:9151:a8db with SMTP id c8-20020a170902848800b001679151a8dbmr243067plo.2.1655134044732; Mon, 13 Jun 2022 08:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134044; cv=none; d=google.com; s=arc-20160816; b=ziPZcezQI82T9lMXQE7eQwqeKlbSi9UAhyPNlbS1ljyGUqz/9FZLkVYvQhGqK0bLFp 6aDWwCUvckbhJKhQtD9YRdrnGdOa9Ht/gFNohFsKsl0GyOxMC06Ff558PjFh0XuZP4lI SGlDNEMcNj8zBGy/sYOnoQxQOUJp78cierg5kZnU9pwHCKrS3UghYFjfxx86CbA/X6Pn lB+YoO3VDJ9t+MJZfM/XvouG2eAYxUMyieZ+kgnBz2VVuzjcb0uq89oBkCq+QIAPRt1C sg1GjCfqykXOPIz1pfqzrQEulXiQkVzl7DFIkQsQQhTrWiuWo3ibZARZbTxKh7ttsG9/ W7aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uZlCOt7b8kUkb+Q+rMpbwAPbpPRn97UNkEpxWzbFgiQ=; b=FzN1xT7j+A1bOa9KnZpJqkn/U0iJNRxL/bol7IXn8PiS5+6ScF3WNCN6Bmhw6i+EpW 0PmWq8kbmNB9SZTluMay408kfSGq6+sBr9tP0LqH34iArjtrkO/5oD6ZxMokorypaBpD q3x2chQwDhQAMVXPWTwaHPiKEMqIHnQXJjZJNmTW0Zv/3G9+RKMawV0a6enuPkiGcbvQ zPXWt90VwqD1O2V7W/OTZ8oRpS1y4uvLRe7biZZ3l54y7/BTY+k7K6myRhgptrmjB+tR b4505M76PBNBlddOzSNOCZ23cimZAA/eHp0TsUd+ul8AvLhcmQBeAYX5LKOHttdtZV3d zuQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="nAXVrOQ/"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a056a00170200b00518820f0cbfsi10807500pfc.335.2022.06.13.08.27.12; Mon, 13 Jun 2022 08:27:24 -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=@linuxfoundation.org header.s=korg header.b="nAXVrOQ/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354471AbiFMLct (ORCPT + 99 others); Mon, 13 Jun 2022 07:32:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354221AbiFML3D (ORCPT ); Mon, 13 Jun 2022 07:29:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3313B3EB82; Mon, 13 Jun 2022 03:43:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C3875B80D19; Mon, 13 Jun 2022 10:42:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7A24C34114; Mon, 13 Jun 2022 10:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116978; bh=xlCnOYMrPQdrEqV4rKXfQ3FH5oPFMqNeOf1bVNRdb1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nAXVrOQ/x2MhmQbRXLpZhwx9pCGn8CP+KAaL+CfzL5KRENyih1jf2LZzAFsk/PAuG EUFCUjg/Hj1HfEAYZ3BIZUSumeJ9ujNmcvBu6jyo4UFucAGzemOV/gdIWKBp4dGeXe b9t4aCf/tH8eMUVmbIyqaaGzM2quZbJPjJbCnczM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guoqing Jiang , Xiaomeng Tong , Goldwyn Rodrigues , Song Liu Subject: [PATCH 5.4 243/411] md: fix an incorrect NULL check in does_sb_need_changing Date: Mon, 13 Jun 2022 12:08:36 +0200 Message-Id: <20220613094936.064605601@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaomeng Tong commit fc8738343eefc4ea8afb6122826dea48eacde514 upstream. The bug is here: if (!rdev) The list iterator value 'rdev' will *always* be set and non-NULL by rdev_for_each(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found. Otherwise it will bypass the NULL check and lead to invalid memory access passing the check. To fix the bug, use a new variable 'iter' as the list iterator, while using the original variable 'rdev' as a dedicated pointer to point to the found element. Cc: stable@vger.kernel.org Fixes: 2aa82191ac36 ("md-cluster: Perform a lazy update") Acked-by: Guoqing Jiang Signed-off-by: Xiaomeng Tong Acked-by: Goldwyn Rodrigues Signed-off-by: Song Liu Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -2532,14 +2532,16 @@ static void sync_sbs(struct mddev *mddev static bool does_sb_need_changing(struct mddev *mddev) { - struct md_rdev *rdev; + struct md_rdev *rdev = NULL, *iter; struct mdp_superblock_1 *sb; int role; /* Find a good rdev */ - rdev_for_each(rdev, mddev) - if ((rdev->raid_disk >= 0) && !test_bit(Faulty, &rdev->flags)) + rdev_for_each(iter, mddev) + if ((iter->raid_disk >= 0) && !test_bit(Faulty, &iter->flags)) { + rdev = iter; break; + } /* No good device found. */ if (!rdev)