From patchwork Mon Sep 13 11:26:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12488583 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=-26.2 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, URIBL_BLOCKED,USER_AGENT_GIT,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 4C9A2C433EF for ; Mon, 13 Sep 2021 11:26:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D471460F44 for ; Mon, 13 Sep 2021 11:26:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D471460F44 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7BADB6B0078; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 792676B007B; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A9A46B007D; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id 57B256B0078 for ; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1A8FA1C967 for ; Mon, 13 Sep 2021 11:26:40 +0000 (UTC) X-FDA: 78582322560.17.D6B2F3F Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf08.hostedemail.com (Postfix) with ESMTP id CFFF730000AB for ; Mon, 13 Sep 2021 11:26:39 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id a11-20020a0ca98b000000b0037855a1171fso55550454qvb.12 for ; Mon, 13 Sep 2021 04:26:39 -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=RLfVSTnmaFR6BCLsdGDNNy/lIjkdCKWfb/4pjdgI7U4=; b=FgLtShlMOVfjaXGo7f/oS0G8myvJmOGkAHupBhG1n66pC03AfWY1h02QQwxGm/BC2q NIiVoAt5RptGMta67XGFwYCxNjlG5g+z4pbIT5EDeS+HaFlHPyxz6XLuLeBlG+4Abr3v kYNbhUcrEFGFUE4/+CaCg1scl6StUbvOZxBpqOPfJgxIHfBIzP1tOoqI5daIERLmD/Xx y79UikpTXnQMSKEd6Zhq79VGWW3+g8XJG6WHCYb1QvfRVRgYch7iMM9pNUn3WOVf62yO rmPhlXm2OXvKXpmRroN3j6TxIJlZD+7fafvKRni0OdTZ5WyJIp789q/oqpIb9A8/9eM7 hrjw== 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=RLfVSTnmaFR6BCLsdGDNNy/lIjkdCKWfb/4pjdgI7U4=; b=lVejBGjqh7eSx9jH7nwQQirKL4ljWIQklMWrMaRCAodS/j9Ss5yQqOhc2xdO1VNIWo EAzDWFwGN9vemju1KA4ADdxSM+nV2wSjE4vZNnvcJkQN0Wj24x4k2SW5KVLwcDVx/Pbi 3Y39gEObzEYNM/4QoFdUcEWmjUYLru24zB/8/en11mBJxdhHZdXh1m78EvZku1zS8lsR X5UZYGy7WanRfG3ij58uyD00f5qzKvSuC0oiOObjdm5gFvDTgZ1Cg6hJrRJ530S8Dx+R IrGFPaENvvdGttCZ6bwKZPbeRIXJiPn3hh6vxAL9nsg5vtjNUneaTcx0RXPCLC3f6oya c2pA== X-Gm-Message-State: AOAM531hpoQh24Exzp/PVB8Mieds/piBEleWRj+UK3MRd3gOfHVgLtk9 2542tIZCucIz9UV7U2d/RP5tm7ypJg== X-Google-Smtp-Source: ABdhPJwEBO7FeGHgJTcmfUUVA+smyLBjaAlSYjqDfG51drrvptWMJdaA6VPLMTvhcadpEq6oPbHI9LyatA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:ad4:56a8:: with SMTP id bd8mr9898132qvb.0.1631532399089; Mon, 13 Sep 2021 04:26:39 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:08 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-6-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 5/6] kasan: generic: introduce kasan_record_aux_stack_noalloc() From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan X-Stat-Signature: ks7xr7n7jcq64hii5m3i9yr56ibqxboc Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FgLtShlM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3bzU_YQUKCOYMTdMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--elver.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3bzU_YQUKCOYMTdMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CFFF730000AB X-HE-Tag: 1631532399-802244 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Introduce a variant of kasan_record_aux_stack() that does not do any memory allocation through stackdepot. This will permit using it in contexts that cannot allocate any memory. Signed-off-by: Marco Elver Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior --- include/linux/kasan.h | 2 ++ mm/kasan/generic.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index dd874a1ee862..736d7b458996 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -370,12 +370,14 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {} void kasan_cache_shrink(struct kmem_cache *cache); void kasan_cache_shutdown(struct kmem_cache *cache); void kasan_record_aux_stack(void *ptr); +void kasan_record_aux_stack_noalloc(void *ptr); #else /* CONFIG_KASAN_GENERIC */ static inline void kasan_cache_shrink(struct kmem_cache *cache) {} static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} static inline void kasan_record_aux_stack(void *ptr) {} +static inline void kasan_record_aux_stack_noalloc(void *ptr) {} #endif /* CONFIG_KASAN_GENERIC */ diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 2a8e59e6326d..84a038b07c6f 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -328,7 +328,7 @@ DEFINE_ASAN_SET_SHADOW(f3); DEFINE_ASAN_SET_SHADOW(f5); DEFINE_ASAN_SET_SHADOW(f8); -void kasan_record_aux_stack(void *addr) +static void __kasan_record_aux_stack(void *addr, bool can_alloc) { struct page *page = kasan_addr_to_page(addr); struct kmem_cache *cache; @@ -345,7 +345,17 @@ void kasan_record_aux_stack(void *addr) return; alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; - alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT, true); + alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT, can_alloc); +} + +void kasan_record_aux_stack(void *addr) +{ + return __kasan_record_aux_stack(addr, true); +} + +void kasan_record_aux_stack_noalloc(void *addr) +{ + return __kasan_record_aux_stack(addr, false); } void kasan_set_free_info(struct kmem_cache *cache,