Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp243700pxb; Wed, 6 Oct 2021 04:11:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytYDA8+Cit0kcDiV1CADC+aTphUxIYTCEN5iK1tMpTTtwLXzOggF+/ZNQ/cZfb9oRIyFux X-Received: by 2002:a05:6402:450:: with SMTP id p16mr33141957edw.162.1633518676820; Wed, 06 Oct 2021 04:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633518676; cv=none; d=google.com; s=arc-20160816; b=HmLi2lDKndSJtVpdVG9rCy0ppuISkar4yoVcH7WtFVWggQAKLFul1XlitYn7d/ocnK eqKQ6ArltGFPo6VZU7s2rOXOAaJhz9ZI3TXcN4Si5j7k4CiQtAUZE5dPUjXue10B74d+ gXh4gHsvqE6RnH+1HIsMr+AEZAyngH5zq3p1WGMO7jCWG/sFO+ihHVRAEjmniUpkxeEj ECSSV3RHSbSvEjgIHGdqs/IDuZKCZqb5MVVoBaE41/CIRKxlPN4OmmlrSRF8guvF6bVg MtsZwSkDtzPxTVghObKhPa6Ph1U2ZoMIHSSQZH1TwJBMBlgoFi3wX58Gq+0/MUvPewHf x1hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=NPYO1x8t8q66IiDTyVlrAaxm7/2JWwiYPINC/gUajk0=; b=pjWF3oQJclRXqw/v6FPCa3nisep+TOtgXrcTFmT0/ORyHvq7bCBmNxF+e54ufSytZ5 k+sKCnca/HbTA8c1mVGgeWAbhv0Fs5MPJ08qyN93Mnj9FYm/gAaqZcXmT3bfFGFZgK7W 0sp/1BmX3BplDENEAtAiHBXo7GHGM12lUby8KrDEpu1r/0LOj81KJy3tTtsaSOC6ymlk DUF8v/rol6HUuPIuzu21rrtdkzJd8jku95OjD8tyJWo4LixkaBgkcqDiEyPSvkPwh4JS 3mwlrGkCm/42pur2oCGFFYv9KWtqt/vXCq+Gxo/8M+TFReECUyUagnvfeTCiUmd9pwkJ Fxqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=teGOKFdD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr22si17280511ejb.55.2021.10.06.04.10.45; Wed, 06 Oct 2021 04:11:16 -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; dkim=pass header.i=@linaro.org header.s=google header.b=teGOKFdD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237836AbhJFLKX (ORCPT + 99 others); Wed, 6 Oct 2021 07:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237952AbhJFLKU (ORCPT ); Wed, 6 Oct 2021 07:10:20 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 094FCC061749 for ; Wed, 6 Oct 2021 04:08:28 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id k7so7537401wrd.13 for ; Wed, 06 Oct 2021 04:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=NPYO1x8t8q66IiDTyVlrAaxm7/2JWwiYPINC/gUajk0=; b=teGOKFdDhDsSTSXzlKK/3F6rCmpFIHzypmyst45m2zsOMJvdqVwxTBuWIpItl00H9B YdNO9ZlryPCTJ+LAB4/bOYdPAzARCQmx5BEYYbk1xsVHSy84eL9lW6PoLTzJhC6G/ylZ fStW2ibbzcM69WecqB69/rlps535APGOs+loGZeZoOvJ1qInElCX2tVpMZEOS2Fdn8X/ 5nDlEtdHaC0HwT1hmF4sWLznBxPkafMSE96WIWxWkIKK08cvN15zfVxQkh9LyT/RF+Qr 8u0cJNnX8pVEoTfLTBHoCg6KNeXPh+9a/bCmB1Xs8mRH+xFPReNqrJcbEX6qFrrwksp5 39lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NPYO1x8t8q66IiDTyVlrAaxm7/2JWwiYPINC/gUajk0=; b=clLHAi74ADakw5XqlqRKBThaKoMKeX0Vkhny3p00YvFGybe8+nHl18kTxLqqRZmnZQ oGRVcrTpdNuauFXjKU2zQgYRirei3upRYjqXzD5eQBuQFfPjQEI87yE05Nvt4SHqEnLB nXcAlwWpDOGGZIHaArrU+I3jcO2kiicvWMTxkomYA3k+V0n8WD/CyHT44hm/NHWx8gEY URoSxEukuVQiMgtxYPO+mWCMNSwWsc7cKgmHX8vtRwCcNE0CO4cox3F2oPsBNLmkIgJP gYsD7XgX+SXMMKn7K3xEEcTEBwLBV0AwFwMGeRzLFGVbCZXZWgXv2pn3RQKOByg1ZTYw lc3w== X-Gm-Message-State: AOAM532pOi7aexSuYIAAj2p+XiQ054uiwv4N1fveToRRCVjRKdVZDr+J z0lSKkoHKniLhN7xUqHbqXi2A7sOSuARzg== X-Received: by 2002:a1c:4e0f:: with SMTP id g15mr9142233wmh.74.1633518496285; Wed, 06 Oct 2021 04:08:16 -0700 (PDT) Received: from ?IPv6:2a01:e34:ed2f:f020:278:1f59:2992:87fe? ([2a01:e34:ed2f:f020:278:1f59:2992:87fe]) by smtp.googlemail.com with ESMTPSA id r9sm20587793wru.2.2021.10.06.04.08.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Oct 2021 04:08:15 -0700 (PDT) Subject: Re: [PATCH v2] thermal: Fix a NULL pointer dereference To: Subbaraman Narayanamurthy , Zhang Rui , Amit Kucheria Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, David Collins , Manaf Meethalavalappu Pallikunhi , Ram Chandrasekar , stable@vger.kernel.org References: <1631041289-11804-1-git-send-email-quic_subbaram@quicinc.com> From: Daniel Lezcano Message-ID: <003252f2-510f-e9ea-0032-6034f26aad11@linaro.org> Date: Wed, 6 Oct 2021 13:08:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <1631041289-11804-1-git-send-email-quic_subbaram@quicinc.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/09/2021 21:01, Subbaraman Narayanamurthy wrote: > of_parse_thermal_zones() parses the thermal-zones node and registers a > thermal_zone device for each subnode. However, if a thermal zone is > consuming a thermal sensor and that thermal sensor device hasn't probed > yet, an attempt to set trip_point_*_temp for that thermal zone device > can cause a NULL pointer dereference. Fix it. > > console:/sys/class/thermal/thermal_zone87 # echo 120000 > trip_point_0_temp > ... > Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 I'm still not convinced by the changes. Could please tell the commit-id where this is happening and give the procedure to reproduce the bug ? > ... > Call trace: > of_thermal_set_trip_temp+0x40/0xc4 > trip_point_temp_store+0xc0/0x1dc > dev_attr_store+0x38/0x88 > sysfs_kf_write+0x64/0xc0 > kernfs_fop_write_iter+0x108/0x1d0 > vfs_write+0x2f4/0x368 > ksys_write+0x7c/0xec > __arm64_sys_write+0x20/0x30 > el0_svc_common.llvm.7279915941325364641+0xbc/0x1bc > do_el0_svc+0x28/0xa0 > el0_svc+0x14/0x24 > el0_sync_handler+0x88/0xec > el0_sync+0x1c0/0x200 > > While at it, fix the possible NULL pointer dereference in other > functions as well: of_thermal_get_temp(), of_thermal_set_emul_temp(), > of_thermal_get_trend(). > > Cc: stable@vger.kernel.org > Suggested-by: David Collins > Signed-off-by: Subbaraman Narayanamurthy > --- > Changes for v2: > - Added checks in of_thermal_get_temp(), of_thermal_set_emul_temp(), of_thermal_get_trend(). > > drivers/thermal/thermal_of.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index 6379f26..9233f7e 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -89,7 +89,7 @@ static int of_thermal_get_temp(struct thermal_zone_device *tz, > { > struct __thermal_zone *data = tz->devdata; > > - if (!data->ops->get_temp) > + if (!data->ops || !data->ops->get_temp) > return -EINVAL; > > return data->ops->get_temp(data->sensor_data, temp); > @@ -186,6 +186,9 @@ static int of_thermal_set_emul_temp(struct thermal_zone_device *tz, > { > struct __thermal_zone *data = tz->devdata; > > + if (!data->ops || !data->ops->set_emul_temp) > + return -EINVAL; > + > return data->ops->set_emul_temp(data->sensor_data, temp); > } > > @@ -194,7 +197,7 @@ static int of_thermal_get_trend(struct thermal_zone_device *tz, int trip, > { > struct __thermal_zone *data = tz->devdata; > > - if (!data->ops->get_trend) > + if (!data->ops || !data->ops->get_trend) > return -EINVAL; > > return data->ops->get_trend(data->sensor_data, trip, trend); > @@ -301,7 +304,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, > if (trip >= data->ntrips || trip < 0) > return -EDOM; > > - if (data->ops->set_trip_temp) { > + if (data->ops && data->ops->set_trip_temp) { > int ret; > > ret = data->ops->set_trip_temp(data->sensor_data, trip, temp); > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog