From patchwork Wed Nov 16 00:43:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 20648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3023619wru; Tue, 15 Nov 2022 16:57:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf7krl17SYWP/2RAgFmd0rsn5zC+Yk9NTk57xAxLW2qK31pM7XAuYti6G53iIZnXvtQcnU1e X-Received: by 2002:a17:906:ce57:b0:7ad:e161:b026 with SMTP id se23-20020a170906ce5700b007ade161b026mr16261438ejb.760.1668560260790; Tue, 15 Nov 2022 16:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668560260; cv=none; d=google.com; s=arc-20160816; b=Tm/lvQfTxz3fxq9pv6CU4tLOYp69QcUWWzhaQIrR2ERlVxsA3duxhR4hzEjd3fwq1E XQKIUnUlANs3Gxd1jVxC7vz3Iko8vH1CfiIdnpFDrGZCdjpixWSwKcKQxhEjdZ2ub3x8 wmL8F0pRkhr91P2zV43xlOYaXjtMlqMrtIH43RTYWxsbHgNaTWIMG2/dmq7j6UepW3ff V+UAUgmbYevqoJyDbf8CgM6O5i4rQf9dm8HNHpfmS5EJnGisdlbwPmo1r+7XJOEhsgqA 6MzMjq25sjmGnu5sEXJMdyoHKo7oSKcGMXzK5+Td71QR6T/yWLxaHRpMWIuybZWdwaJL kLNw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cU6m8eO+ydCEi5cf0Xms8cd7fTO0WN29mHit+UF5opI=; b=RNE/QYkKhYnyrszdrb2H/gtAkLSpv+A+UVyp7xm8U4A3Oh3QXJ7IT3hgqp0gamNEri f7ktWC5zysVb3f8Lk6Ros7l4Z51ieRXNmyBr3TyHJXoxF+ngS5jzVPTePLzDof0IaSPT h19aDgxUo8+UIHoLYLd0AbBl7R5BS6tzFrDArzLpgFHP+h9UW8GCQvCZrtUxtmi20rAb 9rWgFnYYCLuh1Usp28LvxZKB//wfGwkBDzID4oAS7hVtLrZ2dUanv25pPWhsDWhL4y+W Uhf39ZsjXo4wrQVFJOArWRMeHfNhyaeOJMpoSkKhhC+ntY/u2OP9bkFSMfEnL2PURoq5 u6LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WGzt4t8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z9-20020a50cd09000000b0046462065e1dsi12138529edi.291.2022.11.15.16.57.10; Tue, 15 Nov 2022 16:57:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WGzt4t8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231398AbiKPAoK (ORCPT + 99 others); Tue, 15 Nov 2022 19:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbiKPAoG (ORCPT ); Tue, 15 Nov 2022 19:44:06 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 410E32AC7D for ; Tue, 15 Nov 2022 16:44:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668559445; x=1700095445; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IhFBAznLG1DY+6oqG9WaOOSep20Baj1si3bnp+y4wkA=; b=WGzt4t8oEe5VRtFUZSR9YTHmXHXLsYKP2c8+bU7oFvYlMauG+nxZmu9L tH2CnGuEz3Gx24ZjqyGwvCZzgtHNo7WtSQV+/jox/Zoeu3qp+blZOPNB7 kEwW3NQJ9IJ+DyHVEexlsgWsXlzdu+aanSNcnHfc6t0v8F0NWg2zyAILo xKVxQ/iYDwC3S7l7FomA1xRVW/DR3x5F3lhD7vGJGSQawOD8AX9XEZag/ uMNpO27m6Na2Cp+ARsgCOHLr5hc3fDsKYNTAS7hXdnMEhtGTqptTuLnsQ h7gK0r6xmGBheHHOoRVqgGOLK+/1yF1X7xKGFyrT3s1jKRof06nobx1SZ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="299935334" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="299935334" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 16:44:04 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="707941468" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="707941468" Received: from nrobin-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.45.56]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 16:44:01 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 19A4110443E; Wed, 16 Nov 2022 03:43:59 +0300 (+03) From: "Kirill A. Shutemov" To: kirill@shutemov.name Cc: dave.hansen@intel.com, dave.hansen@linux.intel.com, jejb@linux.ibm.com, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, lkp@intel.com, martin.petersen@oracle.com, oe-kbuild-all@lists.linux.dev, x86@kernel.org Subject: [PATCH 1/2] scsi: Fix get_user() in call sg_scsi_ioctl() Date: Wed, 16 Nov 2022 03:43:52 +0300 Message-Id: <20221116004353.15052-2-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221116004353.15052-1-kirill.shutemov@linux.intel.com> References: <20221115155802.p3vjnk7eqqcyskt3@box.shutemov.name> <20221116004353.15052-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749612244217627281?= X-GMAIL-MSGID: =?utf-8?q?1749612244217627281?= get_user() expects the pointer to be pointer-to-simple-variable type, but sic->data is array of 'unsigned char'. It violates get_user() contracts. Cast it explicitly to 'unsigned char __user *'. It matches current behaviour. This is preparation for fixing sparse warnings caused by Linear Address Masking patchset. Signed-off-by: Kirill A. Shutemov Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Signed-off-by: Kirill A. Shutemov --- drivers/scsi/scsi_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c index 2d20da55fb64..72b3ab5137b8 100644 --- a/drivers/scsi/scsi_ioctl.c +++ b/drivers/scsi/scsi_ioctl.c @@ -519,7 +519,7 @@ static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode, return -EFAULT; if (in_len > PAGE_SIZE || out_len > PAGE_SIZE) return -EINVAL; - if (get_user(opcode, sic->data)) + if (get_user(opcode, (unsigned char __user *)sic->data)) return -EFAULT; bytes = max(in_len, out_len); From patchwork Wed Nov 16 00:43:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 20647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3022811wru; Tue, 15 Nov 2022 16:54:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf6rjhTsayUeviCYZwfwZJGg7WEfuc6bj8I6/6WnddUBqCDrQ8zCVNfmd0Z/lWZtbQd3+CmW X-Received: by 2002:a05:6402:28e:b0:461:c937:da3b with SMTP id l14-20020a056402028e00b00461c937da3bmr17252590edv.41.1668560056181; Tue, 15 Nov 2022 16:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668560056; cv=none; d=google.com; s=arc-20160816; b=MAElmlzBHRpgU9g9fvCSKa7e8IRguUp/SYmMNwGAw3pIck4KSdlkdaMMsLJmPBLVOe uECQKKJ96mfRwki81sMzAgUovj2EYtBEbUPBqm9CxfY9I08lUZm5p6hLtXHnmpLjXVoe R5EbcDGQGpb0XW1++fjE3VWAzVe/8Ec3Zqmn5sY3TTCWR0z5cnNq4UoN3PbboCqHWCYS BDQdPKiQuMbVJKNOfWRVznfI6DIaXh4BM5CMBHdPZ26TJ+SRa6gEB8k8y00K3M2ZTV21 WNOrX8MFnNoo0oqyhT08XaL0r+zzASKDZER8er7KeUFC/sYE/teHyJw9lpxfgFoUROKP nuug== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yBDkad18DYBUQR+uT2DmEQabpeakka2GcSiqcGhrPTk=; b=btRnSQKhcLRnmuFMfYdIUfdV+R38TLJD7R20qDxqRD1bDN+dSa0ehv5udddIW3hstw VZ1u+K3kZPb9Wn2icAWWmlk3UpxqxD6hkgbpB6w+Plr5q4ZWL+9LmujwptwGLsuM8MuZ hAE2FKtAB2GQpu6MYMnFvCrg0INepzNVT+cPDIC+QFlqS1aW4UB5C9htzuLLwt1QVztk 2hiiwbSlnaFc9v2ZtQ9Vgp+PxQm0IaB831aPMlTSIivLEcNNTKyV0nq2uRI+zLWslxRe QCPmww3woq5zGs4CWEtq4uQ22c6Liw1UPzb8SyR/No+dkwHQHJ0tHADoNUR0HNeIzyJA vVmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QWcsbQT8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj10-20020a170906b04a00b0078dc5c888f1si11745223ejb.135.2022.11.15.16.53.51; Tue, 15 Nov 2022 16:54:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QWcsbQT8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbiKPAoJ (ORCPT + 99 others); Tue, 15 Nov 2022 19:44:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbiKPAoG (ORCPT ); Tue, 15 Nov 2022 19:44:06 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44DDF2BB15 for ; Tue, 15 Nov 2022 16:44:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668559445; x=1700095445; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tx19St9qzi0HfKCU80s71CDjOvtppRUy1zquC1kpDYM=; b=QWcsbQT8PktRUKx+mk+1Ijk0qlzdQu37u8+bN+DR+4kshHfGm1rkezeM LioqLDKtlHQCzA/WPTr/6rH/rBj7bgIdNcIp+jOW1MjwcTpTlh/rLtKId PHhBUNIgAvZyytAkqicx4ACxhipp/QB1ovpzCfP61r78f3wLw8rPKeXkc q9p+Y+waac5rGyotxyNoGHwNEaZLNFDTU42r7H+9rMLMgoCGcz3Xt9d5+ Rsptbxc+D0k/v38D8ks1mshGlbdrU3VE+p0GFvzDFlY4H/iMs8hr9sSAU anZS8ElYltWBIg7X8341l0P9W8Q3za1eURG7YhNjOagx2fgtbIz3boo6E g==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="292800212" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="292800212" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 16:44:04 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="968210385" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="968210385" Received: from nrobin-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.45.56]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2022 16:44:01 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 23AB810446E; Wed, 16 Nov 2022 03:43:59 +0300 (+03) From: "Kirill A. Shutemov" To: kirill@shutemov.name Cc: dave.hansen@intel.com, dave.hansen@linux.intel.com, jejb@linux.ibm.com, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, lkp@intel.com, martin.petersen@oracle.com, oe-kbuild-all@lists.linux.dev, x86@kernel.org Subject: [PATCH 2/2] x86/mm: Fix sparse warnings in untagged_ptr() Date: Wed, 16 Nov 2022 03:43:53 +0300 Message-Id: <20221116004353.15052-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221116004353.15052-1-kirill.shutemov@linux.intel.com> References: <20221115155802.p3vjnk7eqqcyskt3@box.shutemov.name> <20221116004353.15052-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749612029269717652?= X-GMAIL-MSGID: =?utf-8?q?1749612029269717652?= Linear Address Masking patchset triggered a lot of sparse warnings. The root cause is that casting pointer to '__typeof__(*(ptr)) *' will strip all sparse tags. The type has to be defined based on the pointer type, not based on what the pointer points to. Fix cast in untagged_ptr() and avoid __typeof__() usage in get/put_user(). Signed-off-by: Kirill A. Shutemov Reported-by: kernel test robot Tested-by: Andy Shevchenko --- arch/x86/include/asm/uaccess.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 1d2c79246681..bd92e1ee1c1a 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -43,7 +43,7 @@ DECLARE_STATIC_KEY_FALSE(tagged_addr_key); #define untagged_ptr(mm, ptr) ({ \ u64 __ptrval = (__force u64)(ptr); \ __ptrval = untagged_addr(mm, __ptrval); \ - (__force __typeof__(*(ptr)) *)__ptrval; \ + (__force __typeof__(ptr))__ptrval; \ }) #else #define untagged_addr(mm, addr) (addr) @@ -158,10 +158,8 @@ extern int __get_user_bad(void); */ #define get_user(x,ptr) \ ({ \ - __typeof__(*(ptr)) __user *__ptr_clean; \ - __ptr_clean = untagged_ptr(current->mm, ptr); \ might_fault(); \ - do_get_user_call(get_user,x,__ptr_clean); \ + do_get_user_call(get_user,x,untagged_ptr(current->mm, ptr)); \ }) /** @@ -263,10 +261,8 @@ extern void __put_user_nocheck_8(void); * Return: zero on success, or -EFAULT on error. */ #define put_user(x, ptr) ({ \ - __typeof__(*(ptr)) __user *__ptr_clean; \ - __ptr_clean = untagged_ptr(current->mm, ptr); \ might_fault(); \ - do_put_user_call(put_user,x,__ptr_clean); \ + do_put_user_call(put_user,x,untagged_ptr(current->mm, ptr)); \ }) /**