Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1081979yba; Tue, 2 Apr 2019 01:45:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyz7x4gLjQe6ax6553z63ekyoUFCQM3hSH+GBma8G7PfmeJXIgbOjgdYxJk6kiS3l2LeLuj X-Received: by 2002:a17:902:b948:: with SMTP id h8mr39916958pls.39.1554194725437; Tue, 02 Apr 2019 01:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554194725; cv=none; d=google.com; s=arc-20160816; b=r4i1Xi+0JMxZdDBpYEIVmnxaGXeWQZv3I5inOgKHiLftF9Eo2+3lJb9Oc1esE7quvU O/xnqolv9WM9Ly485zQxY11t4F62fWjn2M1ZPkGq18YRCJeTNGOLHHOUGbJ/Qs08bB0Y xoB0dkN6bFDrJpPASvD1lYqzgEzjR4PEEYq3vTTOu89hmAtHv/ImcHsKPVNqWXEEeWQc qVqW/tgCgVpshtEkQbwCWuH2FPLuqUDCwIalE7LbwXseGreKS66MZ9YBxOl/eE9ZpHMN +taUyCPzxpgUNoFrfv8gbAtK3asD1+us480ok5VV1DSG5EkG4smzAOOyjeTigDs4oEbV pcag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=gjGHwngAJSVJ2KiNdZzbTLMhNPhH72tWkpY6R4Qk25c=; b=Pty6Y6wuE+PDtRKaaQ+XrNNrNEjKILGeIHYF45Hb7G8MCmm3OgfbuNhrrCea6f8BWN WKN77YEfdLYOfzoQaFBiJ+bF8jleKOZHs27X0gKkHzFSrVlGtvVvpZkde0UYOGHuHL8j VBckOtVGwTO8f5z+S6UgjjAP+r8yrN+gQ59st7Fh37BGDnzR8yiTRiSC3ZuvtWzCI2g7 VI0bw9KBuixS8OCFzHhwZpPU0rTvt3ucTtR8kHu3s6gyl4+1kV/cfAA/MKE9MD/b8QG5 +A4tk8w6FPiuFMbQSsRp2R8CSDC3Y/JKWys/fnEs94gFH6IyKDImxmod6FIRl2FcTnI2 RHwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si10510998plp.392.2019.04.02.01.45.10; Tue, 02 Apr 2019 01:45:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729617AbfDBIoE (ORCPT + 99 others); Tue, 2 Apr 2019 04:44:04 -0400 Received: from terminus.zytor.com ([198.137.202.136]:59371 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729526AbfDBIoD (ORCPT ); Tue, 2 Apr 2019 04:44:03 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x328hJKJ1310039 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 2 Apr 2019 01:43:20 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x328hHIT1310034; Tue, 2 Apr 2019 01:43:17 -0700 Date: Tue, 2 Apr 2019 01:43:17 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Ben Dooks Message-ID: Cc: mingo@kernel.org, adobriyan@gmail.com, bp@suse.de, jannh@google.com, ben.dooks@codethink.co.uk, mingo@redhat.com, hpa@zytor.com, mojha@codeaurora.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, tglx@linutronix.de, x86@kernel.org, dan.j.williams@intel.com, mpatocka@redhat.com Reply-To: bp@suse.de, adobriyan@gmail.com, mingo@kernel.org, jannh@google.com, ben.dooks@codethink.co.uk, mojha@codeaurora.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, dan.j.williams@intel.com, mpatocka@redhat.com, tglx@linutronix.de, x86@kernel.org In-Reply-To: <20190330115624.4000-1-ben.dooks@codethink.co.uk> References: <20190330115624.4000-1-ben.dooks@codethink.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/asm: Annotate copy_user_handle_tail() pointers with __user Git-Commit-ID: b5dbb6799e3e5b8ebdce33b52b2d4ec9c66e15fe X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=2.4 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_12_24,FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: b5dbb6799e3e5b8ebdce33b52b2d4ec9c66e15fe Gitweb: https://git.kernel.org/tip/b5dbb6799e3e5b8ebdce33b52b2d4ec9c66e15fe Author: Ben Dooks AuthorDate: Sat, 30 Mar 2019 11:56:24 +0000 Committer: Borislav Petkov CommitDate: Tue, 2 Apr 2019 10:38:51 +0200 x86/asm: Annotate copy_user_handle_tail() pointers with __user copy_user_handle_tail() clearly uses both @from and @to as pointers to user-space memory. Currently, it triggers sparse warning on using the calls to get and put to user-space which can be fixed easily by changing the call to take __user annotated pointers: arch/x86/lib/usercopy_64.c:68:21: warning: incorrect type in argument 1 (different address spaces) arch/x86/lib/usercopy_64.c:68:21: expected void const volatile [noderef] * arch/x86/lib/usercopy_64.c:68:21: got char * arch/x86/lib/usercopy_64.c:70:21: warning: incorrect type in argument 1 (different address spaces) arch/x86/lib/usercopy_64.c:70:21: expected void const volatile [noderef] * arch/x86/lib/usercopy_64.c:70:21: got char *to Linus further explains the reasoning why it was done this way: On Thu, Mar 28, 2019 at 12:24 AM Borislav Petkov wrote: > Well, but copy_user_generic() (which ends up calling the > copy_user_handle_tail() eventually) casts those __user pointers to > (__force void *). Converting them back to __user looks strange to me. > > Linus? Well, it does that because the x86 version of copy_user_generic() can work in either direction, so it works when either the source or destination (or both) are user pointers, but they don't _have_ to be. So the "userness" of a pointer in that context is a bit ambiguous, and so we've picked the pointers to be just plain "void *". That said, arguably we should have gone the other way and just made them both "__user" pointers, and do the cast the other way around. But there's no absolutely right answer here, and nobody should ever use copy_user_generic() directly (ie it is very much meant to be only used as a internal helper for the cases that get the pointer annotations right). [ bp: massage. ] Signed-off-by: Ben Dooks Signed-off-by: Borislav Petkov Reviewed-by: Mukesh Ojha Cc: Alexey Dobriyan Cc: Dan Williams Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jann Horn Cc: Linus Torvalds Cc: Mikulas Patocka Cc: mingo@redhat.co Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/20190330115624.4000-1-ben.dooks@codethink.co.uk --- arch/x86/include/asm/uaccess_64.h | 2 +- arch/x86/lib/usercopy_64.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h index a9d637bc301d..cbca2cb28939 100644 --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -208,7 +208,7 @@ __copy_from_user_flushcache(void *dst, const void __user *src, unsigned size) } unsigned long -copy_user_handle_tail(char *to, char *from, unsigned len); +copy_user_handle_tail(char __user *to, char __user *from, unsigned len); unsigned long mcsafe_handle_tail(char *to, char *from, unsigned len); diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index ee42bb0cbeb3..aa180424e77a 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -60,7 +60,7 @@ EXPORT_SYMBOL(clear_user); * it is not necessary to optimize tail handling. */ __visible unsigned long -copy_user_handle_tail(char *to, char *from, unsigned len) +copy_user_handle_tail(char __user *to, char __user *from, unsigned len) { for (; len; --len, to++) { char c;