Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp991115lql; Tue, 12 Mar 2024 04:30:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGU83qw2QxmiZco8zlXWDYNKEYfK5pPxu1ZIvweAKm0qlBPjaDMLBHA0Uw/32Np2vyv9zGKZwurvZdFiINnHYOu1ybHO7M2Jqv02ZTrw== X-Google-Smtp-Source: AGHT+IGaf8nD9Q3gpf52+C0tSAOrOW5dGBTR3ca33jf9/7C9ZVrlFUa7z7T6XLsYxzrzRG4En/jr X-Received: by 2002:a0d:f146:0:b0:609:fad9:1faa with SMTP id a67-20020a0df146000000b00609fad91faamr9083220ywf.40.1710243028671; Tue, 12 Mar 2024 04:30:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710243028; cv=pass; d=google.com; s=arc-20160816; b=I5gwnY71MNLiH5gipFYfhxK/0HNXcmtIMCA6dGtysOAOZvbtkczjXuG7QxnyWd3HKD 9LihPNHwCzQI5cyF9Qd7oCpYngsDeLgGEpnsNkquW1QUFmAEtfm9q1taLzmHBIrazYqX L7VIW/4ilOwZg7s6FkkjwiT0f7OyKRrXFoOPtsiO7IRk2/Rpd/7UzZHsa+g/+6rqGPtf pyHiESxOBiQhlhscqB69zWRV42alXctLIopurqAokFgs92UlF79S8u1ku7mdrk9Rckm7 dWnPjLRZx7K25qsINKeb9P5ew/AGRT4fjiZZXYC5tEiDyz1QBI1ALcnkn3sbd4CQV3s+ l7zw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=CupxoLbqDAw0iGT/Dkpjp3a8L1C7qew16mx6r26LNOI=; fh=7C9Qc4TBhZVK8KEk//MPq4vSWlhB7xCxSk2hsDu5lhM=; b=y3FR6cXZm9G7+Dv3lfeQwwYeDTAst5dJb+Xw+CFtcizJ/U+MiaZFeMKG4Uo6HLwMnT HS6xFwKYw3xs3HI03ppxqQ11qVqfElC97gxg5cvF+3fECDQBDFVtz5DwXh2EWs1LdPur q9TcGd9nIP1Z1mc05QAFr/pI+lbF6QNjiMpvoDMxQlXOps0ejL81AncTleIkzNHM9V/K wZnjnNPbKfXAi6F8uydLyOGVqDHtpG/NiUaOOQB+sjERLEpswiA96pptS7H5qQlX4Vd7 EyuwzYK2EeTiLHy9ErEI38I3VJXaoKY7D/jgd7XUTEJMAp1Glc8E8hOwFLTXXs0I50kP PodQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=suy3Kme3; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-100176-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 5-20020ac85705000000b0042ef5574ebbsi7198595qtw.190.2024.03.12.04.30.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 04:30:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100176-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=suy3Kme3; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-100176-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 572021C22C66 for ; Tue, 12 Mar 2024 11:30:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DE2C79B88; Tue, 12 Mar 2024 11:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="suy3Kme3" Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9B8D20304 for ; Tue, 12 Mar 2024 11:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710243021; cv=none; b=kvDf9ejMVrhiSXwiAQOEHIGpop6JM7390chPVVoKagoG292kW11HNQ+MhvMr8BXqgV8lg8SStHvhvi0gMNXDqtURNQzACqd1WPkO/phS0MyTu5ZtjtQt75SZjV0T7aDtsy6QtGnXk3M23JSwhsxWwzOHG+7vd7l0vNojgTqLqDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710243021; c=relaxed/simple; bh=l2WdSNUP4K3SIKsekSGXnuJXGSgpdVPTEVsLPobE8NU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AVqhUZlgULsNkbGKw9Xsdd3I8tse3YBA/qmHJZ0PLFyvuLLR3ZQjSYJ4XzgG0ewf0X73oOuywssq6UR/LKHPqFsEgEU8myNSBMjyrQusMbjqR8mWhOnCc/jQY+Qzeqoml00WB835cqMJN3uOrJN2631rJUuIwsS2eGCxLNm+XgI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=suy3Kme3; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-56845954fffso4004351a12.3 for ; Tue, 12 Mar 2024 04:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710243018; x=1710847818; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CupxoLbqDAw0iGT/Dkpjp3a8L1C7qew16mx6r26LNOI=; b=suy3Kme3GoTwvuDvCo7FxdJ4a+X0G2nZQEYnirOqW84ejLh0FNsdIG/IdeyWsJwlFX D7PNR2xUj0GR783+HAHnN7+hHCRMgjBIInIpLdwnMdGTyCIy0biLlg9ycPQ+C9pTbhG7 cRMhWL7iAUiWrhJNIC/aM7XMio4TxArzO1LvhDAQfOmTE+tcf3g7e89yzg3Kk6ileFgn fuchibVdIeFlJ0GcoP/jE8/vPo2mWCd5eaR38R7eyGJ2WJFoJpRxt3tD2PLWHrjjJeHY m4CIB/9GbXBcjcCJq4JQpGegS15S67nS7e58TjUSuj8Ft/+fg2noDGObneizeWuQ/uK/ INoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710243018; x=1710847818; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CupxoLbqDAw0iGT/Dkpjp3a8L1C7qew16mx6r26LNOI=; b=fXPelOHBVEwLPJMhrUqeAytHwvWkXC3QXM10WQVX284KAfMHV8MJbknbfmPux6w8X+ z0tJYufaJi9KF9rJSKo54QqYmxJaDU4A05jXS6pQ8Qwuz5fQp4EV8IepgTl6gaYJf7s7 ogJaSruVt2C+tid/H5p5RBbrkkOccyKKeCDXk4COCsQRAjRPdT5U6GP7GqDvnI4NJkRz 6iJfwbPEh7QbxC4UH7FPqumRJTh9MKxACGHV0GrLOVTg6Exm5HmNINTwmWxVgxO6wta4 IDxCsCvmtMfErET2cZu2QhLSU0ouq+Px+aUhjhYJffOkYKLpRHV4uct91oHNPU9YeYCI pqCw== X-Forwarded-Encrypted: i=1; AJvYcCWDKbQSDmSm7Awmgp//3CIk6tBfRzOxe9qumM1ou0MYeVpKjsA+R8XCfY/czhzBe0aqAQPBA2Wliz0hcJyg1/Q6NFn5p000H4tTV5qw X-Gm-Message-State: AOJu0YxzGCB9WdpLarPy5IC9pw0fT1CqkQ06hFY67GCzTiBtLOutER3/ yaj0FZ1HVhVNSwWOolXXNtYsKlADUZ1OtBG1qcnEEJlsNTStKSdYyEWCO02Mbu+vndEZJE49en2 7qZJqz0WA7/34Bn/ifjCgQiczp12VZIQaLhlfig== X-Received: by 2002:a50:9e24:0:b0:565:1460:8447 with SMTP id z33-20020a509e24000000b0056514608447mr1438863ede.28.1710243018038; Tue, 12 Mar 2024 04:30:18 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240307085135.16245-1-amishin@t-argos.ru> <98dea36b-41dc-4d2e-aec6-56c849e1d58b@t-argos.ru> In-Reply-To: <98dea36b-41dc-4d2e-aec6-56c849e1d58b@t-argos.ru> From: Ulf Hansson Date: Tue, 12 Mar 2024 12:29:40 +0100 Message-ID: Subject: Re: [PATCH] mmc: dw_mmc: Fix potential null pointer risk To: Aleksandr Mishin Cc: Jaehoon Chung , Wen Zhiwei , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Content-Type: text/plain; charset="UTF-8" On Thu, 7 Mar 2024 at 20:07, Aleksandr Mishin wrote: > > > > 07.03.2024 13:57, Ulf Hansson wrote: > > On Thu, 7 Mar 2024 at 09:53, Aleksandr Mishin wrote: > >> > >> In dw_mci_runtime_resume() 'host->slot' could be null, but check is not cover all corresponding code. > >> Fix this bug by changing check place. > > > > In fact host->slot can never be NULL in dw_mci_runtime_resume() or in > > dw_mci_runtime_suspend(). > > > > A better fix would thus be to remove the redundant checks. > > > > Kind regards > > Uffe > > > >> > >> Found by Linux Verification Center (linuxtesting.org) with SVACE. > >> > >> Fixes: 4a835afd808a (mmc: dw_mmc: Fix potential null pointer risk) > >> Signed-off-by: Aleksandr Mishin > >> --- > >> drivers/mmc/host/dw_mmc.c | 4 +++- > >> 1 file changed, 3 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c > >> index 829af2c98a44..a4f124452abc 100644 > >> --- a/drivers/mmc/host/dw_mmc.c > >> +++ b/drivers/mmc/host/dw_mmc.c > >> @@ -3570,8 +3570,10 @@ int dw_mci_runtime_resume(struct device *dev) > >> DW_MCI_ERROR_FLAGS); > >> mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); > >> > >> + if (!host->slot) > >> + goto err; > >> > >> - if (host->slot && host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) > >> + if (host->slot->mmc->pm_flags & MMC_PM_KEEP_POWER) > >> dw_mci_set_ios(host->slot->mmc, &host->slot->mmc->ios); > >> > >> /* Force setup bus to guarantee available clock output */ > >> -- > >> 2.30.2 > >> > >> > > > > At the same time there are few checks such as "if (host->slot)" in > dw_mci_runtime_resume() and commit > 4a835afd808a3dbbac44bb399a902b822dc7445c message contains: "we > previously assumed 'host->slot' could be null, null pointer judgment > should be added" and replaces "if (host->slot->mmc->pm_flags & > MMC_PM_KEEP_POWER)" with "if (host->slot && host->slot->mmc->pm_flags & > MMC_PM_KEEP_POWER)" > So where is the truth? It looks to me that the runtime PM callbacks are prevented from being called, unless we have a host->slot assigned. Just adding checks because it looks like the code could need it, isn't always the correct thing to do. I would rather try to remove the checks altogether and give it some tests to see how it plays. Kind regards Uffe