Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4589864pxt; Wed, 11 Aug 2021 09:19:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY/SR2HzblJRfm5vFHeH7Knx7zAaQMXHyTnkA8EdIbDhZGY7nDyhWSPSt/E7EywBd6LSae X-Received: by 2002:a17:906:3707:: with SMTP id d7mr4506169ejc.127.1628698780541; Wed, 11 Aug 2021 09:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628698780; cv=none; d=google.com; s=arc-20160816; b=JPFoypRxo273+TDzwfDXCLIhpMPMjL9xq/Plv5xj7ubMJjJxwhwvNgoUpDnEAxwUcY Ib0/rK1Km8w/F7fRPo+cmOwnXQdgBdQ4RuZBHUN4Rhw04YENxmc2oLg/QK9hJDYWSg43 B6SCnT5L3CBBFaFttwZ2rKZeTkU3owPjQJEPAgroMUAaGanLZ9k+oZkUeo1INDlCT9We 5wCT7BvPDTLavVZjGfbDHzvh0ZxudNhfIHxxGHIyXpqoDKPpFNz3TPQdKC92G48/cpnq 36sQLn84qw96birDVtR62fJx2DAFQstDXqnXYSgMjFfD63/l0ahCqGdu+dveXrMXcRi3 SNJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=5NyLJibXZTAQInYD7e1ZKDqCcoW5AYp/uYQ3OpaoSO4=; b=lUPpjvLlf8n9huh993hZJSAw5NfAqBCr0rxwitpPAqvbByaucyux70WnSiwJLcYEvM FdH2RYucdSlTlktFalN2KM+RAIAnkOr8yEc/Dhcw5pbQURrOvncstjV7rZD2TDkgpVgQ 3j6j8amiy+46KuQbQ/5PxsYHFkCrIYidgRFrwokPKYCUxnnKjgeO+P70vKu+72LSxCyq c1u0MbXzY7aigQJBxxtvpSDV48uI8egQlN3P2npL1h9jDzj1u3EZLoz3y6BvziXXKeea aiYzctzkhgYD5w7iwmSGIfszBnpIJ8YSl60+z7MLjrwCzhqVhociL1skN7VCSuxZxXxS wFuw== 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 r26si14567202edw.396.2021.08.11.09.19.16; Wed, 11 Aug 2021 09:19:40 -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 S229817AbhHKQQP (ORCPT + 99 others); Wed, 11 Aug 2021 12:16:15 -0400 Received: from mail.ispras.ru ([83.149.199.84]:32874 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbhHKQQO (ORCPT ); Wed, 11 Aug 2021 12:16:14 -0400 Received: from kleverstation.intra.ispras.ru (unknown [10.10.2.220]) by mail.ispras.ru (Postfix) with ESMTPS id 359C2407625F; Wed, 11 Aug 2021 16:15:49 +0000 (UTC) From: Nadezda Lutovinova To: Marc Hulsman Cc: Nadezda Lutovinova , Jean Delvare , Guenter Roeck , Rudolf Marek , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] hwmon: Correct the error handling in w83793.c, w83791d.c, w83792d.c Date: Wed, 11 Aug 2021 19:15:15 +0300 Message-Id: <20210811161515.17842-2-lutovinova@ispras.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210811161515.17842-1-lutovinova@ispras.ru> References: <20210811161515.17842-1-lutovinova@ispras.ru> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If driver read tmp (or val) 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) The patch adds checking if data->lm75[0] is NULL. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Nadezda Lutovinova --- drivers/hwmon/w83791d.c | 2 +- drivers/hwmon/w83792d.c | 2 +- drivers/hwmon/w83793.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 37b25a1474c4..8b30bbfafaa7 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c @@ -1284,7 +1284,7 @@ static int w83791d_detect_subclients(struct i2c_client *client) data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7)); if (!(val & 0x80)) { - if (!IS_ERR(data->lm75[0]) && + if (!IS_ERR_OR_NULL(data->lm75[0]) && ((val & 0x7) == ((val >> 4) & 0x7))) { dev_err(&client->dev, "duplicate addresses 0x%x, " diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index abd5c3a722b9..85ae12d950e1 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c @@ -950,7 +950,7 @@ w83792d_detect_subclients(struct i2c_client *new_client) data->lm75[0] = devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7)); if (!(val & 0x80)) { - if (!IS_ERR(data->lm75[0]) && + if (!IS_ERR_OR_NULL(data->lm75[0]) && ((val & 0x7) == ((val >> 4) & 0x7))) { dev_err(&new_client->dev, "duplicate addresses 0x%x, use force_subclient\n", diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index e7d0484eabe4..9d8c44e2fa6e 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c @@ -1590,7 +1590,7 @@ w83793_detect_subclients(struct i2c_client *client) data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (tmp & 0x7)); if (!(tmp & 0x80)) { - if (!IS_ERR(data->lm75[0]) + if (!IS_ERR_OR_NULL(data->lm75[0]) && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { dev_err(&client->dev, "duplicate addresses 0x%x, " -- 2.17.1