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 9CBD0C54E5D for ; Tue, 12 Mar 2024 17:45:37 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aERh3i4J0sY6zg4G8bJcoUjuXaWf65Du012u6dBKyPY=; b=QXQeq1R8DM5iZH 5jx5MFmoQyTSt7sZux8kQp4UwtbPHEhSy47ka7dn1WnGFL8g5wNHaXuwIQQkoM1u1FP4LLNfQ8ngJ g5cljxcZDi788cDGRyq/fQn9KSWsT3UDwZ+6xu2QeuTPq8XE4gJT+Ab5kEgcbgeM6sjtsUYfEoQjH q5WZpeef1C6bSfUwUzZm4PUclTz1oNzYxt9QIJBHuEs7WL1gC9kPU6atG2EkYSQLINBz3NedkI7pc 5TrfVoQLnkAwkdUREcoStxrWqZqpJTLyg59Vue0LjAQ6T9rVDzTzyo4HCG0TI6Jr5jZ8IBk2RJvXA JAVNkRc9WsYiXvcOsIbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk6Bm-00000006und-1NTj; Tue, 12 Mar 2024 17:45:22 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rk6Bj-00000006umh-1Vki for linux-arm-kernel@lists.infradead.org; Tue, 12 Mar 2024 17:45:20 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso4843579a12.3 for ; Tue, 12 Mar 2024 10:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710265516; x=1710870316; darn=lists.infradead.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vHs3Sdkc2w+/+nwJkeNm+LX7f3/qPc/Km1pQR3e4Q0o=; b=UUMZyk9eZHPS9glij5LbnPkVzFaTOBkUqNMABB30ZdvUo5R0AKJCIhnDrsZGNwAiSf n/u+kDOaSjfuxngYK0pPzJxXBWZx7cst+JQni1hJIW21owgFrNzW2mdVvVCP4jhRwbz2 k0W+zlNnxZkdOyEvNe1ZbSUNILEJpRXHY00FTbGoqDt09yYyLfIzBhQun0roprthYvPh LF/tP6Yv3U4GugEJHxE85w+03GAhuOFkTqdGiC/6EUeSXuLueCwJ8biQ3PCQawMwXchX nmfKAk/OyY3mE47R1Yo6bw8D1E+BAAEVv6UNG2TAe7e7ONelwDa8JbyeXsLi+LOMUdsC hCHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710265516; x=1710870316; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vHs3Sdkc2w+/+nwJkeNm+LX7f3/qPc/Km1pQR3e4Q0o=; b=xPxDkMYGAAK1E3/xd7VWdGV49JJu7jvSubmBwzffm9kGes46nal+RnVzV5sgFBVsjD Z6T9/gk8nEBeFiXxit2uD9dTeLl/gj24e1d9e/ZOxX4eD9tA/FKSpH3pJb0Z5UDFAQNy NPKrkatIPRPrLOUfWWi3n2iIUjaTGFBEpxeRE+9qeOSO33JMc6KvW6JcUnHJlQLDa01j +PdhlVpahUV9Hf52kzz9N9V3MjB91QHjdPnClLkpfUj9Dn4XbcAynqRclTwOBVjASWKU pb5ntbCfH4aUV/P8geQmVSj14tNCPG+o3xBFFZcAYIQbDDCv9tHs9kg+N7ow6TRPj7wu xCZg== X-Gm-Message-State: AOJu0Yx+tJidoa8vR6LV/zfTMdRbUuVI0kbcgm3TPy9Sw+BF9t3aBgm+ RGljz3lu0JdOTTeZNw4qSzSeiTGWcmHR3qTpyOpa8jWPhc5dZcfC X-Google-Smtp-Source: AGHT+IH27Q86KbZb3uzCu/d/jQ9JiWnFndSstiKprBNbssgp/K7wPZsI3BmiQUbghpGlvxEZDmrWNQ== X-Received: by 2002:a17:90a:f2c1:b0:29b:331e:ec47 with SMTP id gt1-20020a17090af2c100b0029b331eec47mr8547549pjb.27.1710265516353; Tue, 12 Mar 2024 10:45:16 -0700 (PDT) Received: from [10.67.48.245] ([192.19.223.252]) by smtp.googlemail.com with ESMTPSA id cl3-20020a17090af68300b0029a78f22bd2sm1299312pjb.33.2024.03.12.10.45.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Mar 2024 10:45:15 -0700 (PDT) Message-ID: <1a138161-6fd0-42d4-b68c-c647fe487a5f@gmail.com> Date: Tue, 12 Mar 2024 10:45:14 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 0/4] PAN for ARM32 using LPAE Content-Language: en-US To: Linus Walleij , Russell King , Ard Biesheuvel , Arnd Bergmann , Stefan Wahren , Kees Cook , Geert Uytterhoeven Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas References: <20240312-arm32-lpae-pan-v3-0-532647afcd38@linaro.org> From: Florian Fainelli In-Reply-To: <20240312-arm32-lpae-pan-v3-0-532647afcd38@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_104519_442727_5B302B0D X-CRM114-Status: GOOD ( 24.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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Linus, On 3/12/24 05:52, 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. > > The simplest way to test a PAN crash: > - Enable CONFIG_LKDTM > - echo "ACCESS_USERSPACE" | cat >/sys/kernel/debug/provoke-crash/DIRECT > - echo "EXEC_USERSPACE" | cat >/sys/kernel/debug/provoke-crash/DIRECT > > This was also 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. > > Without LPAE PAN this will just happily print these bytes from > userspace but with LPAE PAN it will cause a predictable > crash: > > Run /init as init process > Some byte: ac > 8<--- cut here --- > Unable to handle kernel paging request at virtual address 7ec59f6b when read > [7ec59f6b] *pgd=82c3b003, *pmd=82863003, *pte=e00000882f6f5f > Internal error: Oops: 206 [#1] SMP ARM > CPU: 0 PID: 47 Comm: rc.init Not tainted 6.7.0-rc1+ #25 > Hardware name: ARM-Versatile Express > PC is at create_elf_tables+0x13c/0x608 > > Thus we can show that LPAE PAN does its job. > > Signed-off-by: Linus Walleij Tested-by: Florian Fainelli On ARCH_BRCMSTB, there was no noticeable performance drop with: stress-ng --fault 0 --perf -t 1m thanks a bunch for getting those patches out! -- Florian _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel