From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89637C433EF for ; Tue, 1 Feb 2022 17:29:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0108A6B024D; Tue, 1 Feb 2022 12:29:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F02CB6B024E; Tue, 1 Feb 2022 12:29:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA3186B024F; Tue, 1 Feb 2022 12:29:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id CA5196B024D for ; Tue, 1 Feb 2022 12:29:47 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7EA558245578 for ; Tue, 1 Feb 2022 17:29:47 +0000 (UTC) X-FDA: 79094898414.24.1DE1B85 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf24.hostedemail.com (Postfix) with ESMTP id 0F262180002 for ; Tue, 1 Feb 2022 17:29:46 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id c2so13266912wml.1 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=iO/xj1U4XRNKqFxEqJxcySjtCzPpm25K5zodk0UPtvsqBpwXNO0tTWkE7TyP04wIDr 3MkUgY1mQ0/CZzE+dXtDVj0bp2XusArV+utOI4yg8+jM1Ezrp9bp6VpEbFN2CVRJ4TX7 ioA2vwsEL/LcyZqia5w5r3c54zDYZKg152PCkZ6ynmbIy7CE7vyY3FUAoSW/He4fN0eT xAzj6bzzmJB0O1JnfooLZYdSM7skcXNS9ERgYF4/9bzC1d5ujtW4p/dyJn9E44+YLWa/ Jj7Zcsq7+IERB3G/ya2ZhvH4gvSA/QQ05/K8zr7KVEVSb/DIbjvpkZWsTmi/mTdzMtvX l+lA== X-Gm-Message-State: AOAM5322tK7o1mMyED1DC0ylHLNSbAEikN8NcUBSewqlKD7KXrs0BfkX xJ86SLjhWlHuBCKOHToGqu+3sw== X-Google-Smtp-Source: ABdhPJy5hC8TD6/VJePvsLep/Uc4MjPl96ghWdUNl7PHJFXrPu8m3WGr6PFKiyFJDLT/ez1xu4zycQ== 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: X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0F262180002 X-Stat-Signature: tsm7dfah8knqm466f6wx4sjo9zhca4aq Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=QWs0wLi0; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf24.hostedemail.com: domain of daniel.thompson@linaro.org designates 209.85.128.54 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org X-HE-Tag: 1643736586-767668 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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