Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2205936iof; Tue, 7 Jun 2022 23:10:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym1dx5dkZLJZ6qvLxguK4E0SWG0BBOXR29vyoKvIvJksfmC3VKcuJ0/qvLJQ1Us2x1Riej X-Received: by 2002:a63:74d:0:b0:3fc:8fd3:c23b with SMTP id 74-20020a63074d000000b003fc8fd3c23bmr28648528pgh.392.1654668645198; Tue, 07 Jun 2022 23:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668645; cv=none; d=google.com; s=arc-20160816; b=DdoHkvPpmDksKMxkRf/j7cYUzayyTWIPJRLdDgFiu6A6iI3WE3DWEJ5crhZILvlwGB c4lUoIm/a2K9sDCOFsyieapl1Rt1tzC7ykLNfROCmps0Cx7z3zqXhMqUgLgpflUQ8WcM /rYIg2QUKYXpFdBvSq2fvukTIhm6qEikkuAwZeaeimWHCrEtS9WdAnRTWSkNwnP7Wgku vkQ8QEnO+dnnLGozoEnySl6gkGfqWgEWO1FaVJXi/mPZy69dNT5TyLuujLt0TrmP47SZ HS/ZqzyDkuT295N41VuyArVcVav/J2Au5yVnMZeOeh72XUH94FkeEnSzAIqs5ComUDkV qbxA== 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=bevXuIc7csl/RBXy5W2kmT5VLOhpbRE9yh5YpTrvAMg=; b=i8IAgJ7gkaH0W3qLwThIoQlBGIyy03sZSxaX7VgvSTgPsHTxxtimutsTK2ou1ifn73 0NUxH/GiPXQxzaRmNzDFGVe6tSBjWUgh2HQidtbHkW33esRJjn/Mlc8/8xn+K5UL3J6M f/m+Fq0C/CmE5t12JywUO2FGBnBurKjOWalvppNZkMRrFVjoa1suYzk0DCCG/40tbC1r OZoO0OemmuebBzlkaOpvXisn9SldQJ7dkFb6T21GDrVXjNCaJ/a1v8TXva0crcyR+j7P IJYPQmIwPQZc/rG8vpvQx+5AvKXqeCcNQeZ3RsqaCCC7fX2U0lZP0ej7npvoww86mczz J3xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KX1kOkY7; 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=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x8-20020a170902ec8800b001618e01b52esi26468873plg.92.2022.06.07.23.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:10:45 -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=@linuxfoundation.org header.s=korg header.b=KX1kOkY7; 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=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D9E1814641B; Tue, 7 Jun 2022 22:33:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239764AbiFHBnC (ORCPT + 99 others); Tue, 7 Jun 2022 21:43:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381670AbiFGWVy (ORCPT ); Tue, 7 Jun 2022 18:21:54 -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 68D6926C0D5; Tue, 7 Jun 2022 12:22:22 -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 6E291B82182; Tue, 7 Jun 2022 19:22:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6D43C34115; Tue, 7 Jun 2022 19:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629739; bh=AZp9GM2aIQXcY2X/5Buvw7LgLptr9W3PQ57LG/PVk8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KX1kOkY7DDLTzK4JaNBVoLx0lvjKHaByH4Ld0tzAAED8pq0vPMU1YzVrN67wwacbB LFOurdvUVJmF/E2a7NZqt03xJU4jrS/yzduT+gTKAP6ar5ZOaSLsuwINamHUc0GtEW lA7z3cpy/NtK1wBbFNJzCOHY0v+i4NcoDmKl7MC4= 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.18 798/879] md: fix an incorrect NULL check in does_sb_need_changing Date: Tue, 7 Jun 2022 19:05:16 +0200 Message-Id: <20220607165026.024032950@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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=unavailable 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 @@ -2627,14 +2627,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)