From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 582DAC433E0 for ; Fri, 12 Mar 2021 15:10:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E78C164FD9 for ; Fri, 12 Mar 2021 15:10:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E78C164FD9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8ACF16B0070; Fri, 12 Mar 2021 10:10:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 882256B0073; Fri, 12 Mar 2021 10:10:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FBF66B0074; Fri, 12 Mar 2021 10:10:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 548CD6B0070 for ; Fri, 12 Mar 2021 10:10:56 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 17EC78E52 for ; Fri, 12 Mar 2021 15:10:56 +0000 (UTC) X-FDA: 77911559712.29.FF17543 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf24.hostedemail.com (Postfix) with ESMTP id 9891AA001AAE for ; Fri, 12 Mar 2021 15:10:50 +0000 (UTC) Received: by mail-wm1-f53.google.com with SMTP id d139-20020a1c1d910000b029010b895cb6f2so15383927wmd.5 for ; Fri, 12 Mar 2021 07:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2dVcHDhdrF5JaCCByrKqwImhRd8nHqVH/GMv12NMUYc=; b=uEkUsdXAu+3Wx+LRPimdLz9bK3tbRru648YN/jwPSMVdxB8GoaEms5SDU8Wz9SkEBV 4weqGxsSfCwlq4PeJGDCPfbPApyLGJZl8PxjauX1j6nJBL/YkfTjwBJmI1ueTUM+StO/ cN9q0mC4icX821DCux7c+cqYJtrqbli92JoH+6HkfMZpA0Wsb+CboYn57kirYgtqAQsn huQWVtqllgVNdpj/MKW3UhRJyzbgzWKJ78S9v3K8GjPdKxH80fjBDo+1IXNUvS6rcn7t W4jT263n6qgBPyqgIOpDNDHB7wPx6YuoPPwzRyuZpBm94maI3HoKgfHh2iBBvfvc0fEK 3aTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=2dVcHDhdrF5JaCCByrKqwImhRd8nHqVH/GMv12NMUYc=; b=ciduc+cS1aiZ7mpkCQE4xfptTBGigT4liMKG1DVjkQ2EEihoUE4TzWicyAlghCV0WO Jtsfa71WulfNqXypZq7jtcY2+N2m3PYXDEKJPdEQ0mT2Faw31m6cMGWKg2+LmBsYJaXL Hy4aLEDSBl0P9RnssKmiEfbMwf/sKzLcQ1UwmbvJiwpPZih9/u9qC9i3x1/uGFOjmlyG q9cJyl6Dp8eJ6O5fBbhAYVSqQ91Tb9S3cDXHYeK5/L3v19UMvDFXA6Luwp0GgsPNobe0 doBMN4R/lStFtjdYKD+hdPOmG7OYXFWMQMqMgVp/Klf91dUdTFmqTKZaZ6UMTuPgyG06 5TUg== X-Gm-Message-State: AOAM530/OAbu1cswrgBlclbDQ0sVM+T/wrTpowfgbaKs5W5xJS5IRaRO 81ADEJFsydQeLitxgSYxJZ6O3w== X-Google-Smtp-Source: ABdhPJzz6EK+f9gBf+L2EFDROJ+8DMjsJCOvqJgP6GqIlly74JOmBbw2twO6HDCMDb8AGCH54xqM3g== X-Received: by 2002:a7b:c303:: with SMTP id k3mr13820769wmj.100.1615561843302; Fri, 12 Mar 2021 07:10:43 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:d5de:d45f:f79c:cb62]) by smtp.gmail.com with ESMTPSA id c131sm2481968wma.37.2021.03.12.07.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 07:10:42 -0800 (PST) Date: Fri, 12 Mar 2021 16:10:37 +0100 From: Marco Elver To: Andrey Konovalov Cc: Andrew Morton , Alexander Potapenko , Andrey Ryabinin , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 10/11] kasan: docs: update ignoring accesses section Message-ID: References: <4531ba5f3eca61f6aade863c136778cc8c807a64.1615559068.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4531ba5f3eca61f6aade863c136778cc8c807a64.1615559068.git.andreyknvl@google.com> User-Agent: Mutt/2.0.5 (2021-01-21) X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9891AA001AAE X-Stat-Signature: 9j5i3eq9q8me97r1tj6bqo1szj3ba598 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=mail-wm1-f53.google.com; client-ip=209.85.128.53 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615561850-762471 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: On Fri, Mar 12, 2021 at 03:24PM +0100, Andrey Konovalov wrote: > Update the "Ignoring accesses" section in KASAN documentation: > > - Mention __no_sanitize_address/noinstr. > - Mention kasan_disable/enable_current(). > - Mention kasan_reset_tag()/page_kasan_tag_reset(). > - Readability and punctuation clean-ups. > > Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver > --- > > Changes in v1->v2: > - Mention __no_sanitize_address/noinstr. > - Reword the whole section to make it clear which method works for which > mode. > --- > Documentation/dev-tools/kasan.rst | 34 +++++++++++++++++++++++++++---- > 1 file changed, 30 insertions(+), 4 deletions(-) > > diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst > index d0c1796122df..5749c14b38d0 100644 > --- a/Documentation/dev-tools/kasan.rst > +++ b/Documentation/dev-tools/kasan.rst > @@ -368,12 +368,18 @@ Ignoring accesses > ~~~~~~~~~~~~~~~~~ > > Software KASAN modes use compiler instrumentation to insert validity checks. > -Such instrumentation might be incompatible with some part of the kernel, and > -therefore needs to be disabled. To disable instrumentation for specific files > -or directories, add a line similar to the following to the respective kernel > +Such instrumentation might be incompatible with some parts of the kernel, and > +therefore needs to be disabled. > + > +Other parts of the kernel might access metadata for allocated objects. > +Normally, KASAN detects and reports such accesses, but in some cases (e.g., > +in memory allocators), these accesses are valid. > + > +For software KASAN modes, to disable instrumentation for a specific file or > +directory, add a ``KASAN_SANITIZE`` annotation to the respective kernel > Makefile: > > -- For a single file (e.g. main.o):: > +- For a single file (e.g., main.o):: > > KASAN_SANITIZE_main.o := n > > @@ -381,6 +387,26 @@ Makefile: > > KASAN_SANITIZE := n > > +For software KASAN modes, to disable instrumentation on a per-function basis, > +use the KASAN-specific ``__no_sanitize_address`` function attribute or the > +generic ``noinstr`` one. > + > +Note that disabling compiler instrumentation (either on a per-file or a > +per-function basis) makes KASAN ignore the accesses that happen directly in > +that code for software KASAN modes. It does not help when the accesses happen > +indirectly (through calls to instrumented functions) or with the hardware > +tag-based mode that does not use compiler instrumentation. > + > +For software KASAN modes, to disable KASAN reports in a part of the kernel code > +for the current task, annotate this part of the code with a > +``kasan_disable_current()``/``kasan_enable_current()`` section. This also > +disables the reports for indirect accesses that happen through function calls. > + > +For tag-based KASAN modes (include the hardware one), to disable access > +checking, use ``kasan_reset_tag()`` or ``page_kasan_tag_reset()``. Note that > +temporarily disabling access checking via ``page_kasan_tag_reset()`` requires > +saving and restoring the per-page KASAN tag via > +``page_kasan_tag``/``page_kasan_tag_set``. > > Tests > ~~~~~ > -- > 2.31.0.rc2.261.g7f71774620-goog >