From patchwork Mon Nov 6 20:10:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 16310 Return-Path: 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 + 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 ); 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 ; 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 , Alexander Potapenko Cc: 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: [PATCH RFC 00/20] kasan: save mempool stack traces Date: Mon, 6 Nov 2023 21:10:09 +0100 Message-Id: MIME-Version: 1.0 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: 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 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). 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(-)