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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6669C47DDB for ; Tue, 23 Jan 2024 21:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6h3GWuTCdif9Vu519UyApMGi0w1ingLfl5CNYOXe7aI=; b=GbAKrytdDiGUUb Yrqtrvyd5cuNdrM/fbs9CA+Ex8VSXqRmdYnGQZpWwCvLmL4ZTrsddtjGujHdCbxln7cA5UDgoFf2t AbzxutBMrEEGjVz7l7i0T09zAhsdcbp0hzq5s7sVFPQsuW+TcHmFxcjILnmEH3wlr3jPlOAm8Xszi EwtSBroDIGMv+wKIITIhYy3XjBdchtV4ua+NYNrNAP8ocW41kh8HPkxTK2BQuh8Z6ZHvsEZ2ECNB0 ZwD0I4we+r9UHVkxLILhH+pNFi0xDKmxMuAU3ZbsCqiI5jFAf3LqvvEw90BRdLqic3ITw7NFmY9Lb DE9lb7IrPtpGTuWKSWnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSOKI-000XQP-2E; Tue, 23 Jan 2024 21:28:58 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSOKG-000XOS-1P for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 21:28:57 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6dc6f47302bso1715019b3a.1 for ; Tue, 23 Jan 2024 13:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706045333; x=1706650133; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=FMHYxUPMIHhQd2FQ9+HbG4EX95PsLNqSLG0LkVZxKwk=; b=nWMz/SxLRp6XiJtWoIek49hJ+pQwLHEJOmf7gpwU3w17Yc36VnZs2j+Ypi29SgpzB+ AZE1nvO0g6H9GTEb0d166nKu1qQgv0QKh0ZxuwKq6yQPfJNkYcd9brSHPs2z1tglbcpL w/48vlYZTug04piySaDxdiPzrPSBFI5YNmWrY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706045333; x=1706650133; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FMHYxUPMIHhQd2FQ9+HbG4EX95PsLNqSLG0LkVZxKwk=; b=HudrWAbNnF4KeZ/ECPqIm/g/mlmaX/VUj4HL9SHIsAhgG9uwcjbFJ36HxJJ3j/Piop hwBkPbhcR140LN7qzzM8xvg+KvJNMAJxQdefW43fRKGjkUxGXChRAv+Zx4BnWmQCuFFN yLuGQsPja6tW9JfVd9eTlwVg5qUuJz+eCb4dTm43b/XqYNehCSuE6hFkW6HpnBG3YU30 kw94mrG0BNCwuEcGwno3IRA12jm3V558LOwPyPGY2sdSziorAYOA7aMA3eFDgHvDFQKw YR9e7dU9oCz+ypkYIGu0OnJyQUYJ0zXv3BdIj1iCLRKy/DN5XNuB9gUiNB4qaOvsbafO pbvg== X-Gm-Message-State: AOJu0YyP6dYBbHwygoGwe6P6JH+0sMuZ0ws4w5bY14guRuO3JCGgxZP1 kDWb2hi0A3+/Kyp9LhbWxu4Uyl51vmzMUEaPqQ39HTnHKFamqLd5Q67+bjxfLg== X-Google-Smtp-Source: AGHT+IGaeWb977+79hPYqyaP3Jyd3ypLKKjbFhpmNQP8W2ywAF9hmEMPiozfQQFEuUtie3I4b5CF/Q== X-Received: by 2002:a05:6a00:c87:b0:6dd:8744:3baf with SMTP id a7-20020a056a000c8700b006dd87443bafmr594761pfv.38.1706045333443; Tue, 23 Jan 2024 13:28:53 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id fh4-20020a056a00390400b006d9b4a0b6e3sm12114728pfb.80.2024.01.23.13.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 13:28:53 -0800 (PST) Date: Tue, 23 Jan 2024 13:28:52 -0800 From: Kees Cook To: Linus Walleij Cc: Russell King , Ard Biesheuvel , Arnd Bergmann , Stefan Wahren , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, Catalin Marinas Subject: Re: [PATCH 0/4] PAN for ARM32 using LPAE Message-ID: <202401231317.26C7E64D6@keescook> References: <20240123-arm32-lpae-pan-v1-0-7ea98a20514c@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240123-arm32-lpae-pan-v1-0-7ea98a20514c@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_132856_499669_F944EA31 X-CRM114-Status: GOOD ( 23.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jan 23, 2024 at 10:16:13PM +0100, Linus Walleij wrote: > This is a patch set from Catalin that ended up on the back burner. > > Since LPAE systems, i.e. ARM32 systems with a lot of physical memory, > will be with us for a while more, this is a pretty straight-forward > hardening measure that we should support. > > The last patch explains the mechanism: since PAN using CPU domains > isn't available when using the LPAE MMU tables, we use the split > between the two translation base tables instead: TTBR0 is for > userspace pages and TTBR1 is for kernelspace tables. When executing > in kernelspace: we protect userspace by simply disabling page > walks in TTBR0. > > This was tested by a simple hack in the ELF loader: > > create_elf_tables() > + unsigned char *test; > (...) > if (copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes))) > return -EFAULT; > + /* Cause a kernelspace access to userspace memory */ > + test = (char *)u_rand_bytes; > + pr_info("Some byte: %02x\n", *test); > > This tries to read a byte from userspace memory right after the > first unconditional copy_to_user(), a function that carefully > switches access permissions if we're using PAN. You can also use CONFIG_LKDTM to test, with: # echo "ACCESS_USERSPACE" | cat >/sys/kernel/debug/provoke-crash/DIRECT ... lkdtm: Performing direct entry ACCESS_USERSPACE lkdtm: attempting bad read at 76fe9000 8<--- cut here --- Unable to handle kernel paging request at virtual address 76fe9000 when read [76fe9000] *pgd=45e47003, *pmd=43fd3003, *pte=a0000048af7f5f Internal error: Oops: 206 [#1] SMP ARM ... # echo "EXEC_USERSPACE" | cat >/sys/kernel/debug/provoke-crash/DIRECT ... lkdtm: Performing direct entry EXEC_USERSPACE lkdtm: attempting ok execution at 8083707c lkdtm: attempting bad execution at 76f38000 8<--- cut here --- Unable to handle kernel paging request at virtual address 76f38000 when execute [76f38000] *pgd=49ed2003, *pmd=49e19003, *pte=a00000494a5f5f Internal error: Oops: 80000206 [#2] SMP ARM ... I can confirm it works as expected. :) Tested-by: Kees Cook Thanks! -Kees -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel