Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2231778ybt; Fri, 3 Jul 2020 04:18:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzFIH2wqNzV5YrlPlkzmkpTMNngHjQe0GQl7Hf4eVnFEokbwQpXEN7xOxCgZAYl6O2zTjW X-Received: by 2002:a17:906:8316:: with SMTP id j22mr30927247ejx.97.1593775086845; Fri, 03 Jul 2020 04:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593775086; cv=none; d=google.com; s=arc-20160816; b=cDDYeQQPd++1NBUkG+GVEkaBXgYFqV4Oxbph0VL55bqkXwasi7amERZe4EmVOtzTII rmoF89jqjhO1Ih2r7dGeAsaobRRF2q16q7GYBvrsaq2mVIkaeT4Lr5ZzFVIfUnl4GCW+ zIRocS9yhX8YKlCsO7PZUnaFBeJ4dlBMN1CEgICaXW9csKkznfNBMAAvier3pOyKuH98 Trg0oDCAyQ+EkwHpQoE+6lNr3f9TLuFcNIq/XuRiu9TF8bY21nlwWffzcZ5igKuaM9S/ Rf/WaGXJAxU43MsqCBeC/98g2XkcwNpHon2I31BYVkpGBpQpgi7S5UTokaT+CPqNC8N5 THyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=uGrkJ2gSF6Vm86iMC2FhmeBt4ffohVdSmnnn70ksIiI=; b=LgMi3AlNTp/NYxI7J1NW8PL2BQzEQFnHoWA0TGY2hawTuxStFOMMUanvQkpRcV5HFg RAHfW7/vYRlA4DL57WiWqVA/3yFx3WyWSUAhWly5ikNLJWUpTJ2uSEckS/Udtjl36oZq JyejJbdBQ7hbxgrDT3FF+uijZik825bSJ7Von+n3cExc5Fj9z6kkuT4Lytx5BsvJOTwk mC19cXwRJc2NdUhlMqZrL/04WepxyhDl2eCC/mD9nI3jx9T8JHvGNO6RSCrdRU6rVSRp +cgngM+Ru5ngSXHV7aGcKbosuUGqEYhown941QEQdIoUh7kjkb1jXJS9uEhB8N+mmYtZ 0gRg== 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 v22si7282472ejf.411.2020.07.03.04.17.43; Fri, 03 Jul 2020 04:18:06 -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 S1726244AbgGCLPi (ORCPT + 99 others); Fri, 3 Jul 2020 07:15:38 -0400 Received: from winnie.ispras.ru ([83.149.199.91]:10186 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726039AbgGCLPi (ORCPT ); Fri, 3 Jul 2020 07:15:38 -0400 Received: from home.intra.ispras.ru (unknown [10.10.165.12]) by smtp.ispras.ru (Postfix) with ESMTP id 8A042203C1; Fri, 3 Jul 2020 14:15:33 +0300 (MSK) From: Evgeny Novikov To: Jean Delvare Cc: Evgeny Novikov , Guenter Roeck , Joel Stanley , Andrew Jeffery , linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] hwmon: (aspeed-pwm-tacho) Avoid possible buffer overflow Date: Fri, 3 Jul 2020 14:15:18 +0300 Message-Id: <20200703111518.9644-1-novikov@ispras.ru> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org aspeed_create_fan() reads a pwm_port value using of_property_read_u32(). If pwm_port will be more than ARRAY_SIZE(pwm_port_params), there will be a buffer overflow in aspeed_create_pwm_port()->aspeed_set_pwm_port_enable(). The patch fixes the potential buffer overflow. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Evgeny Novikov --- drivers/hwmon/aspeed-pwm-tacho.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index 33fb54845bf6..3d8239fd66ed 100644 --- a/drivers/hwmon/aspeed-pwm-tacho.c +++ b/drivers/hwmon/aspeed-pwm-tacho.c @@ -851,6 +851,8 @@ static int aspeed_create_fan(struct device *dev, ret = of_property_read_u32(child, "reg", &pwm_port); if (ret) return ret; + if (pwm_port >= ARRAY_SIZE(pwm_port_params)) + return -EINVAL; aspeed_create_pwm_port(priv, (u8)pwm_port); ret = of_property_count_u8_elems(child, "cooling-levels"); -- 2.16.4