Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6753536rdb; Fri, 15 Dec 2023 07:31:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXu8ZH4o9refX9zksQj3KEgLJ9ELxoxJ4e8Efdi5kmAviuDHVNDGMb8WwxWyLg9jubYIAX X-Received: by 2002:a05:6e02:1b8d:b0:35f:690b:d425 with SMTP id h13-20020a056e021b8d00b0035f690bd425mr6913709ili.65.1702654278189; Fri, 15 Dec 2023 07:31:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702654278; cv=none; d=google.com; s=arc-20160816; b=ErZ+YUi5DnRSH5DZ4k3aKC81wSkQpScevOJ6Cfn8kVHFV9qSHYRI1ppngMmZAnd6V9 UJbEa2AvN3sKGiIuC0YnMvlgNirMeey+C3/5pgqYU/enBzVuiz72DKlrqEeT/cPXMtl8 /Uhuc0IsuFFXbvUu11Y7Xv7Rv8QGyLupOxGGRznPBMc33NvKYSFlGEsOC/BxMSDrY2tk 0/lnZzRg/tSkWsLGCwwaEBGKcQ4gL59jZabuIJHnm6+njFkSLcYzerxjkBErfsbpWZDL 58+Bhbl8iMmk7uLMhBNtWo/gmjc6S2LdhJr2kMTkF5B9npjfTDDHXtFy0EwUEKZdbNWH 1Gjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=qhy4c0Uuj9aos5gEcmXqi4zbBTDLrVy7jAASUNEcn3k=; fh=P/AMENj6dWKY1a+zg1eactXbcTgTF0nCIoFDSpd64vI=; b=YG/1hWAJCEhvFTMP+rm35Z8EsgarKSpQpGTkNK3XvUSo/zcfeAgZBdqn70e9iOoLKQ i060uMMoEUFbe87gerSYj1yr/mkSgXkUVBgWe1/3jMaVu/yUTgwwcYNPmC+nSiG3b57v ntoyQpQQwVQQZaWAjgLIwE49zyNG27rIbKXujshUFeiB6OfrseCYd6VWbrTTSZ+FfTGy MybI2fFhm+VkSb+u/M/UuyxO1W7hhAWURgGa5afqrdBXpSi9dQl+ehplZZNzp0/A62wx dZRF/4eixai2fXYXUx3l5WAbvtU2G+RffP07NoWVXBzdSG098lzpSHP5yFALJCAmxJ6q YC2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1217-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1217-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q4-20020a655244000000b005c66e020c9fsi12547017pgp.718.2023.12.15.07.31.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 07:31:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1217-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1217-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1217-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6F265B21A13 for ; Fri, 15 Dec 2023 15:31:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BA423716F; Fri, 15 Dec 2023 15:30:58 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0DF237152; Fri, 15 Dec 2023 15:30:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 619E3C15; Fri, 15 Dec 2023 07:31:40 -0800 (PST) Received: from [10.57.85.151] (unknown [10.57.85.151]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D441A3F5A1; Fri, 15 Dec 2023 07:30:53 -0800 (PST) Message-ID: <30891c4e-0fec-4477-ba49-905ea05a4545@arm.com> Date: Fri, 15 Dec 2023 15:31:57 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] thermal: core: Fix NULL pointer dereference in zone registration error path Content-Language: en-US To: "Rafael J. Wysocki" Cc: Linux PM , Srinivas Pandruvada , Zhang Rui , Linux ACPI , LKML , Dan Carpenter , Daniel Lezcano References: <5737641.DvuYhMxLoT@kreacher> From: Lukasz Luba In-Reply-To: <5737641.DvuYhMxLoT@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/14/23 10:52, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > If device_register() in thermal_zone_device_register_with_trips() > returns an error, the tz variable is set to NULL and subsequently > dereferenced in kfree(tz->tzp). > > Commit adc8749b150c ("thermal/drivers/core: Use put_device() if > device_register() fails") added the tz = NULL assignment in question to > avoid a possible double-free after dropping the reference to the zone > device. However, after commit 4649620d9404 ("thermal: core: Make > thermal_zone_device_unregister() return after freeing the zone"), that > assignment has become redundant, because dropping the reference to the > zone device does not cause the zone object to be freed any more. > > Drop it to address the NULL pointer dereference. > > Fixes: 3d439b1a2ad3 ("thermal/core: Alloc-copy-free the thermal zone parameters structure") > Signed-off-by: Rafael J. Wysocki > --- > drivers/thermal/thermal_core.c | 1 - > 1 file changed, 1 deletion(-) > > Index: linux-pm/drivers/thermal/thermal_core.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_core.c > +++ linux-pm/drivers/thermal/thermal_core.c > @@ -1394,7 +1394,6 @@ unregister: > device_del(&tz->device); > release_device: > put_device(&tz->device); > - tz = NULL; > remove_id: > ida_free(&thermal_tz_ida, id); > free_tzp: > > > Reviewed-by: Lukasz Luba