Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2847246pxb; Tue, 21 Sep 2021 08:56:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD7+7eC8EBjZBljTwPB7R7CneDRC4ca0w7AgCu0nUrb4/YrxN4fyb6/VIhpIpgqWhmpte+ X-Received: by 2002:a05:6638:a2d:: with SMTP id 13mr637393jao.12.1632239773153; Tue, 21 Sep 2021 08:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632239773; cv=none; d=google.com; s=arc-20160816; b=uJ5u0HxtzMgND+GNtjO3iHXZhruyTg92QcPNV+04fvDZKDXxRywFgs6gCRBkcFqCuP GIkoGyao5ibpPhnRNv2XcK8ap97U+x6G99+a3ieSO8kSBEYmOrp3UQsUgpWaY9hpApu1 6iGlcd7ezDMG5dq9uvhhFYkgtHuU484JPqEnIDsaOpVvBeCbTLRu+Qm2c+u+HfYgRydi u7XbThk/YAuSGV7s+Sdog1ombpFaGb4RFn1tzhOpTkRuDheG6tLhbgd6HZCZ1IKyWtIE ZmpZPSqNMvl3wxehZKf3SZhycDwRL7dWVROrLXN/aJ7Cm9XC0bDzoPYmDbR3SGR1dB+G I+HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:in-reply-to:message-id :date:subject:cc:to:from; bh=XxW5jf4rxpbywTSpN7ioTUhD41vp3KrNd3D7gdGXg4M=; b=qj15n56PCjFBjciiej89MBccofkvEYTd+PXV7jKLz5F1D4zlIWzQHxH8uFdhp0kDyq gOPXHYCxD5wjjIBcrdXkyR9B2KjfzI1avaYBEWaIYv04jqpuKlWvm1nj4AGvasYyjcmL k20MZB65uQbAsP1ic3Ch5VBIGekQA7Mtzqwudn0g8MBpn0vcJmig3dFttIRCbXRnN2lW rJx9r67zOLZmD7fqS7Q184QkbUHyK1WqUbH7HyfuF2h3Dvjf744tOjnBeHeEQclsFLBl sJ4Ai9PvAbcoSf1S0+DSCaXCKXRhzcCV7g4NSy1cKnyh5zN6ndwvPEZbRMJ2b3COCF0d nAhw== 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=ispras.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si925049ioc.9.2021.09.21.08.56.02; Tue, 21 Sep 2021 08:56:13 -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=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbhIUPyg (ORCPT + 99 others); Tue, 21 Sep 2021 11:54:36 -0400 Received: from mail.ispras.ru ([83.149.199.84]:50732 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234319AbhIUPyO (ORCPT ); Tue, 21 Sep 2021 11:54:14 -0400 Received: from kleverstation.intra.ispras.ru (unknown [10.10.2.220]) by mail.ispras.ru (Postfix) with ESMTPS id 40BFC40755E9; Tue, 21 Sep 2021 15:52:44 +0000 (UTC) From: Nadezda Lutovinova To: Guenter Roeck Cc: Nadezda Lutovinova , Marc Hulsman , Rudolf Marek , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH v2 3/3] hwmon: (w83793) Fix NULL pointer dereference by removing unnecessary structure field Date: Tue, 21 Sep 2021 18:51:53 +0300 Message-Id: <20210921155153.28098-3-lutovinova@ispras.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210921155153.28098-1-lutovinova@ispras.ru> References: <20210921155153.28098-1-lutovinova@ispras.ru> In-Reply-To: <20210811181844.GB3138792@roeck-us.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If driver read tmp value sufficient for (tmp & 0x08) && (!(tmp & 0x80)) && ((tmp & 0x7) == ((tmp >> 4) & 0x7)) from device then Null pointer dereference occurs. (It is possible if tmp = 0b0xyz1xyz, where same literals mean same numbers) Also lm75[] does not serve a purpose anymore after switching to devm_i2c_new_dummy_device() in w83791d_detect_subclients(). The patch fixes possible NULL pointer dereference by removing lm75[]. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Nadezda Lutovinova --- v2: - split one file per patch - remove lm75[] instead of adding checking --- drivers/hwmon/w83793.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index e7d0484eabe4..4ee96756ed49 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c @@ -202,7 +202,6 @@ static inline s8 TEMP_TO_REG(long val, s8 min, s8 max) } struct w83793_data { - struct i2c_client *lm75[2]; struct device *hwmon_dev; struct mutex update_lock; char valid; /* !=0 if following fields are valid */ @@ -1566,7 +1565,6 @@ w83793_detect_subclients(struct i2c_client *client) int address = client->addr; u8 tmp; struct i2c_adapter *adapter = client->adapter; - struct w83793_data *data = i2c_get_clientdata(client); id = i2c_adapter_id(adapter); if (force_subclients[0] == id && force_subclients[1] == address) { @@ -1586,20 +1584,21 @@ w83793_detect_subclients(struct i2c_client *client) } tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); + + if (!(tmp & 0x88) && (tmp & 0x7) == ((tmp >> 4) & 0x7)) { + dev_err(&client->dev, + "duplicate addresses 0x%x, use force_subclient\n", + 0x48 + (tmp & 0x7)); + return -ENODEV; + } + if (!(tmp & 0x08)) - data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, - 0x48 + (tmp & 0x7)); - if (!(tmp & 0x80)) { - if (!IS_ERR(data->lm75[0]) - && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { - dev_err(&client->dev, - "duplicate addresses 0x%x, " - "use force_subclients\n", data->lm75[0]->addr); - return -ENODEV; - } - data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, - 0x48 + ((tmp >> 4) & 0x7)); - } + devm_i2c_new_dummy_device(&client->dev, adapter, + 0x48 + (tmp & 0x7)); + + if (!(tmp & 0x80)) + devm_i2c_new_dummy_device(&client->dev, adapter, + 0x48 + ((tmp >> 4) & 0x7)); return 0; } -- 2.17.1