Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3153108pxb; Tue, 12 Oct 2021 23:20:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhsBl7aJ+Qa5Vl1ft0oejMBgPESDsVIPGUSjlxHnbsWy2PzS3uCaNrMQNAV3SYFjsYZF5v X-Received: by 2002:a17:902:ea0a:b0:13e:8b24:b94 with SMTP id s10-20020a170902ea0a00b0013e8b240b94mr34168829plg.45.1634106005230; Tue, 12 Oct 2021 23:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634106005; cv=none; d=google.com; s=arc-20160816; b=lSbr2mz0hegUtoV/qniuVcHrnaZzR6p3bldm1/aIGV9LiuU3UfuZoqX554GKM/4+fX SAnWWXLhYBTiGHZEmD+7L0Cc0POCno+ag2fkfvoZKL0GboF7kd2VRXxxhgcaZHg8T6YF 5SAoMyB6e63WjTzHdFVYbzTEtrwUoZpHwF2u2p48tQzd+GesMAthBjz2gl7+DJXMpVuf Qukk6X4QKQa7sfUGfmGyYYRVAoMs7s+yyxwEo4E1cwVdhqP1kbfmMv/Ua7+5DjV+XmqR tHYW5BEwVDNrbipBwXGcOov5IhlSOssHd7ukJVkMgYPAz246jI4cheQDhkMUhdpzqluh wHiw== 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 :message-id:date:subject:cc:to:from; bh=lVbXRfnMVkN31/s5lCAHbrnLlb8Nb/1iPkaWud0u9NA=; b=ovG1eXxlgSVU2OfIQ8pxoOOAA7KW34X5q6GbUbwXcRrQEnRHYSdS3dCQzU94hh01Ah WLjNJWth9eEGfiJIQds0gE2UzxoxeBBvqAHQCAZe/h2e3N3jQeZTzQ9KmaOGN++BUj1f 7GmnCKqWAmy36d/f0bxtNUSnTqT95cxjLsRXe0X5vK9uKBUDtclMGItg1VFSS34S6/R2 j+L+uqTEmywGQsArBkQKi6iOZl3BnnvOe/yC51oZ2V2caW0/YxoIulaDqGmUWfD8Lgxi 7UF04d4EvOAsZnJ8Mu3Sf04RlcrK9aGpVbLJV11GRoDViCkiUWZCubBU6jggpTDZsCv1 Pg8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d8si3564208pgi.458.2021.10.12.23.19.51; Tue, 12 Oct 2021 23:20:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237837AbhJMGTo (ORCPT + 99 others); Wed, 13 Oct 2021 02:19:44 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14341 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237914AbhJMGTc (ORCPT ); Wed, 13 Oct 2021 02:19:32 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HThyn6Wthz90CG; Wed, 13 Oct 2021 14:12:33 +0800 (CST) Received: from kwepemm600001.china.huawei.com (7.193.23.3) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 14:17:23 +0800 Received: from huawei.com (10.175.104.82) by kwepemm600001.china.huawei.com (7.193.23.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 14:17:23 +0800 From: Wang Hai To: , , , , CC: , Subject: [PATCH] ata: ahci_platform: fix null-ptr-deref in ahci_platform_enable_regulators() Date: Wed, 13 Oct 2021 14:16:31 +0800 Message-ID: <20211013061631.2958938-1-wanghai38@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600001.china.huawei.com (7.193.23.3) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got a null-ptr-deref report: KASAN: null-ptr-deref in range [0x0000000000000090-0x0000000000000097] ... RIP: 0010:regulator_enable+0x84/0x260 ... Call Trace: ahci_platform_enable_regulators+0xae/0x320 ahci_platform_enable_resources+0x1a/0x120 ahci_probe+0x4f/0x1b9 platform_probe+0x10b/0x280 ... entry_SYSCALL_64_after_hwframe+0x44/0xae If devm_regulator_get() in ahci_platform_get_resources() fails, hpriv->phy_regulator will point to NULL, when enabling or disabling it, null-ptr-deref will occur. ahci_probe() ahci_platform_get_resources() devm_regulator_get(, "phy") // failed, let phy_regulator = NULL ahci_platform_enable_resources() ahci_platform_enable_regulators() regulator_enable(hpriv->phy_regulator) // null-ptr-deref commit 962399bb7fbf ("ata: libahci_platform: Fix regulator_get_optional() misuse") replaces devm_regulator_get_optional() with devm_regulator_get(), but PHY regulator omits to delete "hpriv->phy_regulator = NULL;" like AHCI. Delete it like AHCI regulator to fix this bug. Fixes: commit 962399bb7fbf ("ata: libahci_platform: Fix regulator_get_optional() misuse") Reported-by: Hulk Robot Signed-off-by: Wang Hai --- drivers/ata/libahci_platform.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c index b2f552088291..0910441321f7 100644 --- a/drivers/ata/libahci_platform.c +++ b/drivers/ata/libahci_platform.c @@ -440,10 +440,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, hpriv->phy_regulator = devm_regulator_get(dev, "phy"); if (IS_ERR(hpriv->phy_regulator)) { rc = PTR_ERR(hpriv->phy_regulator); - if (rc == -EPROBE_DEFER) - goto err_out; - rc = 0; - hpriv->phy_regulator = NULL; + goto err_out; } if (flags & AHCI_PLATFORM_GET_RESETS) { -- 2.17.1