Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3015440pxb; Mon, 18 Oct 2021 06:39:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSgWDH0XBy4cALpa5vhVS0RYUg25Udt6wYiyxNRAiEpJ6qHtv9usQK6vXKg30pR2aT68nW X-Received: by 2002:a63:7404:: with SMTP id p4mr23426243pgc.222.1634564346292; Mon, 18 Oct 2021 06:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564346; cv=none; d=google.com; s=arc-20160816; b=XC4neoz98mASuuQTPNnWkmK+Gj/ANTJrQ08pahNsto8O4jAeuKlOuEUCUD5cpbsvg2 rqOv7vee0FihXxmzm5Y0Xn0yFRziXQhUN0uFJk77dSwlhVaX67ZXBIK6VFtcFauK3ZyN zqdkPRxLrOKsL7E4qC+sPs3zvVRcqj33YM+aOGy2zVR8jXgQR2QcfmI8Zl9Oztl9Cv/Z JBcniQ152A3NnVXRmkn40HX27DkLphbVBd6gaKFaamH9HYEnyLREydx/wwt0T2ToWC1C KgI+Dc8qBzGt8H/8ZOBDL4ooCU8d8iQ/5YgCJ3IeiITiAiqE2vC9taI4c3RRnY6w9IZ1 Oy+w== 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=a5/LMg7EH2BvCVrk0UgKPurHJQNCarnF7+sjFGQcyn+1ZZJF4JXa38KIYcUaIMo0+2 887ON0NkDcjRRQleJeP5vlX4HPYXb2mQiRO3ptaFyXu/pzxcWJ5QVy9DajucOdw/lKeh MsyQX6c3FqOqtZaT+avLPwmOiqkENjUpA5icmvTx/aBrIcwFKbun6UMjHnPmmqw0Lcy+ 11apqnZ7IDZuMQZcwQnL+ByK1zKR1ZJL/ziB1c6MRvczCNdht2lm1S9aHYdsU/5RpnvA UPxPUIm5y0qQUop/UmmEFXQKaljG9wepbDEL+QNkoF5GKHdQD/lOtwfoeAyenzNittwX HzCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h07rFXsM; 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 p2si30409005pjg.134.2021.10.18.06.38.49; Mon, 18 Oct 2021 06:39: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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h07rFXsM; 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 S232809AbhJRNjr (ORCPT + 99 others); Mon, 18 Oct 2021 09:39:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:54280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232115AbhJRNhp (ORCPT ); Mon, 18 Oct 2021 09:37:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48429613DB; Mon, 18 Oct 2021 13:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563899; bh=FGM35nTA62kE6flpMLAyrF6LD12iQJC9R0HgxLPllvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h07rFXsMLCBs3xP7l6KGw+Jpo5Njo8Yz72k1ByDhafRFqAK7cYSmNX8Bh6oJ5cYU1 ApiD0LUUtqI4Cpiibh238JqbgqYV7u8CAVlaU3LxrO4t0Qpue/bvJbyXoVs00np8k3 EReGr9ckAwFm5AciTUrSOc2ob+bq7VMi+8pa0264= 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.4 59/69] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Date: Mon, 18 Oct 2021 15:24:57 +0200 Message-Id: <20211018132331.426661817@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132329.453964125@linuxfoundation.org> References: <20211018132329.453964125@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;