From patchwork Thu Aug 10 15:23:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vasilyev X-Patchwork-Id: 9893903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9FC1660384 for ; Thu, 10 Aug 2017 15:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B0B228B4D for ; Thu, 10 Aug 2017 15:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FE7228B60; Thu, 10 Aug 2017 15:23:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16AFC28B54 for ; Thu, 10 Aug 2017 15:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752381AbdHJPXq (ORCPT ); Thu, 10 Aug 2017 11:23:46 -0400 Received: from bran.ispras.ru ([83.149.199.196]:13533 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752168AbdHJPXq (ORCPT ); Thu, 10 Aug 2017 11:23:46 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id DFF395FB87; Thu, 10 Aug 2017 18:23:44 +0300 (MSK) From: Anton Vasilyev To: Jean Delvare Cc: Anton Vasilyev , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] hwmon:(stts751) buffer overread on wrong chip configuration Date: Thu, 10 Aug 2017 18:23:34 +0300 Message-Id: <1502378614-13011-1-git-send-email-vasilyev@ispras.ru> X-Mailer: git-send-email 2.7.4 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If stts751 hw by some reason reports conversion rate bigger then 9: ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE); then dereference stts751_intervals[priv->interval] leads to buffer overread. The path adds sanity check for value read from chip. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev --- drivers/hwmon/stts751.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c index d56251d..f6eddbd 100644 --- a/drivers/hwmon/stts751.c +++ b/drivers/hwmon/stts751.c @@ -718,6 +718,10 @@ static int stts751_read_chip_config(struct stts751_priv *priv) ret = i2c_smbus_read_byte_data(priv->client, STTS751_REG_RATE); if (ret < 0) return ret; + if (ret > ARRAY_SIZE(stts751_intervals)) { + dev_err(priv->dev, "Unrecognized conversion rate 0x%x\n", ret); + return -ENODEV; + } priv->interval = ret; ret = stts751_read_reg16(priv, &priv->event_max,