Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2846833pxb; Tue, 21 Sep 2021 08:55:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJPWZ0iL/LDARx8QjA/wLJHGMv/IsqEJmArmwPOOTvtq5FU4ngpq3wMedYP36h7vpFyXPh X-Received: by 2002:a05:6638:13d5:: with SMTP id i21mr605490jaj.55.1632239737937; Tue, 21 Sep 2021 08:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632239737; cv=none; d=google.com; s=arc-20160816; b=aWQ8VNYxOZGmEinTmGH9eimosybP7vD2+xPiQbxYDkeP0khLb0DWKixKxBau2gPTP/ oWAB3e38hWkUS7viRc01gNhmWhUm3qiaUL9YFsE1A8A+j95jwSNRItHAISbSc4WYE8DS 8Sf+zP2OH7mRQSRqYukTAJsQX8fEbW196KVvFQ6ezcSECfmdxJImL+V+5nr1hk3dwZGB hve+VS8lIxW+d6sfHMvgjoUC/pX29dCAjlUaSeNiVHWrh9g1C3eAUtO16I1WGyo5TuBv JWjvcn+DyAssW/05TnJbLibfYcLC6odx9QXNfKy9omIBsH3y/Yn5GPonW/4iI3HMCRDx vrWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:message-id:date:subject:cc:to:from; bh=+fjiGqQkebj8DVq6sTEYkknspPkBVjde9Y/Hi9l3WNA=; b=cyHmPMtResvzcY+9kRyGjNlrKCE3vcVl0EfucegWk08kzGSAXWPXtrIQrj6q2swtib t6gXnnSrkn7ksVOarDWDKQGZyJJi1hRRBCmOwYJhYI7/doYeRIjmOHVs7V75J9f00h6j 96Jffp0mVkvN50flbdy7/1LW6or/eR4AiNgfykk6iev9GbMQOxVBXYm1NNZbGPvc8s2v y25o3UiIouVly2wQ4P71lt2BQ2ajcZkczzK3L4yFtgqxwU6EG2fB2AIxRrJHAUSsJzi1 4u2bH7jloze9H6kNKfVvEadAPMR8222oKptgLjxt1I6mW4ExomN5uebP74Sh9owLL+Vd j8Jw== 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 o16si14359869ilh.153.2021.09.21.08.55.24; Tue, 21 Sep 2021 08:55:37 -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 S234190AbhIUPy3 (ORCPT + 99 others); Tue, 21 Sep 2021 11:54:29 -0400 Received: from mail.ispras.ru ([83.149.199.84]:50686 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234231AbhIUPyJ (ORCPT ); Tue, 21 Sep 2021 11:54:09 -0400 Received: from kleverstation.intra.ispras.ru (unknown [10.10.2.220]) by mail.ispras.ru (Postfix) with ESMTPS id E5DCC40D3BFF; Tue, 21 Sep 2021 15:52:34 +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 1/3] hwmon: (w83791d) Fix NULL pointer dereference by removing unnecessary structure field Date: Tue, 21 Sep 2021 18:51:51 +0300 Message-Id: <20210921155153.28098-1-lutovinova@ispras.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210811181844.GB3138792@roeck-us.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If driver read val value sufficient for (val & 0x08) && (!(val & 0x80)) && ((val & 0x7) == ((val >> 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/w83791d.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 37b25a1474c4..b4eae45859c1 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c @@ -273,9 +273,6 @@ struct w83791d_data { char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ - /* array of 2 pointers to subclients */ - struct i2c_client *lm75[2]; - /* volts */ u8 in[NUMBER_OF_VIN]; /* Register value */ u8 in_max[NUMBER_OF_VIN]; /* Register value */ @@ -1257,7 +1254,6 @@ static const struct attribute_group w83791d_group_fanpwm45 = { static int w83791d_detect_subclients(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; - struct w83791d_data *data = i2c_get_clientdata(client); int address = client->addr; int i, id; u8 val; @@ -1280,21 +1276,21 @@ static int w83791d_detect_subclients(struct i2c_client *client) } val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); + + if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) { + dev_err(&client->dev, + "duplicate addresses 0x%x, use force_subclient\n", + 0x48 + (val & 0x7)); + return -ENODEV; + } + if (!(val & 0x08)) - data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, - 0x48 + (val & 0x7)); - if (!(val & 0x80)) { - if (!IS_ERR(data->lm75[0]) && - ((val & 0x7) == ((val >> 4) & 0x7))) { - dev_err(&client->dev, - "duplicate addresses 0x%x, " - "use force_subclient\n", - data->lm75[0]->addr); - return -ENODEV; - } - data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, - 0x48 + ((val >> 4) & 0x7)); - } + devm_i2c_new_dummy_device(&client->dev, adapter, + 0x48 + (val & 0x7)); + + if (!(val & 0x80)) + devm_i2c_new_dummy_device(&client->dev, adapter, + 0x48 + ((val >> 4) & 0x7)); return 0; } -- 2.17.1