From patchwork Mon Aug 19 21:35:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13769027 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5E87C3DA4A for ; Mon, 19 Aug 2024 21:43:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430626B007B; Mon, 19 Aug 2024 17:43:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B9816B0082; Mon, 19 Aug 2024 17:43:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 259F76B0083; Mon, 19 Aug 2024 17:43:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 050D66B007B for ; Mon, 19 Aug 2024 17:43:22 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A9FF8A161F for ; Mon, 19 Aug 2024 21:43:22 +0000 (UTC) X-FDA: 82470321444.12.1C99A34 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id D602640012 for ; Mon, 19 Aug 2024 21:43:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="2ucw/sCN"; spf=pass (imf04.hostedemail.com: domain of 3r7rDZgcKCHAaaOifSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--mmaurer.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3r7rDZgcKCHAaaOifSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724103785; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dYHfB1jRSques99oHkY91uNPL3BC6i2xvsHR0qX5+O4=; b=XX3LMB5MS8H301LMdOdyZaeE1d2eCp2E7eC+Er3jOC5LO3yCL5p2TkHh1REfR50uRUpOvF SRVn7EAhYuXvDMCqhfFiQ7cgRkTYPQx2IZBSFuxNQjaBnKfUHtf/pPhrsYK+4vwH/jCjF/ M31Xn2WkFPxJpc6u7H2Fq3xlx5xrQlM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="2ucw/sCN"; spf=pass (imf04.hostedemail.com: domain of 3r7rDZgcKCHAaaOifSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--mmaurer.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3r7rDZgcKCHAaaOifSfUccUZS.QcaZWbil-aaYjOQY.cfU@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724103785; a=rsa-sha256; cv=none; b=RmQ66YLGohgWfEEx2b6elAJRcNeB4xhMm/LWJ/rzJkSrmVt4P1giPRJOkhujfd0SrVqgwa n9xXKf3nqPKGSt3wwU96+/lYXqCAFRcZDs3jW9eQ2j8KWMhSZxtoxvKbkmrzfRLVzu8oZl qe2M9d1i5UZt5iMyK9LSOjaNg1k4aJI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b41e02c293so56682107b3.0 for ; Mon, 19 Aug 2024 14:43:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724103800; x=1724708600; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dYHfB1jRSques99oHkY91uNPL3BC6i2xvsHR0qX5+O4=; b=2ucw/sCNsy2KE2SMNdllqPnLlTb2K1ngXyWCCvqYw8kE8+gY4grOcOAlM4e2erjGyo 0fyxh2tO77eSdJv4MKlLJrzwzEfSCfvY/RQKdQwwslw8VLpcXTVIG1s+wQu8XddxRVVQ JCFo//fOb7S7GahN6PBe0jWmY60PK8pwUwswFKt1ouwLacgYuiruM/dWNLV9lx8BXine PTZRmAocndrNUKbddWczvfLv/AovCVPX/ZjP4VgKAb25eIbVjKoJdVMzMcDJrJrXuhGR 4jiUwqDfHiepdauVI1hU2x3Jf5ANh5qFq7/jdeMxQIYGxajrncsoDXQH2Go/yULtAcBF 9MDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724103800; x=1724708600; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dYHfB1jRSques99oHkY91uNPL3BC6i2xvsHR0qX5+O4=; b=g1OUwosz2uF7+rCYAu5MJeEXjiklW4YoNpeeD5UPmQkdHxr2FmPBgd74iZB8eHGXcf tZ0W8vbZuchKnRIw9MpI13i0DZJP6Kk83h0PK3E7fBy+x3+4LRRKdmTsUljg32JAJ6Q7 f5flPF8pIJzieTERd96ZbsMl2rdwIn/b4CCHW3AFofa9FbEqbADVcr+w7vsXWchLkBVh OehatLPbfQu4Qr3jxxWEIrp5sJG84X72TLsSQcfe1OWB6nxv63tryE1IsIxJvlxTTvcp 9lSulO+QmL503Y3nPlFxErpvGken0nvvGACNqKyOknnk3e41oXcF3Fi1VG3MuNUTdjXL ln/g== X-Forwarded-Encrypted: i=1; AJvYcCXhfGEkIyxVhByTzeIep5Va2m5lRsC0xloOBf30sLJkyx3BxQHc7ok53FufCzd88790WvfC8w3uBi7rV+4DwKbnkLg= X-Gm-Message-State: AOJu0Yxi+qoX5SY0ZGUlFsefoHXrnXyqcOz4KTPFeP57K3CvrrEBh54Y UdKg4Wn7nZIocycxEhlViG6G3ly+k4S194SfCs742AGrWJ140FLpxbXarsy4gLki5wmT0lZfMoE dq0kcYQ== X-Google-Smtp-Source: AGHT+IFwshO87RfhTzH1yMuE+dB46zbPZ1Eu9OzIlegM79V4EtZO9MXEpG14lmgTuz2TbiBW6ciN753E2AAE X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:690c:2912:b0:62f:f535:f41 with SMTP id 00721157ae682-6b1bc5e4037mr4097737b3.9.1724103343636; Mon, 19 Aug 2024 14:35:43 -0700 (PDT) Date: Mon, 19 Aug 2024 21:35:19 +0000 In-Reply-To: <20240819213534.4080408-1-mmaurer@google.com> Mime-Version: 1.0 References: <20240819213534.4080408-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240819213534.4080408-2-mmaurer@google.com> Subject: [PATCH v3 1/4] kbuild: rust: Define probing macros for rustc From: Matthew Maurer To: dvyukov@google.com, ojeda@kernel.org, andreyknvl@gmail.com, Masahiro Yamada , Alex Gaynor , Wedson Almeida Filho , Nathan Chancellor Cc: aliceryhl@google.com, samitolvanen@google.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, glider@google.com, ryabinin.a.a@gmail.com, Matthew Maurer , Nicolas Schier , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev X-Rspam-User: X-Stat-Signature: 6q4jd5b8u33pxrzabhhn3g7gjmtdshuc X-Rspamd-Queue-Id: D602640012 X-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kKUoiWoQmOtZOGCUOdnjeXcI4T5sR9Nup+NmfrRw3+2/kShuVZvU382tqM0ZKvkYnOFu6+H6kYgCRgdBdMqRgQpX/AEffLy0mtr+sUKvy+8Zk0vuvY+2HJ/fe58C13m38U4CUiiwU5MSu9+6fXlOedF3blWt5tXQM+lBPUNdlsILA96Kb2Dw7zb00P5NtTwMvnIpoQdyglOuTyH5MhPo9yRBvuD5qljIfNO67rGLlziabUNW7Nc8c/lIYVwzEVDp7oQeKDRlxI8KaMfY0M1u7EJGEIX4/cvYtHE0odWqNhCLBJcAMX0LyDbPyqVVp9rIIhpjylAAYeu9bQnXLNoPn86ZAMFr5ZoOQQpUEVunKSBh6cAONcEGh8VLFi55OcT4h+qykJn6coY/OYdPkLleu+3o+e6J1zg9DaAjHA/1M3h1iRFMMipHdigaPplTaWdEYk8ZwqWhUEKEnrXj+aVFchHIsx7oRIOr3fETv4sgEP+t+sBnQItvJCCpllNmyTaXRnMMPGvzl4/YpqCuY6WuQPYXVgHMN2Cx8zaFDqcXbC1iHL2Xx X-Bogosity: Ham, tests=bogofilter, spamicity=0.000347, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Creates flag probe macro variants for `rustc`. These are helpful because: 1. `rustc` support will soon be a minimum rather than a pinned version. 2. We already support multiple LLVMs linked into `rustc`, and these are needed to probe what LLVM parameters `rustc` will accept. Signed-off-by: Matthew Maurer --- scripts/Kconfig.include | 8 ++++++++ scripts/Makefile.compiler | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index 3ee8ecfb8c04..ffafe269fe9e 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -63,3 +63,11 @@ ld-version := $(shell,set -- $(ld-info) && echo $2) cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) m32-flag := $(cc-option-bit,-m32) m64-flag := $(cc-option-bit,-m64) + +# $(rustc-option,) +# Return y if the Rust compiler supports , n otherwise +# Calls to this should be guarded so that they are not evaluated if +# CONFIG_HAVE_RUST is not set. +# If you are testing for unstable features, consider `rustc-min-version` +# instead, as features may have different completeness while available. +rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null -o .tmp_$$/tmp.rlib) diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler index 92be0c9a13ee..485d66768a32 100644 --- a/scripts/Makefile.compiler +++ b/scripts/Makefile.compiler @@ -72,3 +72,18 @@ clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1) # ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) + +# __rustc-option +# Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage) +__rustc-option = $(call try-run,\ + $(1) $(2) $(3) --crate-type=rlib /dev/null -o "$$TMP",$(3),$(4)) + +# rustc-option +# Usage: rustflags-y += $(call rustc-option,-Cinstrument-coverage,-Zinstrument-coverage) +rustc-option = $(call __rustc-option, $(RUSTC),\ + $(KBUILD_RUSTFLAGS),$(1),$(2)) + +# rustc-option-yn +# Usage: flag := $(call rustc-option-yn,-Cinstrument-coverage) +rustc-option-yn = $(call try-run,\ + $(RUSTC) $(KBUILD_RUSTFLAGS) $(1) --crate-type=rlib /dev/null -o "$$TMP",y,n) From patchwork Mon Aug 19 21:35:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13769022 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ADE9C52D7C for ; Mon, 19 Aug 2024 21:35:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 934F76B0088; Mon, 19 Aug 2024 17:35:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E5086B0089; Mon, 19 Aug 2024 17:35:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75FC56B008A; Mon, 19 Aug 2024 17:35:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5709B6B0088 for ; Mon, 19 Aug 2024 17:35:49 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C8AB641513 for ; Mon, 19 Aug 2024 21:35:48 +0000 (UTC) X-FDA: 82470302376.03.93B5041 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf05.hostedemail.com (Postfix) with ESMTP id EA5F310000D for ; Mon, 19 Aug 2024 21:35:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tYjfzAW3; spf=pass (imf05.hostedemail.com: domain of 3sbrDZgcKCHIccQkhUhWeeWbU.SecbYdkn-ccalQSa.ehW@flex--mmaurer.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3sbrDZgcKCHIccQkhUhWeeWbU.SecbYdkn-ccalQSa.ehW@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724103268; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aFJ5TYFEs+yR5IdjkZAHXbLg1gl48k9ppZEG1vmVjrs=; b=xLD4S71tmJCJW5VLl9Fr6EULYyJNVqHg0IIkD2ILvs1AZmx1crghM+11Y/+KVhP0S7sXoi 1wFYLlVGalQm6hRjwAeO9RTurgJtlsAfqBCf9BEGMkAG3wnO/H3c2Q33DqKFuO2xQuAD6m cM1mnPVJfCD26/vno1iNRSZMEZlFDaA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724103268; a=rsa-sha256; cv=none; b=nVItnb/1MCraACcO6KazpicxQZmf8BClNMVzXjS+HbafmwjCyb+9oBA9N/mQHHMBPshIMh 10AZ+yrc7yuAPsPVtjTKXVWadbqq7HgP5cRDQhXXavSOAC7wy6SYz5oRE8OhLlHgs/XP1D Av8ylOauhMf8arEVcx2LtJRHyLu/J28= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tYjfzAW3; spf=pass (imf05.hostedemail.com: domain of 3sbrDZgcKCHIccQkhUhWeeWbU.SecbYdkn-ccalQSa.ehW@flex--mmaurer.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3sbrDZgcKCHIccQkhUhWeeWbU.SecbYdkn-ccalQSa.ehW@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1159fb161fso6897805276.1 for ; Mon, 19 Aug 2024 14:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724103346; x=1724708146; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aFJ5TYFEs+yR5IdjkZAHXbLg1gl48k9ppZEG1vmVjrs=; b=tYjfzAW39xORD4XsKDiz5V9v4FgCBKVlxQlvY7brR01lmVTtL47dnNDosVmnyeSfRK fNr0Fk9j8bTYYvZuvrkj7ewsI+fm0CvcTUcHYyy5vp+pDT2SzwyjOvJGfIovk25wvq55 JGbEAqcnTOyFUkUQti4wU/19/p7qysFKqM8fKz9DGJ2Iiq6IqvnCLCLafQiZYhV0qo1c UBILc3eXOjAmQ42HFG++B3CgBk0y1UHUiB8tiKyhg4knMiLHQvfQmxI1r0+YqBT9p+yP 5q2JVYE74oJxS6WpmMYc9oAFv01Dpcg/aiUOFLaEr4hDe5PDKNIxJ4TnNxsTeZlujEHg BLKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724103346; x=1724708146; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aFJ5TYFEs+yR5IdjkZAHXbLg1gl48k9ppZEG1vmVjrs=; b=w17i2MH50bghyNgcMkJPkFxT/mU5p60jlQeqMPfzVCmmtGRzcEJMuJuqyBnYPagsv1 zZ3bBvbWXA2TOw1cYEf0LON0XP2S7Wb1bl6dWLJLOEjo0MHPXe829ECCIl8Sn/CJ8nbT 51BTTSKXK5OghpK9z4Mj/aEmkDrRdYDoBknkdAFvBdU0gNZrLBfWAWvQKppiLIDMMa95 h42Rdn5TFoliDusadRJ5UqreAOy5bSVW58cX+JDt9FMroiiy6N9j+JwjzmWRA+ZzitBn IVyzuHPy4QoTuWw0moRBahHI2ywIRC76eGYS+hEDzb6EpiBYvAniSwDHLdHOxr/ItU5y OpnQ== X-Forwarded-Encrypted: i=1; AJvYcCWv1b7GzecCTZUh6ZPG5x/GdHAHKQbCs6pq/8KMRzLxCi7Q3cqCYS9OfNNwgDPryC6ZYuEsO5f0ig==@kvack.org X-Gm-Message-State: AOJu0YxLnE4AuXcFOrZLeM9ICckcbcu1O45comDKv1qHF8eMNFkyYpL2 MALIKTNkHw31SCAxgFNJi5bnJXmLOhIHhfpCQv6W+3P95gz+Q91qkZrkn2Sn+eeATh2Imq/tDzj o0KScCA== X-Google-Smtp-Source: AGHT+IG2tKNbtNYlkOTrRuz31J4vbeiBAaW0c0yUYXPPm8A2joe/19hudxJlIbHojlpceaLwmhCZjbn/6/KR X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a5b:4cb:0:b0:e11:7a38:8883 with SMTP id 3f1490d57ef6-e1180f71f9dmr21204276.7.1724103345780; Mon, 19 Aug 2024 14:35:45 -0700 (PDT) Date: Mon, 19 Aug 2024 21:35:20 +0000 In-Reply-To: <20240819213534.4080408-1-mmaurer@google.com> Mime-Version: 1.0 References: <20240819213534.4080408-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240819213534.4080408-3-mmaurer@google.com> Subject: [PATCH v3 2/4] kbuild: rust: Enable KASAN support From: Matthew Maurer To: dvyukov@google.com, ojeda@kernel.org, andreyknvl@gmail.com, Andrey Ryabinin , Masahiro Yamada , Alex Gaynor , Wedson Almeida Filho , Nathan Chancellor Cc: aliceryhl@google.com, samitolvanen@google.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, glider@google.com, Matthew Maurer , Nicolas Schier , Vincenzo Frascino , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev X-Stat-Signature: pxbyhjmf79uso7wzcbkxxw33jxxp3w68 X-Rspamd-Queue-Id: EA5F310000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724103346-531639 X-HE-Meta: U2FsdGVkX19iUdZ4ieQRUHLk872AZbHo9u0o6EbpWTzP7jbZlrqaJswu3oc6drDigqmRaQOyfnmmPqnNGuxfQyG5eCRgYdt2teup3In1xUPOZak/eFkq3Ho+hl5BH2K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kQocgpicEKOlv+iFK4YH9ffHc5we4u9PM0DRqPCAPuSqmYLqFZiVXi0IJt/ho6YzyRtlLVPX0Wjjw05bOMLmDXRSD84N68wrx8RQ+5Q9tgFiXdTf6OhR0DLrrqNAK8dN+6BkJggZB/z99xhqDW0vUCEamJRkSJb8CGg8oGE/DR4LSg+1tQ/OopLikIdNwrqSAYUValDMNil8THqwkMvaTHidf9OtPFtgKidNKwSrYYI42qwYfdJNU4I9HBGAtbbsQg/xzKuxyBB0/4H86nBIduCWx/MFa+yjC8UdLdEQL9zNpb6morBf6tTwZYRlxqdnd80Xmweka1OH3LHLT8IYI5y7J6ny/Yg0GCptAvHhsCKA3rBT8Dj0fEAixbdEtFJqrzyaVr53mkXlsgtsnzzz++FY2aR9lnIgEm+7Oj1vQcjOEI7s6P2pHGLjUGrQeocMOdcBw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.003277, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Rust supports KASAN via LLVM, but prior to this patch, the flags aren't set properly. Rust hasn't yet enabled software-tagged KWHASAN (only regular HWASAN), so explicitly prevent Rust from being selected when it is enabled. Suggested-by: Miguel Ojeda Signed-off-by: Matthew Maurer --- scripts/Makefile.kasan | 54 +++++++++++++++++++++++---------- scripts/Makefile.lib | 3 ++ scripts/generate_rust_target.rs | 1 + 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index aab4154af00a..163640fdefa0 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -12,6 +12,11 @@ endif KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) +rustc-param = $(call rustc-option, -Cllvm-args=-$(1),) + +check-args = $(foreach arg,$(2),$(call $(1),$(arg))) + +kasan_params := ifdef CONFIG_KASAN_STACK stack_enable := 1 @@ -41,39 +46,56 @@ CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \ $(call cc-option, -fsanitize=kernel-address \ -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) -# Now, add other parameters enabled similarly in both GCC and Clang. -# As some of them are not supported by older compilers, use cc-param. -CFLAGS_KASAN += $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ - $(call cc-param,asan-stack=$(stack_enable)) \ - $(call cc-param,asan-instrument-allocas=1) \ - $(call cc-param,asan-globals=1) +# The minimum supported `rustc` version has a minimum supported LLVM +# version late enough that we can assume support for -asan-mapping-offset +RUSTFLAGS_KASAN := -Zsanitizer=kernel-address \ + -Zsanitizer-recover=kernel-address \ + -Cllvm-args=-asan-mapping-offset=$(KASAN_SHADOW_OFFSET) + +# Now, add other parameters enabled similarly in GCC, Clang, and rustc. +# As some of them are not supported by older compilers, these will be filtered +# through `cc-param` or `rust-param` as applicable. +kasan_params += asan-instrumentation-with-call-threshold=$(call_threshold) \ + asan-stack=$(stack_enable) \ + asan-instrument-allocas=1 \ + asan-globals=1 # Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*() # instead. With compilers that don't support this option, compiler-inserted # memintrinsics won't be checked by KASAN on GENERIC_ENTRY architectures. -CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1) +kasan_params += asan-kernel-mem-intrinsic-prefix=1 endif # CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_SW_TAGS ifdef CONFIG_KASAN_INLINE - instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)) + kasan_params += hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET) else - instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1) + kasan_params += hwasan-instrument-with-calls=1 endif -CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ - $(call cc-param,hwasan-instrument-stack=$(stack_enable)) \ - $(call cc-param,hwasan-use-short-granules=0) \ - $(call cc-param,hwasan-inline-all-checks=0) \ - $(instrumentation_flags) +kasan_params += hwasan-instrument-stack=$(stack_enable) \ + hwasan-use-short-granules=0 \ + hwasan-inline-all-checks=0 + +CFLAGS_KASAN := -fsanitize=kernel-hwaddress +RUSTFLAGS_KASAN := -Zsanitizer=kernel-hwaddress \ + -Zsanitizer-recover=kernel-hwaddress # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) - CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) + kasan_params += hwasan-kernel-mem-intrinsic-prefix=1 endif endif # CONFIG_KASAN_SW_TAGS -export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE +# Add all as-supported KASAN LLVM parameters requested by the configuration +CFLAGS_KASAN += $(call check-args, cc-param, $(kasan_params)) + +ifdef CONFIG_RUST + # Avoid calling `rustc-param` unless Rust is enabled. + RUSTFLAGS_KASAN += $(call check-args, rustc-param, $(kasan_params)) +endif # CONFIG_RUST + +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE RUSTFLAGS_KASAN diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 9f06f6aaf7fc..4a58636705e0 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -167,6 +167,9 @@ ifneq ($(CONFIG_KASAN_HW_TAGS),y) _c_flags += $(if $(patsubst n%,, \ $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) +_rust_flags += $(if $(patsubst n%,, \ + $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \ + $(RUSTFLAGS_KASAN)) endif endif diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index ced405d35c5d..c24c2abd67db 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -192,6 +192,7 @@ fn main() { } ts.push("features", features); ts.push("llvm-target", "x86_64-linux-gnu"); + ts.push("supported-sanitizers", ["kernel-address"]); ts.push("target-pointer-width", "64"); } else if cfg.has("LOONGARCH") { panic!("loongarch uses the builtin rustc loongarch64-unknown-none-softfloat target"); From patchwork Mon Aug 19 21:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13769023 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81CAEC3DA4A for ; Mon, 19 Aug 2024 21:35:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11EF06B0089; Mon, 19 Aug 2024 17:35:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F64F6B008A; Mon, 19 Aug 2024 17:35:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFFD36B008C; Mon, 19 Aug 2024 17:35:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CEE3F6B0089 for ; Mon, 19 Aug 2024 17:35:54 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8A9A51C51E4 for ; Mon, 19 Aug 2024 21:35:54 +0000 (UTC) X-FDA: 82470302628.05.BAF0060 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf28.hostedemail.com (Postfix) with ESMTP id B862FC0017 for ; Mon, 19 Aug 2024 21:35:52 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rtC3cSHA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 3t7rDZgcKCHgiiWqnanckkcha.Ykihejqt-iigrWYg.knc@flex--mmaurer.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3t7rDZgcKCHgiiWqnanckkcha.Ykihejqt-iigrWYg.knc@flex--mmaurer.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724103265; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nhd4bVGt7t2cMFreV83ln0lve5lvedn9wm7Lt/YZotw=; b=BJgH72pHfYqKXVwp32F0Ck9I/cU12bhmzKqHkakXolTdDHmIrLYEBtq0t7xx7Z/dR2PnPp xTfhy/K71WG2xXZv4UHjTb0UEYEwh7xfnRuroM1a3wsytXHX4VuMacKE52MDi6w+6DLT0j 7HNkLQHmRcjWx/aruZp7jLMfb3OsYpQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724103265; a=rsa-sha256; cv=none; b=anISe8x+qVR7pMyU1r7I09MBeLb017KDsVjr6gjpjIpgtSGvCMzBofs7SbjvKLp4HKnZlz itPxbQwyQN3oQF+Sh4Ya/ri4g1GuJDnYzQDzCvT/6G5Q4jf/gK4aj/i6IiwBTz1+uVPKmz dd47H7/u7sxFR+pUsiQZQXIL3uuqXIM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rtC3cSHA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 3t7rDZgcKCHgiiWqnanckkcha.Ykihejqt-iigrWYg.knc@flex--mmaurer.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3t7rDZgcKCHgiiWqnanckkcha.Ykihejqt-iigrWYg.knc@flex--mmaurer.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ad9ffa0d77so87608567b3.2 for ; Mon, 19 Aug 2024 14:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724103352; x=1724708152; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nhd4bVGt7t2cMFreV83ln0lve5lvedn9wm7Lt/YZotw=; b=rtC3cSHA66m9SemJnQ+CtLiHSNzqEeeoKGyKavrC4d/3LDxsXuFrL7cRjAUXE+KihH iT6dLKod4YzL1yluGu68LutoR0gQlmdVb6sRDHgLfrHxW2Ef9i1BROVetDrg9soW5eM1 dmsQ/A4nGuqZbwuHuC9RvxQ5hUiGoDHe0SRTz0f+cf7wXdR/9snuLsy2VbFDwPMdLmRn bkHcOjM71UpdNg7EjJkno4YVuYeOU9sJJNniGKfzNANYE6y/iz43Zy8VubSEQOlPdrm6 D92pfw/4fg1W9zGVNpHdYLaO3qHmPeRqzvZ56MSwBTqi7aYV430CWqxvY8hyRBsPo7J4 MY+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724103352; x=1724708152; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nhd4bVGt7t2cMFreV83ln0lve5lvedn9wm7Lt/YZotw=; b=RDJXq39B63SnI4PpR3J5gkae4KWIO0JoHobqJk7ZX265iEndZgTJf109MinSATOYRh GQuyJfxrUrD5w46jgMZHwwvmILG+a0OO4a3qdEDwWkxvsSq+oyi+L10L8coCN+zh3aYc cIu10NhIIu64HoeIU0nyxnkqiu9ub3YDqHdSKfofSrg4lR3U5tJc3NT2f/kfvfMOzrQ5 SyxyjdrozONaAbtfLg0q2s4MIvPSRaw/wRjXV70RN2jrHMSLHEqfAvsmE7/1oyMbK3Sq 2JqHZKBiZWwR1Y6/dUQF6/SrXMkgWsasqbQN/qBGqkhOFWA7rpw58pDmjuCqtDi1frUU XWJg== X-Forwarded-Encrypted: i=1; AJvYcCXMMwvH+q+FZo01Fy0S1V9AD+Y8jfUSEYzgzUu0Vl6lvCZ+b5FU3I15T3FOvihXN7van9Jh2m7ywxuKq662N1Gs5DM= X-Gm-Message-State: AOJu0YyjPeUXCSjAPBzgYO7AnD10mCIl9QGj/xi4jYdU3Ier8vBD0nea 5PZn2ws07Z+XNu+R2fVTCxIA53Q4jyuHaLisLoju74uqrsKXTJN1W/gMUdiiqsQfbVqqwvgGLQE sh+PCVQ== X-Google-Smtp-Source: AGHT+IGrdGkpFhjR6FPlXdtXR3sEdRIorE/hVIxLA4gK2OzmA6/Q93EsKJfCVwpE5jbhlit9Iqplyhs7pn+a X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a25:6892:0:b0:e0b:a2a7:df77 with SMTP id 3f1490d57ef6-e1180e64015mr158092276.2.1724103351771; Mon, 19 Aug 2024 14:35:51 -0700 (PDT) Date: Mon, 19 Aug 2024 21:35:21 +0000 In-Reply-To: <20240819213534.4080408-1-mmaurer@google.com> Mime-Version: 1.0 References: <20240819213534.4080408-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240819213534.4080408-4-mmaurer@google.com> Subject: [PATCH v3 3/4] rust: kasan: Rust does not support KHWASAN From: Matthew Maurer To: dvyukov@google.com, ojeda@kernel.org, andreyknvl@gmail.com, Alex Gaynor , Wedson Almeida Filho , Petr Mladek , Masahiro Yamada , Andrew Morton , Yoann Congal , Kees Cook , Randy Dunlap , Alice Ryhl , "Gustavo A. R. Silva" , Vincent Guittot Cc: samitolvanen@google.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, glider@google.com, ryabinin.a.a@gmail.com, Matthew Maurer , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Mathieu Desnoyers , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B862FC0017 X-Stat-Signature: uz8s4t14mznpeeuru1ss4ub9azsoux5h X-Rspam-User: X-HE-Tag: 1724103352-569422 X-HE-Meta: U2FsdGVkX18AS1nVQjfLcBk8TxL1XPwbtJcLrosUYJ1owWn5Q56yH8zH1pNgLU+92tZcV1Ajgdk25P1LNkYzRVeKw8u6Kvhj7TvVyn1LY44XqejxQPVnfVaGKh1IpQpxU6h75k1DcBgLdmZ13mTPML7i6tlH6cgSO73d53HZyWMvGB36G5OmDsOK4qucnnkQk+k1oMup7qEc0jfw4tiU5DvSvV5aCLmmdZ9rGhcTmxiEx5Q3PZYzNwmK5FtR3e1FAywlVngT1l16OyqPvTE2/KL+XXVZzFklu20j/x1E+FhoHHTvdW2NLKG6BtyJLjtrM/DHautnVSafq43j4AOWYW0QG7SQVswQlVMRxJUg60Yha0pSx1GlCPQJxwSZMQMwdFkHQ8dKgpEL6Iy2DnaJIrXrG7v/leVQ+aOOzNxOBsHFYog74BnUoaiK4rydjG9WlFvzHShIC+nyO1EPKLkyOJv2dwkJcVEXQ2az1wAqiodaNE9+tLA2Sgpz86n2dvONj2E4nxjay+RNTK+95C40PYnNs9tnLPcMSRYIXTVCcD9JCcs0e60BLZU6IyS0pavUfedvtaICUH8qpCpuhW3eu8Bf4vjmRhG9Zt1XZEtUD9giZD45LVkLqrvzm5G3obtgI3GhslvW18/LtQ/CHHBQJgvD3yJdF2ycgK0y8kDGnRUz1lbShB+x29qs4NcPDNBLshQxOxjz0wDaMr3P9eOwmDLQxFmkO7FcCsOd8iAlMYbOMvSdfk6E87wIf9UN+/+S9TxnFkM8SM/qlZOfGEN0MKPA9wcNpbqMmeV5V64JeV83CGtgZQZDqvPmeZUphmWqVnP9VCKx29aHEUC+CZBQ+d7zDjyLRSIW2fzM1oq/F6gqtWx28LrsO0qkGHTEP30awq3B2dMOumaTugG38AWrecsqtA3er6IMVQZembWMSe1tNDRVZL0BF0jLdhq4ba62rLc1d8UK5mr3kqi4t3E qkrFL5Pw XwTXphLbJ2mOamqiNqcYeMA/VUwJfPKL4drj4qiC9LHydxlgbFzSzW4Jsg/HcXF1SviHm7YpqWdRzgF0KwHZhs6K1ecjmdSU8n3MLfHJfXuyZGmtwJDiu2XBhCZFA2EydZJpuiNLezN/g7yy3wRrsHdxUpI8E0IrXaCxduWtFghfuTgc8RNWqsDkMRRmL7EhAeHnooouqs4nMkDeLRfpMdiGowJ6IBy1i7l9KJEOCSad2QoAYtMv6DEyhi3q6xtbgCPEFKXrqfB1Uayer4BAlut1525ooS3IhNa+gAIK/1xPN9gVuk+2J2mvtXMkvLHCri/4WkqrM1VKy4dDrbnl/2jHQNbeiDIDpUM1a4825jtXdcwobq54RQOYSdrm5jinWfG2WkW5LGRGrc0i02jmrvaoiiD24fJa6TsUj+vM43voIIQfCIdVM5do//unmt4NAcYQqqHFQfjCHlYFmAyfh4txypLiBo5yPGToUq/jdRL1MyXhNuzhIOI9J7Uwm3CeXKWksd2K1O0oelVVWMMTWMH8oZDN0aMa+9IRwpcPYspGHWIchjIQ9kAwm34yym8sqagY+TouEhKHZ4+TqP3wWHqfQrQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001158, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Rust does not yet have support for software tags. Prevent RUST from being selected if KASAN_SW_TAGS is enabled. Signed-off-by: Matthew Maurer Reviewed-by: Andrey Konovalov --- init/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/init/Kconfig b/init/Kconfig index 72404c1f2157..a8c3a289895e 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1907,6 +1907,7 @@ config RUST depends on !GCC_PLUGINS depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE + depends on !KASAN_SW_TAGS help Enables Rust support in the kernel. From patchwork Mon Aug 19 21:35:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13769024 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 298C6C3DA4A for ; Mon, 19 Aug 2024 21:36:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B311A6B008C; Mon, 19 Aug 2024 17:36:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE1116B0092; Mon, 19 Aug 2024 17:36:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CFE06B0093; Mon, 19 Aug 2024 17:36:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7C1876B008C for ; Mon, 19 Aug 2024 17:36:01 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 017E41215A9 for ; Mon, 19 Aug 2024 21:36:00 +0000 (UTC) X-FDA: 82470302922.30.E1D370E Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id 35957180007 for ; Mon, 19 Aug 2024 21:35:59 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ZE3ituyN; spf=pass (imf16.hostedemail.com: domain of 3vrrDZgcKCH8ppdxuhujrrjoh.frpolqx0-ppnydfn.ruj@flex--mmaurer.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3vrrDZgcKCH8ppdxuhujrrjoh.frpolqx0-ppnydfn.ruj@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724103343; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DLZP/QF5cmnVPLPNbpw6BEPvqDqvHQJMieoIEn+0YgI=; b=uBdiauA7YNTAkeLzjrk6jGu3IaD4NIBaRU1HBzsYat4XG9Op4IlFgPYpg4Un2bRFKN+0Sl d5siIXh9+qthZnq6q1fF4eH0L9EAqap8B56TQ+OiBO/vQE7c0pycGem41afwKc/Zr5WgIk udsdql8hbAMKI3x5e5PyGsZyYHnz3Zo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ZE3ituyN; spf=pass (imf16.hostedemail.com: domain of 3vrrDZgcKCH8ppdxuhujrrjoh.frpolqx0-ppnydfn.ruj@flex--mmaurer.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3vrrDZgcKCH8ppdxuhujrrjoh.frpolqx0-ppnydfn.ruj@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724103343; a=rsa-sha256; cv=none; b=pqWmhVKgYkhWRKcQtl/en8zTyMtqIiK5rBcD683L8s4Xf0rr/8eQ8me26bdaJ4/Lu1YlAc LqreqSc1mYQwouY86GEjlOShxqNFNN/a0chKx5xDJ1M57coYUyUBRZgcH/CRTEm13Eqdch Mg4lgs7ZwbHGxoSx5NOSeLhdCbPdDsM= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b052c5939cso43872417b3.1 for ; Mon, 19 Aug 2024 14:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724103358; x=1724708158; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DLZP/QF5cmnVPLPNbpw6BEPvqDqvHQJMieoIEn+0YgI=; b=ZE3ituyNAPXC1Dkbz06+PTFzZaNRPSdJhDpoEtt10iFVmpHEdTaGdYXqYRLRfJXxR4 yy1qiNm+aWSNANt88sf9TsevS1YJBKuhOmYUq9vbsbVqYQepMAIrRcw+KQYDp3DPKXKf nFMeQwYwhKLJpg5VmIGCzbj6kM5ZU+EZlR8+HibGEfIMGzX/QbfP5CkwYktIRuquqxEJ 4AKZ2hJK27zQvX/XuaCt/DblJSZnZFSh+/7ZbCV7NLeGbyEqtZ6wV/Z8b0i4JQ4m30y1 AB0Rs3nXG4VzoWOs8ZCrFhYlDinpn7vZYWBijPFUNZskqU3Wdl410Yv6yjWFOsTpVtZj oIkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724103358; x=1724708158; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DLZP/QF5cmnVPLPNbpw6BEPvqDqvHQJMieoIEn+0YgI=; b=RAW/DYNNne/KPBnE8IzR3oTKH+/+uL3EnEQB+1LgBqd1N44HVh8n1TC0I/xARPJRTr z4Yt0vTfO/15jbCbWngkYarmrVa1RqcfID9Ypt76oHF9xBwH+LZkxS2xMSpI3y1MrWKa 0EE2BiXUjiaF5qvrqQnWeQjBKSlNiheVNuJonXBuzwwG40YmZE8seiDkg2slFJr0NDgS G7C+vtp3pfvuOkvEUseQQoj8k63Fx20fXA5qbb72vvsh0pVNV1dBRGM6RpL6YLQDyxHd DamLZ1XnxTNwTceobyvVWxdX3WVsCg7hWEjGcGDmZs+jeDPCKriFfFtGqIlDRjt8p7Sz iJKQ== X-Forwarded-Encrypted: i=1; AJvYcCW3xIOXN1b8KF9PHwdCISXz+9PYQYo1PhwEKQndD9dqzSANRX4XojwSM47t+ArSxkJo6uvCXh/uIg==@kvack.org X-Gm-Message-State: AOJu0Ywi6yk2uXbUiQzcmxSIcPd2Dy4LMgMLm05UTBWg2Da6AgYRR0cn XHIK+/uwY8nkEZHWy9umMK8XdvymEdvUnEtTEQaN+S8Dnp1SfRppxbqFsvEmTUokLQNIM6uEogv 39R7BVg== X-Google-Smtp-Source: AGHT+IFZS2xXJL0usEpl7aC1i9T/njX/Lp67FzLHxgLhINWz6El3o0+qNCa3oemMpCX7xuFSKtHBgm4HGnGG X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:690c:4d82:b0:644:c4d6:add0 with SMTP id 00721157ae682-6bdcdcb9effmr348377b3.1.1724103358288; Mon, 19 Aug 2024 14:35:58 -0700 (PDT) Date: Mon, 19 Aug 2024 21:35:22 +0000 In-Reply-To: <20240819213534.4080408-1-mmaurer@google.com> Mime-Version: 1.0 References: <20240819213534.4080408-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240819213534.4080408-5-mmaurer@google.com> Subject: [PATCH v3 4/4] kasan: rust: Add KASAN smoke test via UAF From: Matthew Maurer To: dvyukov@google.com, ojeda@kernel.org, andreyknvl@gmail.com, Andrey Ryabinin , Andrew Morton , Alex Gaynor , Wedson Almeida Filho Cc: aliceryhl@google.com, samitolvanen@google.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, glider@google.com, Matthew Maurer , Vincenzo Frascino , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Rspam-User: X-Stat-Signature: 643g7w63m38d3stjrzasshs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+c3znNzFvGOCP/pcG7cT7hZ9V8NwDiIlWeZtigGY60J0tDoxx4AeUCxK3QV40EDV6liSFJ+twaq6pE5bWJiVHtEfdqXlEWXVPNek3P19ZprRPeQvB43R99jHHxGX5DAv8/AErYZiG8NjjujZl4FC0I6JlC1+B07zPUqifaR12gdTlLB/DSta2oIs0RDbfWHGkQ09si3QhplyjAspgisQ+ADTPCK8JxFyHz/IqDDuFSCl45BLpvrt4wWZNgC3ReSyXMQojBPWzugSuVwAITeWoSp55aryTQIgy6fzJ+g4H0S4uh+hov2rSuWsy9SmiNrHtDFHF2sfdWau2O2hoNFH053Jv7O+HXtMiI+WFKwwZKaemkmE9uQVD8WXBvY8TaDAtvCI7QfnLmU8nsA22GylLDw8TIQSHJEtWDU2V6zyHi4kMpm6bboKakR44I6bEr44tx3g+8RCyjYW0ZrCKVEW1OtHBxPTmNqiThtGJwm5KcEs/cp974vIozBSaN5iHifXt03syiS+HDR+9eZnGBUTXQ0aB8TuLjt3rIgEcWLsmA8SKgxi6IgeWYxFkZP2ptCEa0iqQo6oGqYLv9vjViG7nvlEULBF1aQWIANgFg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Adds a smoke test to ensure that KASAN in Rust is actually detecting a Rust-native UAF. There is significant room to expand this test suite, but this will at least ensure that flags are having the intended effect. Signed-off-by: Matthew Maurer --- mm/kasan/Makefile | 9 ++++++++- mm/kasan/kasan.h | 1 + mm/kasan/{kasan_test.c => kasan_test_c.c} | 11 +++++++++++ mm/kasan/kasan_test_rust.rs | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) rename mm/kasan/{kasan_test.c => kasan_test_c.c} (99%) create mode 100644 mm/kasan/kasan_test_rust.rs diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 7634dd2a6128..d718b0f72009 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -44,7 +44,8 @@ ifndef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX CFLAGS_KASAN_TEST += -fno-builtin endif -CFLAGS_kasan_test.o := $(CFLAGS_KASAN_TEST) +CFLAGS_kasan_test_c.o := $(CFLAGS_KASAN_TEST) +RUSTFLAGS_kasan_test_rust.o := $(RUSTFLAGS_KASAN) CFLAGS_kasan_test_module.o := $(CFLAGS_KASAN_TEST) obj-y := common.o report.o @@ -54,3 +55,9 @@ obj-$(CONFIG_KASAN_SW_TAGS) += init.o report_sw_tags.o shadow.o sw_tags.o tags.o obj-$(CONFIG_KASAN_KUNIT_TEST) += kasan_test.o obj-$(CONFIG_KASAN_MODULE_TEST) += kasan_test_module.o + +kasan_test-objs := kasan_test_c.o + +ifdef CONFIG_RUST +kasan_test-objs += kasan_test_rust.o +endif diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index fb2b9ac0659a..e5205746cc85 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -566,6 +566,7 @@ static inline void kasan_kunit_test_suite_end(void) { } bool kasan_save_enable_multi_shot(void); void kasan_restore_multi_shot(bool enabled); +char kasan_test_rust_uaf(void); #endif diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test_c.c similarity index 99% rename from mm/kasan/kasan_test.c rename to mm/kasan/kasan_test_c.c index 7b32be2a3cf0..3a81e85a083f 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test_c.c @@ -1899,6 +1899,16 @@ static void match_all_mem_tag(struct kunit *test) kfree(ptr); } +/* + * Check that Rust performing a use-after-free using `unsafe` is detected. + * This is a smoke test to make sure that Rust is being sanitized properly. + */ +static void rust_uaf(struct kunit *test) +{ + KUNIT_EXPECT_KASAN_FAIL(test, kasan_test_rust_uaf()); +} + + static struct kunit_case kasan_kunit_test_cases[] = { KUNIT_CASE(kmalloc_oob_right), KUNIT_CASE(kmalloc_oob_left), @@ -1971,6 +1981,7 @@ static struct kunit_case kasan_kunit_test_cases[] = { KUNIT_CASE(match_all_not_assigned), KUNIT_CASE(match_all_ptr_tag), KUNIT_CASE(match_all_mem_tag), + KUNIT_CASE(rust_uaf), {} }; diff --git a/mm/kasan/kasan_test_rust.rs b/mm/kasan/kasan_test_rust.rs new file mode 100644 index 000000000000..7239303b232c --- /dev/null +++ b/mm/kasan/kasan_test_rust.rs @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Helper crate for KASAN testing +//! Provides behavior to check the sanitization of Rust code. +use kernel::prelude::*; +use core::ptr::addr_of_mut; + +/// Trivial UAF - allocate a big vector, grab a pointer partway through, +/// drop the vector, and touch it. +#[no_mangle] +pub extern "C" fn kasan_test_rust_uaf() -> u8 { + let mut v: Vec = Vec::new(); + for _ in 0..4096 { + v.push(0x42, GFP_KERNEL).unwrap(); + } + let ptr: *mut u8 = addr_of_mut!(v[2048]); + drop(v); + unsafe { *ptr } +}