From patchwork Tue Dec 19 22:28:44 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: 13499294 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 3D2F6C41535 for ; Tue, 19 Dec 2023 22:29:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9F976B007D; Tue, 19 Dec 2023 17:29:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B4F696B0088; Tue, 19 Dec 2023 17:29:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3EDF6B0095; Tue, 19 Dec 2023 17:29:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 905ED6B007D for ; Tue, 19 Dec 2023 17:29:15 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6A8CE16024A for ; Tue, 19 Dec 2023 22:29:15 +0000 (UTC) X-FDA: 81585009870.09.0CEF01F Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by imf24.hostedemail.com (Postfix) with ESMTP id 8A4B618003A for ; Tue, 19 Dec 2023 22:29:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=cmqIC4mq; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703024953; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=4hIWKlq3vwUHvNMJIcXvuTboO6P/RRCs5XS67UMRG18=; b=F9JMC1nOUj8ny212azCTQrR32Xqq71rKpUQSqjeShvyQLwYSP6PoexBMCIsr1YuSGaWtns PlUaYuHHfYcnKY1qOFtVh897mifRu+tHKHlqgnBdyT8Zhufx7A/VM1RGwBwdokc8MOenuw 1ZK4/PgZtRvYijEWDD0guJtfSpVZmmo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=cmqIC4mq; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703024953; a=rsa-sha256; cv=none; b=wRRpzgkWW1Pw/fDrXOz/cV0JPZWk4xcCC3Uj1yes/pR7mjWxfybf0BKBPpH+81i1nENcDX I9cX7sT6nIz9lEhu0KoQXP9xnun0JgcBpCVB9h/8pwTSDdZiYnqXmBHHEkfsv8ULHr4loa JIZ7R7mbrJGjFeeZjMzxECJWvK1XNh4= 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=1703024951; 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=4hIWKlq3vwUHvNMJIcXvuTboO6P/RRCs5XS67UMRG18=; b=cmqIC4mq/S1If3wT0VfK4ZSI8XnX48OZPjpLmv8Nch6LR34oryd27ZqdCEKyY6LHfFJJsq eErX9SPgAzm7ap40rzJt2NtwXY3A7eaRiArCtrdS3JJsvDA853U3/0S6FWfyzlfKznN6hI IldQO8JAQsTlsxMRb2XrXbDrvagtAkI= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Breno Leitao , Alexander Lobakin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 00/21] kasan: save mempool stack traces Date: Tue, 19 Dec 2023 23:28:44 +0100 Message-Id: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8A4B618003A X-Stat-Signature: 8uikoyn1cecof5kd3yhgktjxrs5sg371 X-Rspam-User: X-HE-Tag: 1703024953-355757 X-HE-Meta: U2FsdGVkX1/pv56alzPKh2v1UDkwLHRp/1g1Dgji5niUi46ZzllAvrZdL7W7h8EB89aBZn40HnQ8b7BTB752jbpTkMr6DHgReac5dk8fEIp1AXsMO9rQRGCwSPelCRb0pw7BBYsj03GwPJowWgXz4U8M5rKneN6zvLa8XBhXvaxxiRWir7LjTTr3WMROpAMeHjXW3rYNfaCRJWBeMfMCiWnp13AhV5RknGUoV6Sz3wlEbsao9xvlxs7A//s3JN1KS3sS/EZ7zR6U2YBrQSNFngW4FxqMCTwW1hHvEYtfWJy3Wh3mC2TA0dWRm80Y/Fb7ftFVxGk6mXIoXtOsL4X6jfO7cLOsR1/yuqRGyd+Nm8Hh6UGtIh4DqHcWp8IXyBh3g5wCAv3NEwLe5PXNYDeIUhPERhnCT8qpE6dL7b8/0UhuAgA/3DYTq43H+66sNnJ57JE9ghoIaotl8XRp567ze7RLLP6LXiNtMsHZuujcL1EjFW6EU4ZQ8WOTTcZ1Q4VVEbk/ogdgNHEd0mwFxI80vssC/RiJOs33EnvL+IDK7jg9JFkOW/wFc08ke1+EeVk0fCsa7gEmIFZ9h//wIzr8lucOun9fsnZz2TR/YsdaLXBKYGe0zpk6EMfJyBe+5FxTtwEGSgTmJ+7+eXbeKcnsTSghsH6raCbpIawZcXyyAkTISuTC4ea0kB7qhZM7XKTWBfYm1F4lUGm2yvdtw4k066zqLfdQ9XxzdIzRJt/E/GiPI+xn/BQT/XhF37wKkX2AqhjoBMfvFW4QsEWfMb46077op2E6GyFFlFhU9ThRoanm1oYXrbZ53dlsJJOdSJbe5OTNqtT4ttWomvkZ0ypA4MUE7UwtNI+Y/Qg07cc5RVAnXQX2bAPSZt8hJTiYPe3Lm1j/wC3rgeF8WAwjSsoJ5T6lVXRCp4kMevDjm20qzmdtoJXPEuJmHpMKzdul1sFw45fQTDPaGxhQnwIyRBP 200miXwU fbqAkPgaahRgkyYju2AbxEcnhnOCJSmZYteR2s+7a+LWwgkEIL3BWRbWKISQtmgbz9yXelxNwPxGuuKYRQ31VK4JgHKVOt+BY1+PNZyuaKg/fQ8ZoQ1ZMkNl9vN0t8O9kXyZnyYg9+IWt+CroBIsh7MDweUk28HbScczIpMjsPBa1YaY= 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: 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. There doesn't appear to be any conflicts with the KASAN patches that are currently in mm, but I rebased the patchset on top just in case. Changes RFC->v1: - New patch "mempool: skip slub_debug poisoning when KASAN is enabled". - Replace mempool_use_prealloc_only API with mempool_alloc_preallocated. - Avoid triggering slub_debug-detected corruptions in mempool tests. Andrey Konovalov (21): 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: skip slub_debug poisoning when KASAN is enabled 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 | 1 + io_uring/alloc_cache.h | 5 +- mm/kasan/common.c | 221 ++++++---- mm/kasan/kasan_test.c | 870 +++++++++++++++++++++++++++------------- mm/mempool.c | 67 +++- mm/slab.c | 10 +- mm/slub.c | 4 +- net/core/skbuff.c | 10 +- 9 files changed, 954 insertions(+), 395 deletions(-) Acked-by: Marco Elver