Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2433208ybb; Sat, 30 Mar 2019 05:04:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHoZXaSRhbjBW20y05sNNWA4G3EfzJRybIOBlUqHgr3+kuzKer+qjdBR/TNgOWeLVjdxpj X-Received: by 2002:a63:6bc6:: with SMTP id g189mr51567343pgc.427.1553947450782; Sat, 30 Mar 2019 05:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553947450; cv=none; d=google.com; s=arc-20160816; b=JVdDQTyozcjMSzDa/LZCD5KUnSGHUKEG/jaMVZh+V6lfMlbd53wOymUwlxh2Zpcsev bZ3vMNU5W+TnntMRNIosnNS1wYAogkUYMhoyYVeKbrVYxSUP1SPfZA3a3qs/CRRsk8Bi NrHdiZzby5m9L9umeR0SNdOVsgqVGpkoZyb6STBYBPeNKFRNAxH1am1HGCj3osCUyXX/ R5izq2wMrzyci1Uq8w2ovRritBzXIkbAjnSTU3iT5HmMuzLMdr51MGD6VZWjgOj07GS6 AeAkY1OibWlYd80qtqgRafbKEt1BuUmXn6IFPpYplkRb8v9ImH6LfsSU9aUu4lC5OMLf qLyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=27jSfTQ4W3FmrKbZkTaW0ltLt560v6Y4yTfnuYXHYkI=; b=BZdc0bbryfUwX8epQjAOGtMADCrFa+5fYuk8MwspwU+fO4QjpHfRfXQG3tE2BNegwa Qr/y+d5xZNMA5LHzWc82SidTkWCQtmtQRsavNZXKUnWxfkrjZ9S8gj3pMflQZ2qNMPEq pMYFgmirAKQTb8Pvfgx3mkjN7HbTiHunMBKUc3bxo+EAHl1L3ptaiC92J93PXZSvbGyQ /YAUC6Lzh3wbaZpqtHzEFoYWI6dvhfokofAcg3oHnbcL01fMukOLmCAMgKy/D7RwgsRu vJYpuk59ARFRYGJz62Ol41CR4HAhtNquf4UapazAsfc8BeC06kWN91oCWkcjosg+E3qf 57mw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si4196047pgq.421.2019.03.30.05.03.17; Sat, 30 Mar 2019 05:04:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730558AbfC3L4g (ORCPT + 99 others); Sat, 30 Mar 2019 07:56:36 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:48487 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730428AbfC3L4f (ORCPT ); Sat, 30 Mar 2019 07:56:35 -0400 Received: from [167.98.27.226] (helo=rainbowdash.codethink.co.uk) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1hACbA-0004lI-KE; Sat, 30 Mar 2019 11:56:32 +0000 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hACbA-00013M-9l; Sat, 30 Mar 2019 11:56:32 +0000 From: Ben Dooks To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, mingo@redhat.co, bp@alien8.de, hpa@zytor.com, torvalds@linux-foundation.org, tglx@linutronix.de, Ben Dooks Subject: [PATCH] [V2] x86/asm: add __user on copy_user_handle_tail() pointers Date: Sat, 30 Mar 2019 11:56:24 +0000 Message-Id: <20190330115624.4000-1-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The copy_user_handle_tail() clearly uses both from and to as pointers to user-space memory. This triggers sparse warning on using the calls to get and put to user-space. This can be fixed easily by changing the call to take __user annotated pointer.s 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 From Linus Torvalds: 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). Signed-off-by: Ben Dooks --- 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; -- 2.20.1