Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3033421pxb; Mon, 18 Oct 2021 07:01:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzAy19yXNFCNfhNTfN+uO7XxDQAiGRQyPgrCizckCi7e+6/DCuitbdFjeni+8iQdBy+jjT X-Received: by 2002:a17:90a:ea94:: with SMTP id h20mr48087110pjz.58.1634565667235; Mon, 18 Oct 2021 07:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565667; cv=none; d=google.com; s=arc-20160816; b=kO4W/h8cvOtcBUK0D5dVUG3Ho9qKHIDfc4LjZGqiuE+a0Roi4g57pVGO+kyTcUhB7g hQYhruyQvcOpplOgQ2fYmz0MF7HVknjW8s4pUMpDuoz1LO4wGQLwuLQALVujjffZ+smV lIk5uYrdz/wQlkh/NbOei+JyxsY2cI2falf3bi+3eZsKT2S36VwDwqt6jhX4ETAxa2X+ MUmPMX5SwBRb9sEht3LZdp7fU0QIL0sa3CXXk8WFfmmffuy/rUkIKSocjcCFIyMkcCIp R/expYKE7L3KmmtdB6LX2WgaSt8EVRhmVxsIGuxFMdIjpFgREz+c7DtkyxRknEmiSnel pfPw== 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=fnoNnENwroi3mLeZbhVeTpbhTFgqYjxAyZ5rwOVV/fc=; b=N4YjC5Kzf9Cb1ETfiB/Yen7WIUwJENfPc1+Lc8QES1BdV63Ok/Wrkdc3djHvwoQRKM e2hgp6aS+5aGPSYPdjEQY6Rrvt8geQrVZhTWSdhdRFM1nOjFHTMUckyTQrPsdmNMzW+i pkocuhxweu4WRg5yMq4GzEotpWpZ2KR0PPIidBiHunJkiJV0M5kemaguRUjefizj2xTh 7yunrcOjPj6LCN553LEtQjRURDVVjfWopSVxgSqj32ZHh1Dr9asM+JKqe+5DflsCWUgO uIrFdJsuOb04w8/HXVn01Exd+J+38KCpsRghAkc3786V4K0GwlM8D5sKbZcgci+Kb8N4 EhbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="tUAKat/5"; 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 v15si8807507pgj.38.2021.10.18.07.00.53; Mon, 18 Oct 2021 07:01:07 -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="tUAKat/5"; 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 S234202AbhJROB5 (ORCPT + 99 others); Mon, 18 Oct 2021 10:01:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:40796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234166AbhJRN75 (ORCPT ); Mon, 18 Oct 2021 09:59:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 284E861A7F; Mon, 18 Oct 2021 13:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564520; bh=HRFTNtA+EIHY4T1vUwID7BP9b/K85QKNpgaRKClWL5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tUAKat/5lmO+qWq1TJhTpdsGiVen+r1RqxDHiW1n88r4/k/bo1FdOSBGiwjIshXN1 6k5TBsO1Kz7REIX6u53AHb2UznN9OogDEHZ3Prg1Rxhj+HjXHFHjBUsVCf5iOmJQKm SJ2vIQzMSdTX+KuyBZxhS4v13zyYdHCsIaz5kFUE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vadim Pasternak , Hans de Goede Subject: [PATCH 5.14 121/151] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Date: Mon, 18 Oct 2021 15:25:00 +0200 Message-Id: <20211018132344.609478403@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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: Vadim Pasternak commit 9b024201693e397441668cca0d2df7055fe572eb upstream. Change kstrtou32() argument 'base' to be zero instead of 'len'. It works by chance for setting one bit value, but it is not supposed to work in case value passed to mlxreg_io_attr_store() is greater than 1. It works for example, for: echo 1 > /sys/devices/platform/mlxplat/mlxreg-io/hwmon/.../jtag_enable But it will fail for: echo n > /sys/devices/platform/mlxplat/mlxreg-io/hwmon/.../jtag_enable, where n > 1. The flow for input buffer conversion is as below: _kstrtoull(const char *s, unsigned int base, unsigned long long *res) calls: rv = _parse_integer(s, base, &_res); For the second case, where n > 1: - _parse_integer() converts 's' to 'val'. For n=2, 'len' is set to 2 (string buffer is 0x32 0x0a), for n=3 'len' is set to 3 (string buffer 0x33 0x0a), etcetera. - 'base' is equal or greater then '2' (length of input buffer). As a result, _parse_integer() exits with result zero (rv): rv = 0; while (1) { ... if (val >= base)-> (2 >= 2) break; ... rv++; ... } And _kstrtoull() in their turn will fail: if (rv == 0) return -EINVAL; Fixes: 5ec4a8ace06c ("platform/mellanox: Introduce support for Mellanox register access driver") Signed-off-by: Vadim Pasternak Link: https://lore.kernel.org/r/20210927142214.2613929-2-vadimp@nvidia.com Signed-off-by: Hans de Goede Signed-off-by: Greg Kroah-Hartman --- drivers/platform/mellanox/mlxreg-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/platform/mellanox/mlxreg-io.c +++ b/drivers/platform/mellanox/mlxreg-io.c @@ -141,7 +141,7 @@ mlxreg_io_attr_store(struct device *dev, return -EINVAL; /* Convert buffer to input value. */ - ret = kstrtou32(buf, len, &input_val); + ret = kstrtou32(buf, 0, &input_val); if (ret) return ret;