From patchwork Tue Oct 22 01:57:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13844982 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 6D5E7D17157 for ; Tue, 22 Oct 2024 02:05:59 +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:References:In-Reply-To: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:List-Owner; bh=9FnCjcC1/gsDOd6L8rx/6dcUkVYp18eK0+PNRkpMvb8=; b=jFYN/p7kFzOVSf2TPJI4GN/5U2 byCAz5PRL1hlvd7Gv92R28Ik7aTYei+SN+Fcz30sM7iakfn8cHP4n8oJwbox4ANav51IK4YcwunrU K+fPnmBi1lAr+ApyfjkeJt54lQ68HglAeA3aeJ5QWbTX2mmnZ0MO1GhYNinIM187BusZRUZWxiiXD FaSgadTIiCsjzb7l9vzW32PFZIozJRksMO4O2UWfTX1EzsgtN0E6IKHZ77y8VLcIYSU9MU7Bl0cza nGs/18iu6WAdjji/h93zOXgAJP4XZ9DSlsITddlg3zA5nQKmc48b25Ep79grLcQpNK9MgDGqUfMOB hPjviHmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t34HN-00000009HRW-1dZT; Tue, 22 Oct 2024 02:05:49 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t34B8-00000009Fme-2rDL for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 01:59:24 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2e59746062fso1706031a91.2 for ; Mon, 21 Oct 2024 18:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729562362; x=1730167162; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9FnCjcC1/gsDOd6L8rx/6dcUkVYp18eK0+PNRkpMvb8=; b=RjU0oPD7oXD+tWMcDuFQbnpYbwgcS/6n5ftq+xWErEa7IsRrNRv7HKxV+ZEc7ef2qO FwjvUdnbTN1W44f4PmRcHDronghY+wxKbSEpbCVRddKIkv/i5gVgstIKzLLt9g2itoCx rze5GfTMydmioM8/Z23DEqsoZxolfRQ6GsWy3y5flhHtWv9NigwvX/bj6odFJdSzsDHF SsruXeZBQND+Yn+6S9+8mcwjp1xziuEJkQyhfu/tuDdXyDZFXrI+8CHI0Wlz8KJ+bnAc k4zxALwozIFD6uRqe2nDZqylyRO/SBvrl7nxsRvHxWTUoHuz+Lq/ZQqPFCaP0kHMvX+q Bduw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562362; x=1730167162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9FnCjcC1/gsDOd6L8rx/6dcUkVYp18eK0+PNRkpMvb8=; b=WkuF26s4oBt85A2CFLUSaqb9FEtk5G5S64V8AVGjADiVnFKRY/chCp11O0seeT9nHK F5z0eyDSo+w3ZSXKbcmcVOR5nh/3Af/GzWFisVb/U61eQLtWPRdO3Yo3o8kOCCNCsDp5 R+6V8anCFVqodjjT9KhdUneqJpL9Gacyzx7bsj4hjEJI7kvnEvLuxGxaSl3RPaIffp+/ mnws6AuV/EFYItQQD9V2x5/ilPMb0wEZ9UD2z/m8IPNtOOavssuQYR8LqthajGcGtY45 W1WqeEm+S0xzwIH5K0lNmKvEeu46dH4zwdag2vkpvpmQ8aYXt326rFkmhhWZ+Eym8+ll wGQg== X-Forwarded-Encrypted: i=1; AJvYcCUxXBGNajKOzkk6DdgfidqbOLkZc1qZDoH12Rlq/bl36ghL+AKgyaj9BeVsaDQVaO0UBF2PJRkmHNChRnHj68Zy@lists.infradead.org X-Gm-Message-State: AOJu0Ywz5h220NaqG45sUlq9Xk1Czh1QRCsXW77eIXqWmD5Q/p/Lxleu xq1Jz+2ujzGpB3RTmfJDyU5lQsbhlAPdVdjH6yM6paUc9pq9aeq5ApVecoz/IEU= X-Google-Smtp-Source: AGHT+IFrGG6oMYUOck7CBYXToXMnxG+Lx4oLmbcg4j3FeL+zQkCHcoYgP+J0xW6HIU5j3POtBJfPHg== X-Received: by 2002:a05:6a20:43a4:b0:1cc:9f25:54d4 with SMTP id adf61e73a8af0-1d96df0ed05mr1060384637.38.1729562361689; Mon, 21 Oct 2024 18:59:21 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec132ffdcsm3600710b3a.46.2024.10.21.18.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 18:59:21 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com Cc: llvm@lists.linux.dev, Catalin Marinas , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Will Deacon , Evgenii Stepanov , Andrew Morton , linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [PATCH v2 3/9] kasan: sw_tags: Support outline stack tag generation Date: Mon, 21 Oct 2024 18:57:11 -0700 Message-ID: <20241022015913.3524425-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241022015913.3524425-1-samuel.holland@sifive.com> References: <20241022015913.3524425-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_185922_797722_875E5A39 X-CRM114-Status: GOOD ( 11.64 ) 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 This allows stack tagging to be disabled at runtime by tagging all stack objects with the match-all tag. This is necessary on RISC-V, where a kernel with KASAN_SW_TAGS enabled is expected to boot on hardware without pointer masking support. Signed-off-by: Samuel Holland Reviewed-by: Andrey Konovalov --- Changes in v2: - Split the generic and RISC-V parts of stack tag generation control to avoid breaking bisectability mm/kasan/kasan.h | 2 ++ mm/kasan/sw_tags.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index f438a6cdc964..72da5ddcceaa 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -636,6 +636,8 @@ void *__asan_memset(void *addr, int c, ssize_t len); void *__asan_memmove(void *dest, const void *src, ssize_t len); void *__asan_memcpy(void *dest, const void *src, ssize_t len); +u8 __hwasan_generate_tag(void); + void __hwasan_load1_noabort(void *); void __hwasan_store1_noabort(void *); void __hwasan_load2_noabort(void *); diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index 220b5d4c6876..32435d33583a 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -70,6 +70,15 @@ u8 kasan_random_tag(void) return (u8)(state % (KASAN_TAG_MAX + 1)); } +u8 __hwasan_generate_tag(void) +{ + if (!kasan_enabled()) + return KASAN_TAG_KERNEL; + + return kasan_random_tag(); +} +EXPORT_SYMBOL(__hwasan_generate_tag); + bool kasan_check_range(const void *addr, size_t size, bool write, unsigned long ret_ip) {