Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1097634imm; Thu, 6 Sep 2018 15:31:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZqkZA36YbnQe1Sv95/Y9lSZfqVPEN6PRCBRq+94Uag0F6adQSToaybrjlhOGlkJ17HKH5F X-Received: by 2002:a17:902:b40e:: with SMTP id x14-v6mr4883417plr.314.1536273107453; Thu, 06 Sep 2018 15:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536273107; cv=none; d=google.com; s=arc-20160816; b=nPfWJUsam1yWmvyGGD7bpugtC1YwVB5QJSdBna+0eTWdwyKcVj39xdFuJ7Hs27sl7G b1MRRo4+Af64e0lzWeDV0YLM4t4VkHIhm+K5jY8aFmcYPamWrwZAs3+EhxaLUQvJ7DJR HOKV7FkaNoU5HF8D9FfowhvqyZtSRaP/8qT3UiAVUZ/KNn14FE+0KA1SeR33dUE5X8ZI ZwA16MbOuufckwIPTyaS2n7g6KwlCRtMHPe8t4c3SMpI9g69YIAHQnG2g7b9j+Sa4vgC 8fpGobe8AujbO0C+igqIBDIrgNK4OPZzxXQnM2AjgkPfNdj5bFFKQ5YItCiaCsi7V77C 1s5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EnYW6ky3ItoT2KivNLq/iXbl9f+ePTKUcOmgWI5+k2Y=; b=O7VnY53Yyt4L10aGeYSrnIZg/ppXcgzMAIEWaDHSqPO9473eVboxb+50HHP9UKTQS9 4LbYplcbiyLWoZY7UG+zwXIuMr7UoagVET7cNq1tVO6CUjNkz89lYoWj8+aBfu7jjGep S9HHJUbMVW/cVhDojRDFiXL1tcBvzWrfKzvd/49L3l/0qdbB9BFo97VbkQjozy/uweG0 lKTPS3fgR92oRSCYmyRFZcQWhxcmeYBw+hG3UDHIzgFCQeSaBxBK3C3kRBuxg6icZqYb eFlnGIoIfP/YIB15rTqTt7n+3KDqSkpuWrCeT4drxxa4aEqSSQNU0rGBTWiInnQx4/gz Mglg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZbMUWEmp; 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 x18-v6si6025019pll.88.2018.09.06.15.31.31; Thu, 06 Sep 2018 15:31:47 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZbMUWEmp; 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 S1728027AbeIGBvM (ORCPT + 99 others); Thu, 6 Sep 2018 21:51:12 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:52655 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726308AbeIGBvL (ORCPT ); Thu, 6 Sep 2018 21:51:11 -0400 Received: by mail-it0-f67.google.com with SMTP id h3-v6so17733468ita.2; Thu, 06 Sep 2018 14:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EnYW6ky3ItoT2KivNLq/iXbl9f+ePTKUcOmgWI5+k2Y=; b=ZbMUWEmprABY+YRbPRJdMPpOUhWglTIyxdTbNeRNb2iXmku8eVAULCaqOIpsTpEvNQ DvTs9HGZl/GDigvQQYHVlapZj9YhV/WsFAu+7g2GayYhl4B5FTu3U1406MLZvi0fSG2U myAbiofGAyhHA8F90mbI3KFwEiMKUmFQJQ030= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EnYW6ky3ItoT2KivNLq/iXbl9f+ePTKUcOmgWI5+k2Y=; b=H7GhsNl8VxayFPe4lFXb6cq2wZTT0wyWqvpKyd43EbhJR2x5+r3Zj3pT+ebk1z57h6 WQYYlnDyPZuNlamHjQT/vm+pLmajewQxb4+ogjSTWaNTSW/SriDSkmbO5naP9PAdXWRl qQw4iHVydw9O6ohPbtiRERv9YHFbMY0nM6Og7dzFYJ0PBwtivdMKxr8jDnxd2gYlJu59 IQTiPcc/TEzZS09NgFlAQ64pIqpio7F1us4n8am3xcK7WHgtPKxTXJwoN57xZ5XrRRbZ L5X9hpCXZuwbqGW1L4EigSBlhsJhkPY0udZZML698ThIMA4YooXZs0h6ZNJHcKfgMGQZ 1tbg== X-Gm-Message-State: APzg51D3wTNys6PV4m4Gi+EpDbjHruEpz+YO/ug7M8qnV76CjiMaasME LGGv86lrWWqrikdVvccCgq61gn2qG3aOneKzBTA= X-Received: by 2002:a24:61d2:: with SMTP id s201-v6mr4750602itc.22.1536268432238; Thu, 06 Sep 2018 14:13:52 -0700 (PDT) MIME-Version: 1.0 References: <5d54526e5ff2e5ad63d0dfdd9ab17cf359afa4f2.1535629099.git.andreyknvl@google.com> In-Reply-To: <5d54526e5ff2e5ad63d0dfdd9ab17cf359afa4f2.1535629099.git.andreyknvl@google.com> From: Linus Torvalds Date: Thu, 6 Sep 2018 14:13:41 -0700 Message-ID: Subject: Re: [PATCH v6 11/11] arm64: annotate user pointers casts detected by sparse To: Andrey Konovalov Cc: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Al Viro , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A. Shutemov" , Shuah Khan , linux-arm-kernel , "open list:DOCUMENTATION" , linux-mm , linux-arch , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List , Dmitry Vyukov , Kostya Serebryany , eugenis@google.com, Lee.Smith@arm.com, Ramana Radhakrishnan , Jacob.Bramley@arm.com, Ruben.Ayrapetyan@arm.com, cpandya@codeaurora.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 30, 2018 at 4:41 AM Andrey Konovalov wrote: > > This patch adds __force annotations for __user pointers casts detected by > sparse with the -Wcast-from-as flag enabled (added in [1]). No, several of these are wrong, and just silence a warning that shows a problem. So for example: > static inline compat_uptr_t ptr_to_compat(void __user *uptr) > { > - return (u32)(unsigned long)uptr; > + return (u32)(__force unsigned long)uptr; > } this actually looks correct. But: > --- a/arch/arm64/include/asm/uaccess.h > +++ b/arch/arm64/include/asm/uaccess.h > @@ -76,7 +76,7 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si > { > unsigned long ret, limit = current_thread_info()->addr_limit; > > - __chk_user_ptr(addr); > + __chk_user_ptr((void __force *)addr); This looks actively wrong. The whole - and only - point of "__chk_user_ptr()" is that it warns about a lack of a "__user *" type. So the above makes no sense at all. There are other similar "that makes no sense what-so-ever", like this one: > - struct compat_group_req __user *gr32 = (void *)optval; > + struct compat_group_req __user *gr32 = (__force void *)optval; no, the additionl of __force is not the right thing, the problem, is that a __user pointer is cast to a non-user 'void *' only to be assigned to another user type. The fix should have been to use (void __user *) as the cast instead, no __force needed. In general, I think the patch shows all the signs of "mindlessly just add casts", which is exactly the wrong thing to do to sparse warnings. Linus