Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3719527pxb; Mon, 24 Jan 2022 16:15:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKIO/7lj08bItgM6s1Za6zVSkvo44wOROGmU/Wg9FMwSGqy7aSIGPlly7rtI+4bLeH5x8g X-Received: by 2002:a17:903:249:b0:149:dbf7:2753 with SMTP id j9-20020a170903024900b00149dbf72753mr16739166plh.101.1643069732637; Mon, 24 Jan 2022 16:15:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069732; cv=none; d=google.com; s=arc-20160816; b=PDoCzS42NOdUIDXftSrkPOTqosP04862MsSNzBp/ZL1RDftYJrVcwnLiVBtyUmAA5I YIP5spA8h+EP/SfhcX//CRMzUNVLu0Pbg7GyI/XzN7faRs72pSr8gpWxOOg7hsyT4270 Tc9MR+YCVBo06Gp3TvEixeoHHZ0ro5HL3iJ4skZaYy1oMK6dGEOO7HAHOCeAXRYdIYvz MBMHtg8DZzj9hiRCfd+DXOLuCLMKMDmg8v0e3vNeioL3eO5Ot9IlQP7BR8X4MWsXtkEj pzrQxpJwi5lt7XTF1wdzUtVgiK9VvsGog2T7l5sFuli4pcG5UHg9i/wQUSz0tDo1tRm0 NkTQ== 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=AGNbiYCruSzhWgEztKW3dwsFra90iPBcyBh6B1NW9LY=; b=cimcxycV8xIyW9MKpvrab9yfMIYfMbeSc300mrkO50Mb8R2b9vW3Xak9hd1Owtxclh 3j1T8hPZVL1UGbBQrLNHwWeNtLTiujsnyMeeelDcmKQT85WaYLX/oSmFqY7K5GdOmjBv dEUce0ZlAX7QOWwr2Prs1WZQ8LFQ1C1mOoP5RU9/ZA3t8uJXKVQUZrZLxEQgbhqoGe7k UwE6TM+gCN+X+vnNtOsgomAUFI64oAA45gGfNEQArua+1zgouWCrtxJVjyl1QJwDKwM8 J+bHWddXNjf5Vila6mfo16hAmYLBm65rarQ9p8ay57zf+48btw5CZKdPct5F/mACoK7Z gpMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="cx/ch0OT"; 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 x6si12419187plb.319.2022.01.24.16.15.20; Mon, 24 Jan 2022 16:15:32 -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="cx/ch0OT"; 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 S2372650AbiAYAMI (ORCPT + 99 others); Mon, 24 Jan 2022 19:12:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1849615AbiAXX0Q (ORCPT ); Mon, 24 Jan 2022 18:26:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62D50C01D7E8; Mon, 24 Jan 2022 13:30:28 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 0050561028; Mon, 24 Jan 2022 21:30:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D80A9C340E4; Mon, 24 Jan 2022 21:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059827; bh=6YKiuUS8IB5VXSiZrYfnABL7p33uLb807OzSPrmlgRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cx/ch0OTCEOhJbwGd1ToMSX1kL5NNtM7BtykpSMa2oQCS+OI84mWejURG9RX/uDsm 2PdG7vEuCIZClAwe7SvF3+qp5RAdEG2hoVlQydsyOTlgwWjymz9v2EvIEhxlvQWlyb jVpCteBCtCPlSosvGbt8x2J3S1fPY69RBaqqAKEw= 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 5.16 0747/1039] w1: Misuse of get_user()/put_user() reported by sparse Date: Mon, 24 Jan 2022 19:42:16 +0100 Message-Id: <20220124184150.438766576@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 e4f336111edc6..6cef6e2edb892 100644 --- a/drivers/w1/slaves/w1_ds28e04.c +++ b/drivers/w1/slaves/w1_ds28e04.c @@ -32,7 +32,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 @@ -339,32 +339,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