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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7877C61D9B for ; Wed, 22 Nov 2023 17:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 129A46B0507; Wed, 22 Nov 2023 12:13:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DA3F6B0509; Wed, 22 Nov 2023 12:13:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE4F26B050B; Wed, 22 Nov 2023 12:13:32 -0500 (EST) 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 DD0706B0507 for ; Wed, 22 Nov 2023 12:13:32 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A26A3A1146 for ; Wed, 22 Nov 2023 17:13:32 +0000 (UTC) X-FDA: 81486236664.11.DEE00D6 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf18.hostedemail.com (Postfix) with ESMTP id B80601C001E for ; Wed, 22 Nov 2023 17:13:30 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fjjiPRy8; spf=pass (imf18.hostedemail.com: domain of elver@google.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=elver@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700673210; a=rsa-sha256; cv=none; b=2PUD5g4UN8MUWVryPfYkIRTtonqhf4LLIr5EiwpLoqv2pvH9nXdWgTFyO8LBhmHikGG6Li sNWKYOVP7s6aERiwmrD3tTVyzRtLpvdTT4eG8Q1PUx5F9zjPLXaZZPmEp6SOXYvw0Z2I1A cM2+JOSz+UvMxJauHB3zOfIg7CsHpxc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fjjiPRy8; spf=pass (imf18.hostedemail.com: domain of elver@google.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=elver@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=1700673210; 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=iREYFokOV8dvymG/8i5EmbN9PgByJeos08X2K2e+878=; b=d5D3kVHnUV/cpskxZg+Asw3UQLyC7goConZl4qHVa6mPywllftoZArCDBlQgBPvrkhH3Ha ymQsi4rjC1hWsA7q0NPRQCz1Bh6NATjvOOB+4kPQ5PEK/byo2gofsvHOEOf4BmavtHLE31 j11cxFPWaoRxp9X1yyrxvHISVCBmGjQ= Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3316d09c645so3589908f8f.0 for ; Wed, 22 Nov 2023 09:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700673209; x=1701278009; darn=kvack.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=iREYFokOV8dvymG/8i5EmbN9PgByJeos08X2K2e+878=; b=fjjiPRy86q3FTms8AHeeFq86lNyJmH3jPfTjerxV8XDeSu1wVnJG7tZro67rVeleMx Ymgwry2hZ6O2lGLD/XwMpZaVpPY8MYIOgAPfn7PLbLrsk7isZbWSlmAmpehd5sqCXoZc S+0kfaifKybRIxMHYhbweHARZ0UXadb/j0beHCTb2XmTKcUfU8umsm6b5odfoOA5dG3I bit0sDYmlZM0HqFBLtRYYhRLcajkevHrb+8TGjLMykej384eOFR1hhXCJEr6sj26Aao1 oTK/IFFGFREA38fKZjaSTOztTkGmfw//sHY6xK2+6kfL12RDlbAVl1uf9elSvI2CuglG ay0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700673209; x=1701278009; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iREYFokOV8dvymG/8i5EmbN9PgByJeos08X2K2e+878=; b=VkOqG1sEDFordURRTWfE50ftC1Pt4Wp70qM2f9cqkGOoVJj3HdHh2GP40lot2OeTtl VeDsNHynyWC2rBApUBI8q3qut74QmQFOMJRZ2KgWz9PuaQYaMmaZfGoN1v8kcvOvTcyE PJgqBcBXbiALddqDsU3efJjNcO5OGfxy2JqUAc04ibwSVNTHOVPT+qW6xvx7Jxg+ssuj 3m3/YrwofWsC2mZCbtUG4+BtavwXQfa2L0ix5JxDYdV57VzPJMEfpWrkBb3rMrE8Rm5n T+ZvR3w31ALJffj6q+qbnjLFzCbe77A23ogylXtJFfrsBs5CsWZyWzUbWF7H73ZYwCkz QRTA== X-Gm-Message-State: AOJu0YwXMhVh2HT55ujl2t72Ffa+xvCE1dmFtTJnaPpG9DQ/YlW7HV/+ oQ9LW1dPWBaQ2H5j+gCDdsBsTg== X-Google-Smtp-Source: AGHT+IHG50GHV18iXf9NgLcNgDR5o5sNBk599jpI37YLzVcyzNoVxOG6dCer6jFfQZDfi6s6ijq21w== X-Received: by 2002:a5d:64e4:0:b0:332:ce3f:a370 with SMTP id g4-20020a5d64e4000000b00332ce3fa370mr2275817wri.51.1700673208904; Wed, 22 Nov 2023 09:13:28 -0800 (PST) Received: from elver.google.com ([2a00:79e0:9c:201:1dcf:36df:c2d9:af51]) by smtp.gmail.com with ESMTPSA id b15-20020a056000054f00b0031980294e9fsm17633839wrf.116.2023.11.22.09.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 09:13:28 -0800 (PST) Date: Wed, 22 Nov 2023 18:13:23 +0100 From: Marco Elver To: andrey.konovalov@linux.dev Cc: Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: Re: [PATCH RFC 00/20] kasan: save mempool stack traces Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B80601C001E X-Stat-Signature: utbs7efwkzock4rwug4e8mm9otx9jeko X-Rspam-User: X-HE-Tag: 1700673210-531837 X-HE-Meta: U2FsdGVkX19DKDIegHKI4dz7XRwP8HfU6kSgQN+anSXxKl7gN8K6ja6BCWAQN7+OSw9F0O3E/mxtP77KGTLfJvXngYbKpkHxRsVSBMZZdICsHEsD/aVfI5QPQEEwBl8/O8qw7UOqzcyGuoIfKqQHDRE0VnB02OKpLQDmwkzTZqAJ8541tuMwMcxqfJaE7MgJYkxs1R4ACjBRJrVjjxNYAqIxHFhlCd98r+dgTfiSOpeoQUjMha1ZmWWkrNhqOLWVNAfpOgJ0e9o82KoIS3oXq8VGi4Q/NeOpGNVxQc+q9YWQL/T4hakZoc2+G3n1rb7qRlKnhsin8dDhrJgMHKDft4JmGlBXeFRc7BZ1V/BIEXTpXfW+z0T1a3Bl6gJP2Ap4oJObOpqQORyP/WiuU29TBltQXcqDtpGkodoHpfG26bXf21rJutLuGqelRQK/UOBc0rQxvYRv6U93nIdvmL2U/pIF3BA6X5s7PdkuMc2B/KWha8CbhnB/KZkUlRzMZovdaiTZaSlcGSh5YFNlTZaQCRNrhxkp6RrS/7xKPJ2wXjPTXuJCfx0m3Unwd+ZggAsdFYx9G5khIndJv3DP1IDIVhp7v414uRzLp8jgoQIsTiw8LfO91mdxq0vIH1ns7R/Q/tlxtxs6f41py4w3F6mn5zt4j389sEbG1s2UFsPBkNojvx2eA3+rsg9Sf4Hxa1BmCZ2ERCocgSv9xBzOl3vtJtQL5wfQ+7c5KoHFOq+BiJY/SoGO5LQVzFtovg49m56TB7rl9akIO6Fte8zGFIdsfMlKQasBxMICTTSV/IeF8uyEehkBVk1IaUsv7L/TnTeaA5MVUSmKTAKbTR/DXeriqyBfH2oq/tLwlzv3YSvrNYeLfTj6o+Mqs0BQ5ZC03HLYdL8nIWYJgT+GNzVpq4y58Vb9BrB0pqra90MoHoouBhWjDF1B1xPbQW/FSIKGRB26upQ7BPktb8Y+GGVndev 68SdTV6m VMhsFIwYmHFj2qTLYIPBQMSvS04y9sxeML4Ele+qy7MrNAOW2lmeY06HfS+60ViLJEjjBb89Ji9sitX+eZj1IhMwWRDCU5wOZcq6fXdQnPQ8VOrWFY5ytLf9ny8FdcmD3IrL9mrXagGIdqptS4sXlXNWq3F5k1z8WZTIvubXRfsO0o0ZiuHr80SaeOisPzR8M5wJN7gXu4w1aFvgrxsJ/8GydrpdBECmcGadA5LgWCWHXWY8NdOS/oFOLaVauPW7+qSXBiOCiu+2CHXB2w8838w0/KAy8Yr0AHcrWxu07CWqshl8/symZ+iHPnWG3Hs+/tH3LanDuVpnJsxuUc/fqZmDnLXZAZrnREaK3j/V05Xt+GKbtXlBOEh4hgA3khusMLeJfy3egYuc08G4WUVihNiKS9WBkaz367B9tqpqhWNYUyQxq/CotPfBfpk/1h1RxiK/5hSi0wxZMFGVKTnjEPFeIeA== 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: List-Subscribe: List-Unsubscribe: On Mon, Nov 06, 2023 at 09:10PM +0100, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov > > This series updates KASAN to save alloc and free stack traces for > secondary-level allocators that cache and reuse allocations internally > instead of giving them back to the underlying allocator (e.g. mempool). Nice. > As a part of this change, introduce and document a set of KASAN hooks: > > bool kasan_mempool_poison_pages(struct page *page, unsigned int order); > void kasan_mempool_unpoison_pages(struct page *page, unsigned int order); > bool kasan_mempool_poison_object(void *ptr); > void kasan_mempool_unpoison_object(void *ptr, size_t size); > > and use them in the mempool code. > > Besides mempool, skbuff and io_uring also cache allocations and already > use KASAN hooks to poison those. Their code is updated to use the new > mempool hooks. > > The new hooks save alloc and free stack traces (for normal kmalloc and > slab objects; stack traces for large kmalloc objects and page_alloc are > not supported by KASAN yet), improve the readability of the users' code, > and also allow the users to prevent double-free and invalid-free bugs; > see the patches for the details. > > I'm posting this series as an RFC, as it has a few non-trivial-to-resolve > conflicts with the stack depot eviction patches. I'll rebase the series and > resolve the conflicts once the stack depot patches are in the mm tree. > > Andrey Konovalov (20): > kasan: rename kasan_slab_free_mempool to kasan_mempool_poison_object > kasan: move kasan_mempool_poison_object > kasan: document kasan_mempool_poison_object > kasan: add return value for kasan_mempool_poison_object > kasan: introduce kasan_mempool_unpoison_object > kasan: introduce kasan_mempool_poison_pages > kasan: introduce kasan_mempool_unpoison_pages > kasan: clean up __kasan_mempool_poison_object > kasan: save free stack traces for slab mempools > kasan: clean up and rename ____kasan_kmalloc > kasan: introduce poison_kmalloc_large_redzone > kasan: save alloc stack traces for mempool > mempool: use new mempool KASAN hooks > mempool: introduce mempool_use_prealloc_only > kasan: add mempool tests > kasan: rename pagealloc tests > kasan: reorder tests > kasan: rename and document kasan_(un)poison_object_data > skbuff: use mempool KASAN hooks > io_uring: use mempool KASAN hook > > include/linux/kasan.h | 161 +++++++- > include/linux/mempool.h | 2 + > io_uring/alloc_cache.h | 5 +- > mm/kasan/common.c | 221 ++++++---- > mm/kasan/kasan_test.c | 876 +++++++++++++++++++++++++++------------- > mm/mempool.c | 49 ++- > mm/slab.c | 10 +- > mm/slub.c | 4 +- > net/core/skbuff.c | 10 +- > 9 files changed, 940 insertions(+), 398 deletions(-) Overall LGTM and the majority of it is cleanups, so I think once the stack depot patches are in the mm tree, just send v1 of this series.