From patchwork Wed Aug 14 08:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13763124 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 22AFFC52D7F for ; Wed, 14 Aug 2024 09:01:39 +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=Kr1OlloTvp35mKilBnuEZzypgigPXmCly4KSd56Q7OI=; b=RLNl11Z7Vm9kXGYaU88Ft6Dkm0 wRn35SrLFzqNMPDAPnuoLexRr/6Kg3VVBHZHG0+F/B9gG/u7kywRD2R0kc4/I28bDzSv6aazC0Ntz irHRhxx5xjoZPteNVIH2CIoZoAksfupuwCUbdNg94Ef2TV+A/ATMNYSrMxRHNQxQrUHkq+gHovzvO do+xLi3FhK0OKSvBIOB/8tmz5lBTrZpe3MAtlzYwPEwHnQ2YTx0O1LpNNdsK6SMrK7zm7luhUqT/m 9nrrVWAIOc75OOHQXK47fWmN9+1Ljs07dcUILpdMoZ3KLw+fJTpIY9yMXmuV/v64hqYA0dIoJifHi 6L/LnLyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9sj-00000006Jhn-2Cxr; Wed, 14 Aug 2024 09:01:25 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9o1-00000006ICr-3Hgf for linux-arm-kernel@bombadil.infradead.org; Wed, 14 Aug 2024 08:56:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Kr1OlloTvp35mKilBnuEZzypgigPXmCly4KSd56Q7OI=; b=B1/KZEJx5Vr9fQtj4hIEeBiQz/ MUtnuVJeVMn0gvOrd2JhcLC5dZjZheuDF8eNs7bWXtb3w5xpos45heBYGrtMuubxJ4cG/SC7hZSSF rE5mGI5xEQuKJj0Z/sFZalhytdN88fxO0la7GDPHLFyYm6tIxs4vrRiV/yeG+IvKap6GVkVgty3kT zIzK1DET4MrcQJsNHAucku42wKCFPUPCVZUEqf8znceVh3WGcuNO+iMc8+UrDi1uViGOfr1E1FezW vxeN4CIACo3pEPMKGbPAaiYHOWVY2PjeiyshJ/uXsqPBAYTviLZt523+lgoOPWHtwBhNGt8bR29SI ZRpXCxVA==; Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9nw-00000007zBB-3zCN for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 08:56:32 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fec34f94abso55493755ad.2 for ; Wed, 14 Aug 2024 01:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723625786; x=1724230586; 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=Kr1OlloTvp35mKilBnuEZzypgigPXmCly4KSd56Q7OI=; b=iEddrKr4i1PnAor6PaBO4WFxY8fFLVHe1ZAXi4dMJCW55fBHSFIoCntBILB+IGoKix 5otW38RKyh9z7afkeJpvChRdCo+ZWd38V4an1oO3e6k6wJteeS8BluSdhtEEFEt+dw/i koODw7tZSe3/OdcMsR+TeXCwGmLsqmcmTnSNBU1HY9bQgMgdTM0cm3gMvWxY+dy5F8iW VAyO0aRYiNBY38GEie3eIzMRfYaFfuI7VvkjUQaAOQ+VqgHS0AsLZKWYSzvkodyvbqcm 12X5UPZLL86klSW+RLpCPhqOywd/79fd5ZJgvVWoyZRKgvAE11OBe+yPa4f/LtASEoVB Lffw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723625786; x=1724230586; 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=Kr1OlloTvp35mKilBnuEZzypgigPXmCly4KSd56Q7OI=; b=neGLFcyBhThYQyUlhVS1V8f1OppkOgZL5MLEEEpkD7i8O/VkJX2gNGt6iM2i7tcy6d mHxWhU5s4OsC75KRrSVdCJXsuXu8Z25ZLe1p4P1ow4ztV3HYn2yEInQelu6JTcB6i4s4 lWDbdFSKVEFfMQPm6KcTU9Ar5gBeF860DjBv78vH1oDvD+2mrzYV59COBZG+ODwDkJyM KyKDbAkJQE91KnnKZJmfSC1UwOxZ8skNaj25hX8QUpCuidgZ9egxhKt+HOq9WnBMZfnt EW+YVexHRFd4YZAo/7hicOl1C/LxwK7F8kLi4BWyhAsO2jlwO75NhfKCOMS/3Vcemvis 3+5Q== X-Forwarded-Encrypted: i=1; AJvYcCXJ4T1fvQ+MVBUUdE5QoAmETktsQ59H4A7iImYKj2+WFPd8I2n0KeT7sPmyRrm+SQH9iFSSceVH1NAIqzihgswqTw3P/kIZTeXYtB04McndnVVvCrA= X-Gm-Message-State: AOJu0YyY1a+seN/IycazobsoHLz5+VjonoTkFUCbryp+VK5igspzg/st IydpO+HKRRx/dXgnU+3jsvCYalo8PS9x1wbWVd28/IIfMo48n0BrR8ajEI11yIo= X-Google-Smtp-Source: AGHT+IE20LewatO25ueMR3XW0aRNE3Ho00UvK46l5CUL7vUBX+0A3K1zUsQysbjVk0qPCHhMgq/ydQ== X-Received: by 2002:a17:903:360d:b0:1ff:49a0:46b1 with SMTP id d9443c01a7336-201d6397db6mr25518915ad.6.1723625785721; Wed, 14 Aug 2024 01:56:25 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd14a7b8sm25439615ad.100.2024.08.14.01.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:56:25 -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, linux-kernel@vger.kernel.org, Alexandre Ghiti , Evgenii Stepanov , Andrew Morton , linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [RFC PATCH 3/7] kasan: sw_tags: Support tag widths less than 8 bits Date: Wed, 14 Aug 2024 01:55:31 -0700 Message-ID: <20240814085618.968833-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240814085618.968833-1-samuel.holland@sifive.com> References: <20240814085618.968833-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-20240814_095629_065287_9C49F28F X-CRM114-Status: GOOD ( 12.67 ) 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 Allow architectures to override KASAN_TAG_KERNEL in asm/kasan.h. This is needed on RISC-V, which supports 57-bit virtual addresses and 7-bit pointer tags. For consistency, move the arm64 MTE definition of KASAN_TAG_MIN to asm/kasan.h, since it is also architecture-dependent; RISC-V's equivalent extension is expected to support 7-bit hardware memory tags. Signed-off-by: Samuel Holland Reviewed-by: Andrey Konovalov --- arch/arm64/include/asm/kasan.h | 6 ++++-- arch/arm64/include/asm/uaccess.h | 1 + include/linux/kasan-tags.h | 13 ++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index e1b57c13f8a4..4ab419df8b93 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -6,8 +6,10 @@ #include #include -#include -#include + +#ifdef CONFIG_KASAN_HW_TAGS +#define KASAN_TAG_MIN 0xF0 /* minimum value for random tags */ +#endif #define arch_kasan_set_tag(addr, tag) __tag_set(addr, tag) #define arch_kasan_reset_tag(addr) __tag_reset(addr) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 28f665e0975a..56a09f412272 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/kasan-tags.h b/include/linux/kasan-tags.h index 4f85f562512c..e07c896f95d3 100644 --- a/include/linux/kasan-tags.h +++ b/include/linux/kasan-tags.h @@ -2,13 +2,16 @@ #ifndef _LINUX_KASAN_TAGS_H #define _LINUX_KASAN_TAGS_H +#include + +#ifndef KASAN_TAG_KERNEL #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ -#define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ -#define KASAN_TAG_MAX 0xFD /* maximum value for random tags */ +#endif + +#define KASAN_TAG_INVALID (KASAN_TAG_KERNEL - 1) /* inaccessible memory tag */ +#define KASAN_TAG_MAX (KASAN_TAG_KERNEL - 2) /* maximum value for random tags */ -#ifdef CONFIG_KASAN_HW_TAGS -#define KASAN_TAG_MIN 0xF0 /* minimum value for random tags */ -#else +#ifndef KASAN_TAG_MIN #define KASAN_TAG_MIN 0x00 /* minimum value for random tags */ #endif