Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3024406pxb; Mon, 18 Oct 2021 06:49:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyetLA3WjHG4Z+wsNyNjFvXNkM5CVrSXCQ6csFg7s/AIsUNgnu1Wnvjx+qlyByM9PM7KYnB X-Received: by 2002:a17:90a:3ec2:: with SMTP id k60mr48032247pjc.176.1634564997794; Mon, 18 Oct 2021 06:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564997; cv=none; d=google.com; s=arc-20160816; b=GZEdGiDmOHNAIh5B86gslwiKxZ46jMeobDd4/6zZYbfy4+sl19qP/0tkWgarD/jZE8 CtELZUTyaEZVfS1nisrdAGZ5dqZnf4uhw+ZFrBWKdglrMrgB3jwjDUj0QCq6lps+rPtx 0tudYhb9SQkUpG0YoaDdsxYH+8137sE0G4kyBG1CqZKCyR6gPlfwC9D38M7WqUb+C+a+ u20snG8G3QfKp63a5bVbX3wi8RSj4pulunbofIUdelwDsToQbf72emj6FpGlQWRtK7So 4O0de2YImQ0B5O9Xrb0xTOu/J+Pjmsbsrb4fHnDj+X8tlHOh1AsLrDoe7d/90GHlEiH7 LP8A== 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=H3CKNZ9Q86f4QmFNqgAJEA+52SH6Y5E5seLCsT5dOMYlieMLihURBYyGKdf++fDcx3 lBJRA9QefsApaZYwwAHDivU0tS8Z65rENWg+PJs6wi3DeazYi7wcElcTw8kFoU9Wu9/E tGWM8OV3Bev9Y0gzAWcTnbbMYsf/4ng80XUcPm9ddvaWltPWpZJaBOLXFwaKoEUPKy/4 AnQoBemxXVMApbm66wXvIBj989mB4TyarhbCPG+W6HdCFTHJSnJ/JEZm8cgGnkYJ4WOJ yyMDu9S/q2OTO0zKUxCzMrycdaY+e3as/FmhCdo/XnQMT1uQvIkMVgwlsXkhEwMNGKTc stIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dl5YG+Ft; 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 v12si23400677pfu.224.2021.10.18.06.49.36; Mon, 18 Oct 2021 06:49:57 -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=dl5YG+Ft; 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 S233945AbhJRNuI (ORCPT + 99 others); Mon, 18 Oct 2021 09:50:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:50498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbhJRNsQ (ORCPT ); Mon, 18 Oct 2021 09:48:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8216661350; Mon, 18 Oct 2021 13:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564215; bh=HRFTNtA+EIHY4T1vUwID7BP9b/K85QKNpgaRKClWL5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dl5YG+FtzjO7xSSxj/iA593iR4fq2Jv1lAI/kU/U5YVh/V/pP4zcx0dgdFLAJYC7j xflb4FcwORye/3b2HAhJSWp7xwZmlI2SMWgZ6vAK7IGMmnDjceVlBDHjqOqNA3XUqC sWZzGO0t1gIU71sK19Rdtfh8YAjV6R05u6aoeP2w= 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.10 085/103] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Date: Mon, 18 Oct 2021 15:25:01 +0200 Message-Id: <20211018132337.612532251@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132334.702559133@linuxfoundation.org> References: <20211018132334.702559133@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;