Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3776326pxb; Mon, 4 Oct 2021 09:20:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDEfXgw8OYADJdMOgwfJmh2UKs5zoU2sZqWNz7UraObrITN1Je1GpMwlLYhBHeZQKCjSEq X-Received: by 2002:aa7:ccd8:: with SMTP id y24mr8803363edt.358.1633364450443; Mon, 04 Oct 2021 09:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633364450; cv=none; d=google.com; s=arc-20160816; b=p0m2N2JeVwJxiiXHfxADhfbt691EnwGvN94PXsH0cTSyadEzngVFAZg73/O2EMjjXw 7v0LfW/FCh/pqnenHd7EFFphfhq8symaJqSoYB6lq0PdR8f//caIaFXgnWkurbqjHEVV pZgDzskxvTxxtvtyWfEqCpFpIT9MIhKE6WagYIpJmsPqdzRFw24Ue+hgE89s+4+5lS+D zZF36FZyb653QsauzdvjgzA3szQLTjvFB75WU+DSrO42w4KB07mjKoPoOeZAyivIb7zU fy6T2AWXjzu786a3XkwMe+RcxVo6/3syDKw2ZcIf4gdJsZzjJBgEikqFwq3FiKwxpcoG uy6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aUi/mRAHXifscWdUwwz6wKoWXs268cva0iuzWl7woCI=; b=C+X1fef69PyqZiS5/KpYp0mQNP985tlHtZkQ7LVN1RJO4OA2WIR+lE+e1m8x1fIL2W 4OJ6BwIl2I24W8yWFOlH99ioSKAU/Emh8BDiANQWf0khEn06Oiy0VFuJu+zv4PXXohrL TtV6yNlblvVB7Af9oOD17kQuuQbdovlAVYncsd3V0dHSS2p6Zz5EeX/fPYJX4imft4+4 iDSx51NtykXA/CbntNSph60boM5WIz2ZD/ngvJ1MQUHB9Go7enj4lRqj8nQR1MdEFh3l 6LwBKTeE0+k4LZgGPciowQHbjmUZgQOA2bCZG4HJ8Wk5lcHUihhBOTn6MhS9Xiem6z1f wT3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=so7IIrI7; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u24si19827134ejn.615.2021.10.04.09.20.23; Mon, 04 Oct 2021 09:20:50 -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=@linuxfoundation.org header.s=korg header.b=so7IIrI7; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237449AbhJDNc1 (ORCPT + 99 others); Mon, 4 Oct 2021 09:32:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:43540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237762AbhJDNac (ORCPT ); Mon, 4 Oct 2021 09:30:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7321561B74; Mon, 4 Oct 2021 13:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353223; bh=X28Zg4aWw+lyjHmNQ5LZLvKHYQtbXNZ4nstGn3KQck8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=so7IIrI7fytXFbU39JQw34gAi699eJUmMOdTfXrEIGip4754BKwvLkAj06xW+uW6T KkqMbKEX4eCWAyRpsu5XqcQpUmgYKnjDnXcYZoANSnFGi4pJZe6sYAj0kXmAwmCVtN OoVn81ilAKHRX4++JBmpZs1ENhW+/Qjylal2iWIs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nadezda Lutovinova , Guenter Roeck Subject: [PATCH 5.14 043/172] hwmon: (w83791d) Fix NULL pointer dereference by removing unnecessary structure field Date: Mon, 4 Oct 2021 14:51:33 +0200 Message-Id: <20211004125046.377005148@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadezda Lutovinova commit 943c15ac1b84d378da26bba41c83c67e16499ac4 upstream. 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). Cc: stable@vger.kernel.org Signed-off-by: Nadezda Lutovinova Link: https://lore.kernel.org/r/20210921155153.28098-1-lutovinova@ispras.ru [groeck: Dropped unnecessary continuation lines, fixed multi-line alignment] Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/w83791d.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) --- 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 w837 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,22 +1276,19 @@ static int w83791d_detect_subclients(str } val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); - 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)); + + 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)) + 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; }