Message ID | cover.1699297309.git.andreyknvl@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2901513vqu; Mon, 6 Nov 2023 12:10:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHg4opmEP5ZbPC8h+1pqggG/7erlxtE/lmHO07jC2eEpTuhnfZclFH3VqJkIEyaB0woLTxo X-Received: by 2002:a05:6358:71f:b0:168:e7b7:1e40 with SMTP id e31-20020a056358071f00b00168e7b71e40mr41015568rwj.7.1699301449627; Mon, 06 Nov 2023 12:10:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301449; cv=none; d=google.com; s=arc-20160816; b=ymTakc5RjfqjcM6QjWCkywVPsyeVAfvmiv0EGwEf9q+BH7MQgw0cSQW/KHE//AeZVU r0kU5DzTAz3fCjsHY0zMtvjXyRkYlKlfAlr1HVGpxvpZ4m3dLzCA2oMDzqhkTAo1oDLE SIApSOW3X8dDSfJjZyzuTcY2GjigT4zF3T+Uh6HWO/Gw/L+s0XshOIolC6OOlLfYykNx fH9rehbQ3H5kafK2PeukBHMyh3OiNiXquhfD+UAdX+C34fnzWsuJUo1IMUWeJcw98lIV +rk4C3OclwsUtfJ13POC9YePTfClJxYQaz5YGIlmlyeUX1i/KnwTekCbMKFrDrpfQq+a JG/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2N8dClZX4LkeO9h3I7+1TV9x58bgqnnBtKmXGx6mG/E=; fh=n5KN85tQTomq0Sa/nFFC9xbnc77mxkBzF8HoolO/QOw=; b=rpXGlUNJkG1bGlVR9TlH/f1QyoX2TTGAkk1TjRa+qi6LoyAuqMD0YIbaXxsLMkn0Ht 7FTILKjPm01RanmkjuadonX+QE6GD+41sp0SLg5FKDEfCxRzD/0EfodCclSYjnB8Ijtk GRLZN2hxQ87/DTqIc28pFlMBEf3xFnLdjpNzr0YedBpbGy/HPsObos6NigdMLT2YjOIe dBWub08wHaECSvl/8/Sd3xJEtGiiPlfYiZUiWyHdyGjzML2Tgms2MeylyjG3ykKFch7e JBiV9f0sUYpi0oFLfHYzdnTXcm/GSzU49zSeg2M/+E+GNtTLEqUppxEfXXd9KcCvk0Ey 5tPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=BE0rMBjP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f14-20020a63554e000000b005b8de051ac6si410571pgm.111.2023.11.06.12.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:10:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=BE0rMBjP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C1373801D4BD; Mon, 6 Nov 2023 12:10:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232959AbjKFUKm (ORCPT <rfc822;lhua1029@gmail.com> + 34 others); Mon, 6 Nov 2023 15:10:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231801AbjKFUKk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Nov 2023 15:10:40 -0500 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [IPv6:2001:41d0:203:375::b0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF147D75 for <linux-kernel@vger.kernel.org>; Mon, 6 Nov 2023 12:10:35 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699301433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2N8dClZX4LkeO9h3I7+1TV9x58bgqnnBtKmXGx6mG/E=; b=BE0rMBjPXM6NBg2ZLuCgNQZtZtu/Aes69+x5dc6h44mRv0DPnGCIuDvU3eryTOAcGk3hNg ivAZm/6KtxWe38HMEo8I8/AMzJXDVBqo4Mn3ZcihM5yvVZ3QNqmM7j4WvztErIv6cds9PK vR9a7t1q0ywIWsjkIqIoYhpVX9OdwQo= From: andrey.konovalov@linux.dev To: Marco Elver <elver@google.com>, Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Andrey Ryabinin <ryabinin.a.a@gmail.com>, kasan-dev@googlegroups.com, Evgenii Stepanov <eugenis@google.com>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov <andreyknvl@google.com> Subject: [PATCH RFC 00/20] kasan: save mempool stack traces Date: Mon, 6 Nov 2023 21:10:09 +0100 Message-Id: <cover.1699297309.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:10:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781846716694133982 X-GMAIL-MSGID: 1781846716694133982 |
Series |
kasan: save mempool stack traces
|
|
Message
andrey.konovalov@linux.dev
Nov. 6, 2023, 8:10 p.m. UTC
From: Andrey Konovalov <andreyknvl@google.com>
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).
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(-)
Comments
On Mon, Nov 06, 2023 at 09:10PM +0100, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov <andreyknvl@google.com> > > 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.
On Wed, Nov 22, 2023 at 6:13 PM Marco Elver <elver@google.com> wrote: > > On Mon, Nov 06, 2023 at 09:10PM +0100, andrey.konovalov@linux.dev wrote: > > From: Andrey Konovalov <andreyknvl@google.com> > > > > 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. Thanks! :) > 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. Will do, thank you for looking at the patches!