Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2315688pxb; Thu, 3 Feb 2022 04:09:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbn7Suux7GfnyWCQrHCEoGIKEXz3k0Hghjh2f2jS6Tk/HTsunOS2GzJTxxl+J1KfEzuXiW X-Received: by 2002:a17:907:160c:: with SMTP id hb12mr10313442ejc.46.1643890185878; Thu, 03 Feb 2022 04:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643890185; cv=none; d=google.com; s=arc-20160816; b=MCugCFOob9xxMrWe1CWNMoXxtwzeyMw6rPQ9rpzgIUqvjrxxg0ZH41LPktjd6r/Fqv 6l7KN/p2vtoPdD0FFE5BPRU8aiL3NLN6fcK0L3nroKiPIXg9jIcVxpBOTeo5NS8iH+x4 EWmo5YlNQ88AG6FlJ05oiynLKqTiwioxxTYamObAY0r61emSUNfBh/ErCdEALC+lyUc0 JDMLANWQCvE0CWQ00fLFR0OTD9ESFnL030LtfhY3shK4Byz+np9hdkfyiUFUBJKfbHsV 2bYemDUirOnHPSNM1JUoJg/2EcpVwHZS1PCZXQ+kwxmdEwar8/3ZHEIihRgyt3p+kN/o 649A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1up9Iuvtlk/iyAkaowMrPN9aJld0zeiBLUkLL04DY6A=; b=0v+PdruNaVkIkrX6TLh1UBD1OOz7GGQMc1GFqh4VyuMElRyeK7M1gPg5plONoChZBN caHKVS/78R9KmS5xtJBrEaVVpfX06vJb5zAoubC3y49h/R0iaWc4wbarL1R1fwvEaCPl JebGmQBXJzEyeDLgCe+Xhis6CFhKDncKcnE9ZONQsTn3WLxOpP18VAnuKusaazLbxlCC 8N2ahXAzegeUNNHaWTzKaS5naVw2WhcEnuAdE4EX/udxbNPBC5OcLQudPoKK3M3V+Bgq ixx9bYRXk5ECF8lO6Lkh66LxQhqmLQiiTgsp9YeKXk2OW9Aad204haTYnBgirPyYVa7A mppg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QWs0wLi0; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t25si14113788edc.95.2022.02.03.04.09.16; Thu, 03 Feb 2022 04:09:45 -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=@linaro.org header.s=google header.b=QWs0wLi0; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241528AbiBAR3u (ORCPT + 99 others); Tue, 1 Feb 2022 12:29:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241524AbiBAR3r (ORCPT ); Tue, 1 Feb 2022 12:29:47 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADD14C061714 for ; Tue, 1 Feb 2022 09:29:46 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id o1-20020a1c4d01000000b0034d95625e1fso2546487wmh.4 for ; Tue, 01 Feb 2022 09:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=1up9Iuvtlk/iyAkaowMrPN9aJld0zeiBLUkLL04DY6A=; b=QWs0wLi0831HmP/LvqHWVwVANAT7rANQll4UtSe0l1qRMJfkYwUAlKC3MvzM9LY59m jmirGQcKXR2hKtxGaZX6Az0HBlznNCAt81xhDClcfIpnqSk13VYqNycCy0XzFjBCU8y+ 9+lem5hhoqyNL3tQXojrP7IHE2wBlqnqwYaFh9k63vA91VEWklbrE2Do21974PHp3HPL r1uDWYNx165mRiOBob23AYLyRCknUOLHWb/R//K6lz4j+1aU/xNrgpfEx0Qs2nGmuKGl yqRWPDr3oPvupXdGUcXBR1+8kd3f2tUAhIzklDg7pSJuKT6T45EHtBwQEq15U83al5Tf 5pwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1up9Iuvtlk/iyAkaowMrPN9aJld0zeiBLUkLL04DY6A=; b=1glulh9K1lsUwRM0Qrfj3D1KOqOj0B9HgXXKQ7VSPR+CxW61Cs4CZNEEoqztC9xKtg t/riQV9yLcc7/QezcSl01QOddH/ieKjdlbvDMd2ItZ9xOzmBLaeUbKIi71/r2kiiT8Eo iJKjH3UdVbsy7ZW6AqT2Ug1KmOOg1CN3uVxHmKSldjGpQ9e8FkWeFFYuJh4CQ/tygLgL +VGcDFaq0x4Evfh5qlAX85Hmmgrf9NteL63Tmc8G8Xlb/EYRFq0KYXadxnbIrPVj98OD jHKCCGtww0/7WuHV7QHzmbK0ilSPCeJwdZlkgO8DwtwNk3PrTsUYkRV3oEDME/slm6Ct 5IcA== X-Gm-Message-State: AOAM53334aq25RQDVAQmuH7lkBUyz9bXpt5fmCZ3WaZmQac/NxTrgKf6 0vrDyUjSiloCLq7CEwoqy4iVsA== X-Received: by 2002:a05:600c:5c1:: with SMTP id p1mr2710329wmd.31.1643736585242; Tue, 01 Feb 2022 09:29:45 -0800 (PST) Received: from maple.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id l29sm3800651wms.1.2022.02.01.09.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 09:29:44 -0800 (PST) Date: Tue, 1 Feb 2022 17:29:42 +0000 From: Daniel Thompson To: Arnd Bergmann Cc: "Russell King (Oracle)" , Arnd Bergmann , Linux Kernel Mailing List , Linux ARM , linux-arch , Linux-MM , Alexander Viro , Linus Walleij Subject: Re: [PATCH v5 08/10] ARM: uaccess: add __{get,put}_kernel_nofault Message-ID: <20220201172942.nxop6cjr3xfa4237@maple.lan> References: <20210726141141.2839385-1-arnd@kernel.org> <20210726141141.2839385-9-arnd@kernel.org> <20220113094754.6ei6ssiqbuw7tfj7@maple.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 13, 2022 at 12:14:50PM +0100, Arnd Bergmann wrote: > On Thu, Jan 13, 2022 at 10:47 AM Daniel Thompson > wrote: > > On Wed, Jan 12, 2022 at 06:08:17PM +0000, Russell King (Oracle) wrote: > > > > > The kernel attempted to access an address that is in the userspace > > > domain (NULL pointer) and took an exception. > > > > > > I suppose we should handle a domain fault more gracefully - what are > > > the required semantics if the kernel attempts a userspace access > > > using one of the _nofault() accessors? > > > > I think the best answer might well be that, if the arch provides > > implementations of hooks such as copy_from_kernel_nofault_allowed() > > then the kernel should never attempt a userspace access using the > > _nofault() accessors. That means they can do whatever they like! > > > > In other words something like the patch below looks like a promising > > approach. > > Right, it seems this is the same as on x86. Hmnn... Looking a bit deeper into copy_from_kernel_nofault() there is an odd asymmetry between copy_to_kernel_nofault(). Basically there is copy_from_kernel_nofault_allowed() but no corresponding copy_to_kernel_nofault_allowed() which means we cannot defend memory pokes using a helper function. I checked the behaviour of copy_to_kernel_nofault() on arm, arm64, mips, powerpc, riscv, x86 kernels (which is pretty much everything where I know how to fire up qemu). All except arm gracefully handle an attempt to write to userspace (well, NULL actually) with copy_to_kernel_nofault() so I think there still a few more changes to fully fix this. Looks like we would need a slightly more assertive change, either adding a copy_to_kernel_nofault_allowed() or modifying the arm dabt handlers to avoid faults on userspace access. Any views on which is better? Daniel. > > > From f66a63b504ff582f261a506c54ceab8c0e77a98c Mon Sep 17 00:00:00 2001 > > From: Daniel Thompson > > Date: Thu, 13 Jan 2022 09:34:45 +0000 > > Subject: [PATCH] arm: mm: Implement copy_from_kernel_nofault_allowed() > > > > Currently copy_from_kernel_nofault() can actually fault (due to software > > PAN) if we attempt userspace access. In any case, the documented > > behaviour for this function is to return -ERANGE if we attempt an access > > outside of kernel space. > > > > Implementing copy_from_kernel_nofault_allowed() solves both these > > problems. > > > > Signed-off-by: Daniel Thompson > > Reviewed-by: Arnd Bergmann