Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3011078pxb; Mon, 18 Oct 2021 06:33:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/1K19y96ErHAZ2Cvitg22T1me7VLL5rZ5LBqVsKwv6u3qKx/I7o01fdmGqKUcLXkUB/Nn X-Received: by 2002:a63:ef01:: with SMTP id u1mr23745916pgh.336.1634564033433; Mon, 18 Oct 2021 06:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564033; cv=none; d=google.com; s=arc-20160816; b=tKmmA3c4pWG7co98cJpTIqPWjpG3l9ljeQ9V61AuctelAhgX+K52qzh1ss5/LlqxHq tjfMUJ00XNVZSgxwrrbHzV08s3jO4iSnBTk7RtjCnlZBRNMp3ezI/ndq0A7eBsA4dMtz eOHA8k7Ybi1f9y/Ue0qBrp5AHCKlaZjALASTMJldZSMkprURTvJPiDC3XL3BJsLDV8ee GuqpZ+yHndqaTF53S5z2kjpa5wa3AlkYYrnqUALp/ZVPda7MlZKGMYGpBuNj2amJKQn6 lKZKOLWi0lCLWna1v5CGgL4tkcaGNGwzvIeHXKW46FMPS8iy7jp+g7cThTekWLlGmTwN nDFw== 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=UPntFuZvQ+fwngdS7VOoPTeAOtB8LL3rfv7q9/QHvWs=; b=0cesrOcWKWFKa/5TBuhKA7IHLYIZDt234q0hWcVTlriX5cnl4Pv35uo5L9GivlQOYs D4dPyONv0/2lpA/CcM7cJudRz6sVIu4aU5Hzt6ahH4HeY5hOpciPx7Th7pipf3gUQI26 GZZVTlvDWqq73wSVpPcTtQNooP5CLPWbUMCrs8j4Lcmy8tg45Cszz8pPqPhdtvwqH8dz U80GmfZTkzjy0zb2b6BpHLHnuo2JqxhEAEBrWZSFvGzBcSGvw/1IqI2VlmngJJxXJMHk jvVE8X8SvBfsQVNmT8X2tiwQNrMbKaUhgdizYyh/avFR5/CvVJPo2ajaQ3BFi1HoiThk F7Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Sksa6BJG; 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 z13si27230956pjq.141.2021.10.18.06.33.40; Mon, 18 Oct 2021 06:33:53 -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=Sksa6BJG; 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 S231858AbhJRNd2 (ORCPT + 99 others); Mon, 18 Oct 2021 09:33:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:43870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232896AbhJRNbs (ORCPT ); Mon, 18 Oct 2021 09:31:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BADEB61350; Mon, 18 Oct 2021 13:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563732; bh=FGM35nTA62kE6flpMLAyrF6LD12iQJC9R0HgxLPllvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sksa6BJGYxs6auYFeWxwor6KrFQULqghQRcoKwym2hRjn0N1M3NDFw2Ks+dbcZ9dF y4TS6mkT50F1gaAtQTtpcnGIyBABB2C6pFA2VqlMqGlv7h6xxgZvX4x9Ym//87U7ke n1xS536OlLgn8gHuv8TnP43xC7KhFkkz6uoVlA7I= 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 4.19 42/50] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Date: Mon, 18 Oct 2021 15:24:49 +0200 Message-Id: <20211018132327.912316024@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132326.529486647@linuxfoundation.org> References: <20211018132326.529486647@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 @@ -123,7 +123,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;