From patchwork Tue Aug 20 19:48:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13770563 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 221B4C3DA4A for ; Tue, 20 Aug 2024 19:49:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 813756B007B; Tue, 20 Aug 2024 15:49:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79CBF6B0082; Tue, 20 Aug 2024 15:49:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63CD96B0083; Tue, 20 Aug 2024 15:49:17 -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 418BC6B007B for ; Tue, 20 Aug 2024 15:49:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E057BA79D3 for ; Tue, 20 Aug 2024 19:49:16 +0000 (UTC) X-FDA: 82473662712.10.4920B99 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf08.hostedemail.com (Postfix) with ESMTP id 3523B160008 for ; Tue, 20 Aug 2024 19:49:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="qMitkXw/"; spf=pass (imf08.hostedemail.com: domain of 3OvPEZgcKCHEbbPjgTgVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--mmaurer.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3OvPEZgcKCHEbbPjgTgVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--mmaurer.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724183315; a=rsa-sha256; cv=none; b=siyITY3Z6LQ5Bsc011x+fnNSa3p6tjhPINgNGHyx/BfzXS7kDPxJZ/CANtL3ZumER8bVxh Q00zrtUrRnAPHNUZEh0CIiodewwkS9NjhaBd+oGGNvoe4DS33CLSd82YSS2OPFe/mNkMuc rft5i1Dxdo44zNLLTWFwJrG5joGllUY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="qMitkXw/"; spf=pass (imf08.hostedemail.com: domain of 3OvPEZgcKCHEbbPjgTgVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--mmaurer.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3OvPEZgcKCHEbbPjgTgVddVaT.RdbaXcjm-bbZkPRZ.dgV@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=1724183315; 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: references:dkim-signature; bh=EZ/BWqyZRlCP7UBokATY0JI3r3d12PwUba1tdxpBJwY=; b=cudwFFDgFosXrv2FEDjFars/GoDAIM9beDXaAK0Tg6tIc3ue6EIuWtA98SAYy8FUDxEga0 9YFp0a2QheCQOmTFJTvBmkC6q+IAeWr4gyUBPHtQ93vkAkAtED63OmODmMyNj/JOPhhRcM z4DzuO55vCJxo6ZC2qE+1Qjl+I/5DG4= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b41e02c255so72137327b3.3 for ; Tue, 20 Aug 2024 12:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724183354; x=1724788154; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=EZ/BWqyZRlCP7UBokATY0JI3r3d12PwUba1tdxpBJwY=; b=qMitkXw/OolR9LM6fsW24WusK2UDfuo+sA9jBLyKpU8dP2pUdqlmNVbGcw0GUlPdo4 NIiZ/yooQzQkPozcmSc1Ie7HO58yj/aTlLG1ltRq8jD7qgDCztCxWMGdd4LVnDFcEtVJ 26ZrClOreRfh/PrHEEAmMRhEuGs3rM5P3t5wtojqEtBsuPdVcYXP55yRCM7i/FRy4rT7 uAnAn4TevBIT38wSJ4iYnxr59a9ZjmuvspBuJqjGGQuLpxNHPww82a4VyFqq6kB5m2I8 7VhM/PQVdfKal7JSq4UbXeKrj0qC7LnLSjzPW6xBsCIqDgsV849Ue/szU1rw/ncZkZ9R qDqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724183354; x=1724788154; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EZ/BWqyZRlCP7UBokATY0JI3r3d12PwUba1tdxpBJwY=; b=awULg7w79iIoDm1ayEMT1qzmD4xnNKi31JAEUyR5XofXDgFcYnFNxWW1eBb/RS15E7 f3+xDPZIJBaa8+3vNoLhJSikxUH3Y9cb3+o0KhqXxmdOTbWGHLRGbYsdgM3sIHjsVnhJ 2gIqL9rPOCDOqYVMvNg46XTAPWteTAC9JHgbYKeoMKRLhEShES+LIC5JxKgGw1RXxu/H zUK+7vb1LaqligOQznXWdVk41ayFTagO96UbwpXpcYXjn8xzVJqNgF+pyXwxv3V4WTgR 2A/FT1iE4BWxEGqLooGdvq0IVPtznA+GnXem/mw9bIvuEy0HkVrk9guO/LonGAvYkLWU zWOQ== X-Forwarded-Encrypted: i=1; AJvYcCXD0+uYnxQeYJif60Jzv8UVvhKIxTc12oDOYNdxzUqFzujK0bTJT7heQRCoybZumu6Wyv6MUgzvOg==@kvack.org X-Gm-Message-State: AOJu0Yzi+qZk7GYZVTTD4umaaujEm5JNHS6QKSCasbwY5HK2ZTkUfFl/ 7sFz3s6zdjJkTC10QLn7Q+cLvQiKgVRM0GmIv8agO6r52Q3+mQ/btgtl/U+rf/Ea/IhQJ790t+3 lss2wrQ== X-Google-Smtp-Source: AGHT+IFp/nm12VvtMz6NTjd0kIpucSX0HE9Tww56O3We2qIoUG3Oc6YRA1DbTDJEzjcCHwu/hP0I6l7HF/pp X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:690c:600e:b0:6b2:6cd4:7f9a with SMTP id 00721157ae682-6c0a09f33ffmr115947b3.8.1724183354122; Tue, 20 Aug 2024 12:49:14 -0700 (PDT) Date: Tue, 20 Aug 2024 19:48:55 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240820194910.187826-1-mmaurer@google.com> Subject: [PATCH v4 0/4] Rust KASAN Support From: Matthew Maurer To: andreyknvl@gmail.com, ojeda@kernel.org, Alex Gaynor , Wedson Almeida Filho , Nathan Chancellor Cc: dvyukov@google.com, aliceryhl@google.com, 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 , Nick Desaulniers , Bill Wendling , Justin Stitt , rust-for-linux@vger.kernel.org, llvm@lists.linux.dev X-Stat-Signature: 3cm6wadq56mna573t9gkz8cjw35ukh4o X-Rspamd-Queue-Id: 3523B160008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724183355-357348 X-HE-Meta: U2FsdGVkX1/VzmYtVPuxMrVWT2hkPzJMcTs9fgkebDBllciei/OQt13QlNVCbd0XewaNeWgbID4CfkDJl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5njTtAxIMqM9PV4HQfStzRvSjqs8IKRXtnA7T35lRY5cJjN3UldrfCwDZibwxIeZOUMR5shFKpQPmbY25wazHzGP7yC4DA6AxlSZVgfrtG6vLkvtJElILkgQWWDkc264xkE92iljcTXvJ26Ylt6ia08b48WbcDW64TpI0GCJHaR5c0cNlBazpG0WqiKf/Ln7UJa1DOM3DoWpwPlNbZJN8xjnhgScqubCkX9UwAt0ArvtuW2BOuflYvjr6zzIfbuD8r8GD+JbOxiYNOwxtFOvPudHCYPsJJ9IEGA1/jC7BUkkaH4BDB9MrxDZYARaflN3YJTgVJ78z6CIWRiaBndAb9+BZ7/yW8cqFXcW3cDp2E+kb1SEO0tdCoZpBNoELowokOR6MUIHcgUvS8PiRDsZqHTTFche65rtYniva8iL3+eHhhIpREqbqyCju2wdymRlKGxbZRrZvWJg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Right now, if we turn on KASAN, Rust code will cause violations because it's not enabled properly. This series: 1. Adds flag probe macros for Rust - now that we're setting a minimum rustc version instead of an exact one, these could be useful in general. We need them in this patch because we don't set a restriction on which LLVM rustc is using, which is what KASAN actually cares about. 2. Makes `rustc` enable the relevant KASAN sanitizer flags when C does. 3. Adds a smoke test to the `kasan_test` KUnit suite to check basic integration. This patch series requires the target.json array support patch [1] as the x86_64 target.json file currently produced does not mark itself as KASAN capable, and is rebased on top of the KASAN Makefile rewrite [2]. Differences from v3 [3]: * Probing macro comments made more accurate * Probing macros now set --out-dir to avoid potential read-only fs issues * Reordered KHWASAN explicit disablement patch to come before KASAN enablement * Comment/ordering cleanup in KASAN makefile * Ensured KASAN tests work with and without CONFIG_RUST enabled [1] https://lore.kernel.org/lkml/20240730-target-json-arrays-v1-1-2b376fd0ecf4@google.com/ [2] https://lore.kernel.org/all/20240813224027.84503-1-andrey.konovalov@linux.dev [3] https://lore.kernel.org/all/20240819213534.4080408-1-mmaurer@google.com/ Matthew Maurer (4): kbuild: rust: Define probing macros for rustc rust: kasan: Rust does not support KHWASAN kbuild: rust: Enable KASAN support kasan: rust: Add KASAN smoke test via UAF init/Kconfig | 1 + mm/kasan/Makefile | 7 ++- mm/kasan/kasan.h | 6 +++ mm/kasan/{kasan_test.c => kasan_test_c.c} | 12 +++++ mm/kasan/kasan_test_rust.rs | 19 ++++++++ scripts/Kconfig.include | 8 ++++ scripts/Makefile.compiler | 15 ++++++ scripts/Makefile.kasan | 57 ++++++++++++++++------- scripts/Makefile.lib | 3 ++ scripts/generate_rust_target.rs | 1 + 10 files changed, 112 insertions(+), 17 deletions(-) rename mm/kasan/{kasan_test.c => kasan_test_c.c} (99%) create mode 100644 mm/kasan/kasan_test_rust.rs Reviewed-by: Andrey Konovalov