From patchwork Wed Aug 14 09:09:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13763137 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 E3DDBC52D7F for ; Wed, 14 Aug 2024 09:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Bu1jHSLXuAowuIlG199J7T3IbhFclzyq7SeJSyjAvvk=; b=jOryk8E9ig30RDFd3uHpXZkZKu hTRGR9UXh03m6CN2JP3tMvfdph7Kp9V5VJxAJN1ZtZVcWXFLNyU/dM5HRy72tYVMhy4Vbhe5rE94r 8IKy97dgMXVOCxPBm86XNoKJOd4nHJM5t8boaVL9l1BGhqtXXzdxFyY1aFFytWvynl1B0heNKlZwX ibXJeGp6JN+mD9pRNnOm3AwQgBGoLgGM8iXmXnrKsMneT7Kt+6VICY3mr9Yez2TF+Vw3QPuDYiPrT FMcYwecLrCdnB6Tu6kiTInhJX0Zh2zXGIM95Cl1XnzRHAPfp4umxOJaIH/YbtGxjAJNdTgjVB1Ojl AvCJMxkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seA1n-00000006LHP-2gy6; Wed, 14 Aug 2024 09:10:47 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1seA1A-00000006LCy-41pT for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 09:10:10 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-7093705c708so6169333a34.1 for ; Wed, 14 Aug 2024 02:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723626608; x=1724231408; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Bu1jHSLXuAowuIlG199J7T3IbhFclzyq7SeJSyjAvvk=; b=i0/t7oUweNIhZJKnzoEffvFSRl8djjH43BXobOOlEfLSSwMs+HsZcEkF3nB/S1OXqV Odnel7B9uC4fItNBZgnAP9E/x2jQG+K3sD6xdkVA1bTTOF366jrkKcGCwm/5PqsXY0D7 br12e8bOoMMmujrPJd4iYz2SOMH3ncmm6UKbYJ2c+3vmzRtKEPcIz+/lB4nJ4AYqTtx7 DjmA1D2XwABVvvMjbZsHodL1jzPz4ALqdjpR5yQ7CKG+gf7jVWIT/1ip+JKYvMj7wSnP igkrOuTJ4pxU3G43RYGIOq9rkZeLG5axNQ7Fe0UXtksbTawCnS//L+k+dJNRozEmDrky yk+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723626608; x=1724231408; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Bu1jHSLXuAowuIlG199J7T3IbhFclzyq7SeJSyjAvvk=; b=ZlRUeAnRw1nulkRz/2XmIlk18/HaatdvfkFQHHZa/H0I6ffA1yBcqUAcyFHJKfGrNy tYlkQV0T0Vj1/D8uUFCi3QCjGacyw8Nd3rN38PfLxNqlatN0Zb0cBr73nY4/0RTj+sI1 561Ca0fbKn9h9MPXaZjIkr/jtqQHYOxrFxumHioCmswxf3Hp+enQvguodHtpf0ktDFUZ 1pgagCtLX1il3TLmY2EzZZ1ST8r+D/Dc3pxQXR2yLMu5s+rtZKye+p/j+uT86FaQ/++X 3tNNgUe1+lB0+Oytcwyxx3XhrZLtCimCEb8wul55fkWOKXWIBpIwgN9Y1HK83jfqSviU JIbQ== X-Gm-Message-State: AOJu0Yzq3jWLUuiC/h2MAq2XyXfEURCC5PjSHAA8bTl93nzyFPfGzsJZ 3GrGjuyUuf3KiElHQUwvQcaZLTFGHp2AoHxMSrc+fL8u56au4wyPlSKQAqX3xK9EJ51emtwhiqm wfAmfdK/cwpZHcYL5f2JC9LVXS5UChAiVzYj3IaM/0jA3UclU12LjoEDJ+UYGfBRyaC6tGQf7j3 njpr9Tb2TEcEk9DqmnEdAelTnTj+ljg54VNOlDsRxY3vy70R8+5v//BqxkTopDtKg= X-Google-Smtp-Source: AGHT+IHUP8SjxzYXdB9aH7HE/2FgWgwqAyUwnJC7ylng8Zw9pj5VO5tT/oMV6jtiNv7lHO2RA41KVA== X-Received: by 2002:a05:6830:490e:b0:709:4a6e:a567 with SMTP id 46e09a7af769-70c9d933298mr2430927a34.14.1723626607602; Wed, 14 Aug 2024 02:10:07 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-712681419d3sm1008802b3a.13.2024.08.14.02.10.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 02:10:07 -0700 (PDT) From: Samuel Holland To: linux-arm-kernel@lists.infradead.org Cc: Samuel Holland , Andrew Morton , Andrey Konovalov , Ard Biesheuvel , Catalin Marinas , Douglas Anderson , Frederic Weisbecker , James Morse , Jonathan Cameron , Mark Rutland , Puranjay Mohan , "Russell King (Oracle)" , Ryo Takakura , Shaoqin Huang , Stephen Boyd , Thomas Gleixner , Will Deacon , linux-kernel@vger.kernel.org Subject: [PATCH] arm64: Fix KASAN random tag seed initialization Date: Wed, 14 Aug 2024 02:09:53 -0700 Message-ID: <20240814091005.969756-1-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_021009_020412_EAB9E682 X-CRM114-Status: GOOD ( 14.48 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, kasan_init_sw_tags() is called before setup_per_cpu_areas(), so per_cpu(prng_state, cpu) accesses the same address regardless of the value of "cpu", and the same seed value gets copied to the percpu area for every CPU. Fix this by moving the call to smp_prepare_boot_cpu(), which is the first architecture hook after setup_per_cpu_areas(). Fixes: 3c9e3aa11094 ("kasan: add tag related helper functions") Fixes: 3f41b6093823 ("kasan: fix random seed generation for tag-based mode") Signed-off-by: Samuel Holland Reviewed-by: Andrey Konovalov --- arch/arm64/kernel/setup.c | 3 --- arch/arm64/kernel/smp.c | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index a096e2451044..b22d28ec8028 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -355,9 +355,6 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) smp_init_cpus(); smp_build_mpidr_hash(); - /* Init percpu seeds for random tags after cpus are set up. */ - kasan_init_sw_tags(); - #ifdef CONFIG_ARM64_SW_TTBR0_PAN /* * Make sure init_thread_info.ttbr0 always generates translation diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 5e18fbcee9a2..f01f0fd7b7fe 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -467,6 +467,8 @@ void __init smp_prepare_boot_cpu(void) init_gic_priority_masking(); kasan_init_hw_tags(); + /* Init percpu seeds for random tags after cpus are set up. */ + kasan_init_sw_tags(); } /*