From patchwork Fri Aug 26 15:07:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956205 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 F31FCECAAA3 for ; Fri, 26 Aug 2022 15:09:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9477394000B; Fri, 26 Aug 2022 11:09:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CFC3940007; Fri, 26 Aug 2022 11:09:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7223594000B; Fri, 26 Aug 2022 11:09:44 -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 615F2940007 for ; Fri, 26 Aug 2022 11:09:44 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3E41140E67 for ; Fri, 26 Aug 2022 15:09:44 +0000 (UTC) X-FDA: 79842078288.30.8C8814A Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf28.hostedemail.com (Postfix) with ESMTP id DE5F3C0023 for ; Fri, 26 Aug 2022 15:09:43 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id i6-20020a05640242c600b00447c00a776aso1249872edc.20 for ; Fri, 26 Aug 2022 08:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=wnBRr6RijpcrZwDY4IvPeedZIJ4FbGOivCI4jGGTq68=; b=Q2dLT3h7TWqrdhr9cKJaZHS7iaLiqYTtydJ8WFBafxLMcKO+tWNvB/c1oHlNA44pJ7 /OXz8Sr59WCHZVNiYq5ZO1SudMDbRYsAoPTTGJZwqRehknAE2rlYQmFGjPCW+F59/jA8 4CGBdHbeqGVMdW2YUIUBHbdr0K3ckRBLlyr7LkOy1/yf2HWblMEVwWDcc4r9h7xID/vX XMqQsXajhwumZ46fKGFKaccQ9fQsrPuYa0ruT4rNz0CxhrMmw4c71iIpLPuYx4UZ7eQv mqdpWuXSHPVCrwsBJhHLWeKUt/81aDaMfsn199V9hC6WQQ+JcGqn5dar3vI5lIw7PM1Z VyHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=wnBRr6RijpcrZwDY4IvPeedZIJ4FbGOivCI4jGGTq68=; b=gyIAzMoIqqAzT0mmJyLhhZq+yfdCK91OxSGZYACIx0AmiPn4xRpFF3LY01kNIiwujY rzSdAmVQmcEL3xxg2K5RpnpqqFR7TMn6t8qMmWrYggtdWed5g5soDMUMDkmSSWR9sh62 9/OSnHt9xJAEnrVTDZmRIGcczXZyhc7gam/O7+cP9jwM6p4EPbeyKJdPDR/xwP6+ab8e aSxCmB5UmdgQYNGX2BPJ8JCPezAW/PVKq0SCaT4zBghDrdJZzWB7yMJWv4ZeLjBLHx90 Ya0QUxMQEeKntRMOl7zSLkBA5oFlyYqwxPQ8Ei3pIqdCxO3oIsPpnT2SuCn2Zgx0rM18 zfvw== X-Gm-Message-State: ACgBeo3gFTKOMnWZEr8Tv7CywplE4ZTTdG8IsVwHqb0PSGp1uk4e76fp sgJaSih2HSs/syQWUPn/iBKyRPKW8pk= X-Google-Smtp-Source: AA6agR5Cviceae2TWrL6o3zdALqTpxVHsH33a+v7kdsRPAsBV/Ys+W35Cv65k+Ev6zMJg2mViJephdzVroE= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a05:6402:268d:b0:43d:b9d0:9efc with SMTP id w13-20020a056402268d00b0043db9d09efcmr7340129edd.92.1661526582428; Fri, 26 Aug 2022 08:09:42 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:55 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-33-glider@google.com> Subject: [PATCH v5 32/44] objtool: kmsan: list KMSAN API functions as uaccess-safe From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526583; a=rsa-sha256; cv=none; b=a0MzxTd/Kt+hzaKFOps7RP9QFoeM1AydkITFWDLmggAgCuxj6W11gewiB9rfF+wJPcBzHu /1SLMrQfWYvX9hlWk7DEgGJ55wFwQgR6lnNXsB3z2CAMki6NRMvhEkDWK9c7+l9S5Uq3hz 1grA13x/3NlQSyCngUQwpMRkLgOWqCU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Q2dLT3h7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 3NuIIYwYKCD0fkhcdqfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3NuIIYwYKCD0fkhcdqfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661526583; 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=wnBRr6RijpcrZwDY4IvPeedZIJ4FbGOivCI4jGGTq68=; b=aGu/VxZJcn3zIZW5VnrDmvoFofcHhioT/HQRsFvH84kooJ90k9Wg7MKrNha1F5oh/z94MO u3hJvXqnXM7whLpiEcXyIjMS9xC11todVgSlFGj8C1w3lPANRBJZzdG598v2Zzx0Q/E7co ie4Wo8RS2X5xolU7KJbEA2SbfeVTHvk= X-Rspamd-Queue-Id: DE5F3C0023 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Q2dLT3h7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 3NuIIYwYKCD0fkhcdqfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3NuIIYwYKCD0fkhcdqfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--glider.bounces.google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: 5coznnd1rnc356kdh7zhx6i9dcmg3sb9 X-HE-Tag: 1661526583-579562 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: KMSAN inserts API function calls in a lot of places (function entries and exits, local variables, memory accesses), so they may get called from the uaccess regions as well. KMSAN API functions are used to update the metadata (shadow/origin pages) for kernel memory accesses. The metadata pages for kernel pointers are also located in the kernel memory, so touching them is not a problem. For userspace pointers, no metadata is allocated. If an API function is supposed to read or modify the metadata, it does so for kernel pointers and ignores userspace pointers. If an API function is supposed to return a pair of metadata pointers for the instrumentation to use (like all __msan_metadata_ptr_for_TYPE_SIZE() functions do), it returns the allocated metadata for kernel pointers and special dummy buffers residing in the kernel memory for userspace pointers. As a result, none of KMSAN API functions perform userspace accesses, but since they might be called from UACCESS regions they use user_access_save/restore(). Signed-off-by: Alexander Potapenko --- v3: -- updated the patch description v4: -- add kmsan_unpoison_entry_regs() Link: https://linux-review.googlesource.com/id/I242bc9816273fecad4ea3d977393784396bb3c35 --- tools/objtool/check.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 91678252a9b67..577dfdca635e8 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1060,6 +1060,26 @@ static const char *uaccess_safe_builtin[] = { "__sanitizer_cov_trace_cmp4", "__sanitizer_cov_trace_cmp8", "__sanitizer_cov_trace_switch", + /* KMSAN */ + "kmsan_copy_to_user", + "kmsan_report", + "kmsan_unpoison_entry_regs", + "kmsan_unpoison_memory", + "__msan_chain_origin", + "__msan_get_context_state", + "__msan_instrument_asm_store", + "__msan_metadata_ptr_for_load_1", + "__msan_metadata_ptr_for_load_2", + "__msan_metadata_ptr_for_load_4", + "__msan_metadata_ptr_for_load_8", + "__msan_metadata_ptr_for_load_n", + "__msan_metadata_ptr_for_store_1", + "__msan_metadata_ptr_for_store_2", + "__msan_metadata_ptr_for_store_4", + "__msan_metadata_ptr_for_store_8", + "__msan_metadata_ptr_for_store_n", + "__msan_poison_alloca", + "__msan_warning", /* UBSAN */ "ubsan_type_mismatch_common", "__ubsan_handle_type_mismatch",