Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4410334ioa; Wed, 27 Apr 2022 03:18:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6Q3wAfRbO/tSXrWPoaZLl2Uq4hY35CH9DzW3gNhtrfRM31/8QvxMBtKWGIWxktLFyVP9W X-Received: by 2002:a17:90b:2311:b0:1d9:2e43:c7ae with SMTP id mt17-20020a17090b231100b001d92e43c7aemr24463499pjb.47.1651054690562; Wed, 27 Apr 2022 03:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651054690; cv=none; d=google.com; s=arc-20160816; b=WWGm6aBR4+Y2sSg1+8uiXL0kYiCb0ZKtVPnaiQ3qV58xbNLcqXDxaoEoeVmcQkCwDt XPUVRg7VIS6MOwzu+cv6UIbAn3njLomRWEiBLIMd3wV1qwWa6QcqJ4wTeo5ivSa2Fmsv SNzrJhTH0IvJOsry7HSvr/vyYVM62CWW0Bln4MHkbMDcUg4LB0UgZ8fiJuPpmwGd8uB3 Jk6Vlc1TPjvhlip5a7WqMk8m2ycEVs1bgfH1nqysrmdaKPng1y8xmUJVwnf7yH/t411b TFJZ9nUOk+dJ75uA6B23cnlNl9nPR6CrmQHcrSny8zvmWrzMEvTFPg5DYk6tIpHLq/kX CNcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=UzBVkSVOyNRYl4KHuto6hQklAwc82x2pMcEIZC5XiS8=; b=mSUqmnoOc2Bd7wMJFCvmcjFX90whl4t4uD84bDTlL8IbzRhjcdHi0xBUaSc/O0rIRv VHo9d5YSGckfoY57xU42wDPf3PYJIxu8s3zbleqb5jJZvwh1YLj09nZW/P2PRZRp9HlI ra5xpImSU3Nc3N1/YM0DpRZWpoN6YKFfslQWTIic0WgZoswRBy1TefarKwizISWAxLP6 6jNbeKftC0wMueH8kndwwsmIc2L93ymOTQ2VwwyPFD/5arM+gDuBfmbq8xw/8btDtUO+ A4X9Hk35JqpEQSyq1sr5n7LgCjP0i69bjsH0tRcWJOwFIGX2uWAwRZm+EuOYljEKE0/P G+NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=owv8rcv7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id kb3-20020a17090ae7c300b001bd14e0308fsi1616384pjb.103.2022.04.27.03.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:18:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=owv8rcv7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 348AE34B2F1; Wed, 27 Apr 2022 02:38:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353400AbiDZQwA (ORCPT + 99 others); Tue, 26 Apr 2022 12:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353352AbiDZQu7 (ORCPT ); Tue, 26 Apr 2022 12:50:59 -0400 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2110048331 for ; Tue, 26 Apr 2022 09:45:55 -0700 (PDT) Received: by mail-ej1-x649.google.com with SMTP id sa27-20020a1709076d1b00b006e8b357a2e7so9327244ejc.14 for ; Tue, 26 Apr 2022 09:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UzBVkSVOyNRYl4KHuto6hQklAwc82x2pMcEIZC5XiS8=; b=owv8rcv7uy/IjMK2oDHnzdeRikUPc32v+DR6vPabqmMBgOdq0UhvmmpjftMy8ytPNt HM3P5/DQ+pT5uKlWjCFQLCWuI9NAXILUzfH3+gwTr92gjb0OskwwBjPetTXSTIPD/6OL 3KUV5a7F0Rw16/K17cTVV6HnNmzJ94eEPwwrT81RmiU5XvUiR8m/dPbUUMv64bYcnrfS 8JLEMyNSW8k05BHKUBKubnloTQr7UOc9bvvDZfi1MjSOdb0FNIpfyPVgIpYfdedOBZYB K6n0Di2ypZYYijr3xtes9AkKQrrbDkPvtqX7ow2f4ddywq7YCN1BIaM7a/np99bjjIjy k1tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UzBVkSVOyNRYl4KHuto6hQklAwc82x2pMcEIZC5XiS8=; b=UI9xdGGYqsUHW/N+TBTrdbzEHGnF6f/FBglyFP3+tQegLU9uzQ7dCBrfnDJXnE1aoO VX+1pEV+JJmWR6PxahKYuASVhgLsKLoGyf+tizs5OkoqW1wqqN5rNxLvMHrIX6+mmqIN KKMci27H5Ak5g/XX6X6450KI8PDOzFRfL3yOrE69ZMPu5D6TULiofs/CMJliulDI5UMe KUOXjYk/xRfkK9PFr6MzO2KK/AOxG5+4z7Ry57JR9dkRPF/pPD9mGYGQ5sjxrfKPUcyD jMKyRAAn3cDFQmB3Wdgw+jLcJbaeVk+tCZUTS1C3aFR6KEZZql4+UXQbV9y/tt0jOt6O oSYA== X-Gm-Message-State: AOAM530RjUvi46TQDPvm8N3hk9sZHtcBIml127apYEfTDd3/USr1v8DW NCyBQg3uXKilTyLkvDIPinMxRF/a4rI= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:d580:abeb:bf6d:5726]) (user=glider job=sendgmr) by 2002:a05:6402:54:b0:419:9b58:e305 with SMTP id f20-20020a056402005400b004199b58e305mr25365353edu.158.1650991553606; Tue, 26 Apr 2022 09:45:53 -0700 (PDT) Date: Tue, 26 Apr 2022 18:43:05 +0200 In-Reply-To: <20220426164315.625149-1-glider@google.com> Message-Id: <20220426164315.625149-37-glider@google.com> Mime-Version: 1.0 References: <20220426164315.625149-1-glider@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 36/46] objtool: kmsan: list KMSAN API functions as uaccess-safe From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Link: https://linux-review.googlesource.com/id/I242bc9816273fecad4ea3d977393784396bb3c35 --- tools/objtool/check.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bd0c2c828940a..44825a96adc7c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1008,6 +1008,25 @@ 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_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", -- 2.36.0.rc2.479.g8af0fa9b8e-goog