Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3548597pxb; Mon, 24 Jan 2022 11:58:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJ2Wo/BlHqa9m/FTBq+tzXn/BxZNWDohj+ITxYDwoI4Rr4HWrAqmC4o4GEwW1rDa3NG2nG X-Received: by 2002:a17:902:8f82:b0:14a:c442:8ca5 with SMTP id z2-20020a1709028f8200b0014ac4428ca5mr15392927plo.31.1643054339142; Mon, 24 Jan 2022 11:58:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054339; cv=none; d=google.com; s=arc-20160816; b=ezeQOaOjEG7SOWcQ2EmawmSPVq9f84uxkslU1K3T7sS0cBH+oZpLKSuqhScuz1Qd7A zt4qkj7ynJZOtLhUaOBsHtY19gA1CamTlT1AVosCegnbCflCx9+uQsownY4sUjbPcZ4u vop8X8fhKNQ+repIJwpkRFTCJzJdomtU31ltx9ACe12n+zEyTaH55nJudAEWOfxl1IaN ldmJ5w7sQDof5T5SG42V2Tmc0C1c+n14rTLSFRgSuEWYrQ2gH8mMHxt4CbkykS8HAlXK 0TClzUsypw+neZvAi72P3p1zXWjZd3PJbZBG6eKZg4qO1brFv3Ra7AC3/6Y8cILuenfJ 9ImQ== 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=S5Adoh4mYgF6ELAhHGjF68ayqtoN/5mPSCJR0GVq3Sg=; b=yR3iECHRlvG14GVb3Km7avOVPvk8lOpLXgQpgROUioog3zcBojUeRutMWIRhnHEKwy AqF/OE6jd3J7tfEa1TqY7nqJD1IE/USvCMs9qCowHZnr8t7+h/qqMt+3orMsynyW/wgC vcns+UZyrLYa7smrdxdL/SJp1HSBajRRriDQC4Y7rZx3WGOO8sq+m2mrZAVgio2TvFP4 b4YEmq6lW7VuJnzHxHUQq1bQZsRGEkZn41h9FnB4X3MUkD1di8a4ZzQQkjHuj/+9wR8Z AjLjH+UYELleign6ID3NsnNtdFjIlI7SPOPAv6Lu8/16RoJl/fVwM4he6fdWcn5GzYTZ zyfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VdiHkR3E; 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 s8si15023429pgg.581.2022.01.24.11.58.44; Mon, 24 Jan 2022 11:58:59 -0800 (PST) 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=VdiHkR3E; 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 S245556AbiAXS4I (ORCPT + 99 others); Mon, 24 Jan 2022 13:56:08 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:52686 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245338AbiAXSyG (ORCPT ); Mon, 24 Jan 2022 13:54:06 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 20B95B8122F; Mon, 24 Jan 2022 18:54:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C234C340E5; Mon, 24 Jan 2022 18:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050443; bh=ttM8YBV/tYxefzD0DSRUsWriYStpWazeCAtSPZpQEGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VdiHkR3EgoDNdpDgiLwNT/TbPvnV8tE5CSdJUKx3EPo7vZMChZGtVVcbf0B6ZiUCy OXMvIbyzobK8wvvsRnYyM+9R/+fA6e4myn6edBgiljM4grydGF8MgmcUk+elaSRHpI yDgQU8yo1LMbYF9bLbnArOCKsC6yx/Zmqezr+5Tw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Christophe Leroy , Sasha Levin Subject: [PATCH 4.4 091/114] w1: Misuse of get_user()/put_user() reported by sparse Date: Mon, 24 Jan 2022 19:43:06 +0100 Message-Id: <20220124183929.921111897@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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: Christophe Leroy [ Upstream commit 33dc3e3e99e626ce51f462d883b05856c6c30b1d ] sparse warnings: (new ones prefixed by >>) >> drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected char [noderef] __user *_pu_addr @@ got char *buf @@ drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: expected char [noderef] __user *_pu_addr drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: got char *buf >> drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected char const [noderef] __user *_gu_addr @@ got char const *buf @@ drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: expected char const [noderef] __user *_gu_addr drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: got char const *buf The buffer buf is a failsafe buffer in kernel space, it's not user memory hence doesn't deserve the use of get_user() or put_user(). Access 'buf' content directly. Link: https://lore.kernel.org/lkml/202111190526.K5vb7NWC-lkp@intel.com/T/ Reported-by: kernel test robot Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/d14ed8d71ad4372e6839ae427f91441d3ba0e94d.1637946316.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/w1/slaves/w1_ds28e04.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/w1/slaves/w1_ds28e04.c b/drivers/w1/slaves/w1_ds28e04.c index 365d6dff21de2..83c5864891424 100644 --- a/drivers/w1/slaves/w1_ds28e04.c +++ b/drivers/w1/slaves/w1_ds28e04.c @@ -39,7 +39,7 @@ static int w1_strong_pullup = 1; module_param_named(strong_pullup, w1_strong_pullup, int, 0); /* enable/disable CRC checking on DS28E04-100 memory accesses */ -static char w1_enable_crccheck = 1; +static bool w1_enable_crccheck = true; #define W1_EEPROM_SIZE 512 #define W1_PAGE_COUNT 16 @@ -346,32 +346,18 @@ static BIN_ATTR_RW(pio, 1); static ssize_t crccheck_show(struct device *dev, struct device_attribute *attr, char *buf) { - if (put_user(w1_enable_crccheck + 0x30, buf)) - return -EFAULT; - - return sizeof(w1_enable_crccheck); + return sysfs_emit(buf, "%d\n", w1_enable_crccheck); } static ssize_t crccheck_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - char val; - - if (count != 1 || !buf) - return -EINVAL; + int err = kstrtobool(buf, &w1_enable_crccheck); - if (get_user(val, buf)) - return -EFAULT; + if (err) + return err; - /* convert to decimal */ - val = val - 0x30; - if (val != 0 && val != 1) - return -EINVAL; - - /* set the new value */ - w1_enable_crccheck = val; - - return sizeof(w1_enable_crccheck); + return count; } static DEVICE_ATTR_RW(crccheck); -- 2.34.1