Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp482968rdb; Tue, 23 Jan 2024 05:52:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkyqqYtnhhMoT81N+BHDTEOzT3LjD8GWl6cbSBv2tf5rwC7YukyAp8kccNhSZMDAMNAK7r X-Received: by 2002:a05:6a00:190e:b0:6da:dc87:cb2a with SMTP id y14-20020a056a00190e00b006dadc87cb2amr3578714pfi.45.1706017937116; Tue, 23 Jan 2024 05:52:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706017937; cv=pass; d=google.com; s=arc-20160816; b=GuP0/k3UOEdqMSP0lzTH4N21cuKtL1IDfFXSvyczFRNrz8QTUBl6wZxwJ9jugOUikC Ytl6kKlFmPsMo33IRG4Z9f8WpmLtC7h7fk2Zo8HryO0rvVdLUd7M8bEVGxAdTF36pUis Lerpr8ELUCI8Ev6jxJrddbWr3SNLTRalGVRqfolR6ZgomxMd1zvk/jBoX1P0eYkPfCSC k2L7YzCXzc1NZbTT1UFKGBbDs0Vz2MbgLLqL74m5xFfr1xhcEtEUSI0kwf4JV33XDMnf BBeOXuXWmwasvmINJCpJ0yXim42TGMFnhn+49TL5o3tQQs93tqbuaCheJp6Zadn2E5yo Po9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=ABVoHtgmT4ydZuLWaE8pZvZdFwGofmYr2cVjEucBYak=; fh=lIrCsVaLH7AxPlAzqIwiuW+2z4fg79468gklvuF1TFg=; b=PL9CsC/cwaOKRI8bc+xjIJROYMn3Y08jdnQtwaTCRx3uxOUXpvS0hoG7nQ6PiZYEXF rIfdzEXw+Ut23Qlv5+p/HbawggB5YxO1xEYmTyDJ4z+4JCyMmQWz5zbbXr/CTHG9i9TV WPcoZ7beQDr6pDVRspsVbaQAL7gbO2tyeRF/EyzEadpM2HqgbJHQ4roUZQ7GMl02pxCK 77cVmThjj0s9nQxRBzeTycDqfza6kDFLmMgWv6hhVk44T/bZClkt05tmnuPq9vGwkfYY l2XrU4wPH1ZiemfokVMjw70FAUrbvvY501vtxFSaDm24Gtp1e2YDRWzBPpOBSaO1Esv7 Opug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QHnCLute; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id fc36-20020a056a002e2400b006dbb2351aa5si8584503pfb.89.2024.01.23.05.52.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 05:52:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QHnCLute; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-35399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C88462895C0 for ; Tue, 23 Jan 2024 13:44:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 376AF5F556; Tue, 23 Jan 2024 13:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QHnCLute" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E1E35F544; Tue, 23 Jan 2024 13:44:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706017492; cv=none; b=hU/7r4SyjcnXlVMniQTHRWmv1U+vUgqvVoWAAuxDHJTF7PXCD+xy0eR6dJIirhaUq9Gnwl+2a0f3kHapBewJcWS7mFbMUceMguqG8Xrs9Vf8nGRqybJ9MF2DxxqKd/Z9yEhDtXHaYmwpWu3bxquJce3lA5LX4iVW7iOvg0sMJ18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706017492; c=relaxed/simple; bh=Qn5tSbzj2r3ltCpstoKo0Sn6ZzFWrGV7o6xX7Xc7q8M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jIWFXhWnd0kNFhpRi/E9bqJS/FXasYsnazEffetqv5gaACwqrNscp74hx35rzGpcoP3MsGEvqox8Hv4GgZp1SLbNC7GYcYbaLCKU1EVI4zKKE93/dIdPnDrEXD0+Any+xELiqXaZDrAEyjhV97VqyoKb/LbbK/g3dMmRKd4of6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QHnCLute; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D484AC43394; Tue, 23 Jan 2024 13:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706017491; bh=Qn5tSbzj2r3ltCpstoKo0Sn6ZzFWrGV7o6xX7Xc7q8M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QHnCLute2mIzLgVlrsjqwDjLrEQjkGbq6JSyg2KMTCI5xZ3wjAeGuCqcZqmUnFDRp bTo/y7AgHBdxBMiEivS2Z2UE+gIz2inia5Ax9b2NfTNXxO5+9R/1pKssLjo5484rNd zNv/F10/BdCAUsnBzzGiSmmLsQDnbGum5QFf28iZJ8ZwTPHFMXN29zKBdngf6aBCyg 7MzmjYZovglLnuYMAd91Od+qFn5uZjaed3Q7LNEFZttAA6W5+FjZizZf6wOONG06vq 7dOEPfb0kWp5nOwkn+ajzHNNzGhykgTUK40KtZbih1PeAyBPAlfFq5SZPw9CxMbYAm tRuFIEjM5uegQ== Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-50e6ee8e911so5791342e87.1; Tue, 23 Jan 2024 05:44:50 -0800 (PST) X-Gm-Message-State: AOJu0Yxilp8nK8RmaH+hvKc8FZ4XeIDBEMORrHKMriYTeICxMowtHxUz 3QfYyYHnFdJ4YJ4g9OHEY7Cr5NRiU2+zunmKb0CX1YorGThPBUKbaOEbw2NVWkP4cwixQLPoaNy wvJB2wOhPHm9t+EhwUSrCkqbf3H0= X-Received: by 2002:a05:6512:130c:b0:50e:4ebe:ca46 with SMTP id x12-20020a056512130c00b0050e4ebeca46mr2801944lfu.78.1706017489085; Tue, 23 Jan 2024 05:44:49 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240123011238.work.301-kees@kernel.org> In-Reply-To: <20240123011238.work.301-kees@kernel.org> From: Ard Biesheuvel Date: Tue, 23 Jan 2024 14:44:37 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ARM: fault: Implement copy_from_kernel_nofault_allowed() To: Kees Cook Cc: Russell King , Mark Brown , Wang Kefeng , Andrew Morton , Ben Hutchings , linux-arm-kernel@lists.infradead.org, "Russell King (Oracle)" , Hugh Dickins , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Tue, 23 Jan 2024 at 02:12, Kees Cook wrote: > > Under PAN emulation when dumping backtraces from things like the > LKDTM EXEC_USERSPACE test[1], a double fault (which would hang a CPU) > would happen because of dump_instr() attempting to read a userspace > address. Make sure copy_from_kernel_nofault() does not attempt this > any more. > > Reported-by: Mark Brown > Link: https://lore.kernel.org/all/202401181125.D48DCB4C@keescook/ [1] > Suggested-by: "Russell King (Oracle)" > Cc: Russell King > Cc: Ard Biesheuvel > Cc: Wang Kefeng > Cc: Andrew Morton > Cc: Ben Hutchings > Cc: linux-arm-kernel@lists.infradead.org > Signed-off-by: Kees Cook Reviewed-by: Ard Biesheuvel > --- > arch/arm/mm/fault.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c > index e804432e905e..bc5b959b6f90 100644 > --- a/arch/arm/mm/fault.c > +++ b/arch/arm/mm/fault.c > @@ -25,6 +25,13 @@ > > #include "fault.h" > > +bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size) > +{ > + unsigned long addr = (unsigned long)unsafe_src; > + > + return addr >= TASK_SIZE && ULONG_MAX - addr >= size; > +} > + > #ifdef CONFIG_MMU > > /* > -- > 2.34.1 >