Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2154554ybm; Thu, 23 May 2019 12:15:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiTUnolmCPbHIZ6RN9NK8J1wyPJyZ/gq4PMbeR/veqppex1b/TS5iEE3LZTqyxnKs0zgze X-Received: by 2002:a17:902:f81:: with SMTP id 1mr51115163plz.242.1558638925563; Thu, 23 May 2019 12:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558638925; cv=none; d=google.com; s=arc-20160816; b=VyBq1Kx5IK278iqjs5VBjM4GrNZ3iNoKWRxLy5x8H10fi7PIDRbZf7BXuXyva/z0La STkpIiXL6PLT+VYfYeJtZGzbn4KMSKNszpquShi/ibSuX+0VpcG+UkxkdeBrJw6eBPfE dI8HsqCeGCVKNdAkRe7bJGNOvfJxQcO8pPDlH81vT5auRep/70XUUDynz09TKkfZnEyk qJx/I45psS+2tAfMyS8RDc1mqwwKWgLLFcQn3yw7wN/Tntg8s7h2YlCS5KVE324hRu3d GS/E6P6orzQ6yYZQX/YnMFMiHAAL080eB3mEZZLOOqzMMOqLYOSQKyHYOQbtqjriprox 4vMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WQK/Jzdc/WHtNM3l1Xgu9mR0uUr7QRmCsmWBclC9GQ0=; b=D9syeb4aP6TrYAD4HQ1qDiTf80E4Lx2f7lPtFXSRmHybKkh4dT1rnpAowIEVl6tgMI 2OuX0zqABiGj3hnWsAh96LHmyWNXRQimXiWB+k4o8ygjD6f/VOp/t56FFtWYiIBd3QCQ iAJYWcijJC5wQagLpwq/zNCfUL4f2t1DD4lVWt8mActHYSQ3QqvYdlHuz5JCH8/aNhRh Saxlk+MtvaXmLlKgzU4GPUAbaAhpk20gfiUm2c44dwY4p273qe6KBw3YzyQNlpzTlBnY FrGR+aal7C6vLGN8Ib7DxYd3It2fcBEoZTA6FHjsqiHnZ9e0u12GKn7ka3m7mwwUuRmI pdCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FeJJqX87; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u6si530133plq.94.2019.05.23.12.15.09; Thu, 23 May 2019 12:15:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FeJJqX87; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388408AbfEWTMO (ORCPT + 99 others); Thu, 23 May 2019 15:12:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:45880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388380AbfEWTMJ (ORCPT ); Thu, 23 May 2019 15:12:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B22FE2186A; Thu, 23 May 2019 19:12:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638729; bh=JtWd6O3/eRycUXinHH2loJFoCaEZwSr600RHCObQA7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FeJJqX87bPKp2DpOXadz4ATqQZay8JBHMYEV9JJ7YAbxXv+fEwZujI2/2mllwVst8 zAkvB35+C9H35PbNTSc8AL+L/w/UYxDTYx9BL9YGp5A1llazChhCwocLZvDNMatuTC GWm7XAIngyqRSP15wB5GR7y9Ki2v06h42WPjVG2U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiao Ni , NeilBrown , Yufen Yu , Song Liu Subject: [PATCH 4.14 16/77] md: add mddev->pers to avoid potential NULL pointer dereference Date: Thu, 23 May 2019 21:05:34 +0200 Message-Id: <20190523181722.480834303@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yufen Yu commit ee37e62191a59d253fc916b9fc763deb777211e2 upstream. When doing re-add, we need to ensure rdev->mddev->pers is not NULL, which can avoid potential NULL pointer derefence in fallowing add_bound_rdev(). Fixes: a6da4ef85cef ("md: re-add a failed disk") Cc: Xiao Ni Cc: NeilBrown Cc: # 4.4+ Reviewed-by: NeilBrown Signed-off-by: Yufen Yu Signed-off-by: Song Liu Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -2845,8 +2845,10 @@ state_store(struct md_rdev *rdev, const err = 0; } } else if (cmd_match(buf, "re-add")) { - if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk == -1) && - rdev->saved_raid_disk >= 0) { + if (!rdev->mddev->pers) + err = -EINVAL; + else if (test_bit(Faulty, &rdev->flags) && (rdev->raid_disk == -1) && + rdev->saved_raid_disk >= 0) { /* clear_bit is performed _after_ all the devices * have their local Faulty bit cleared. If any writes * happen in the meantime in the local node, they