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: 13447415 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 0E8F7C4332F for ; Mon, 6 Nov 2023 20:10:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60E1B6B0285; Mon, 6 Nov 2023 15:10:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BE916B0286; Mon, 6 Nov 2023 15:10:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AD5E6B0288; Mon, 6 Nov 2023 15:10:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3B2FE6B0285 for ; Mon, 6 Nov 2023 15:10:38 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F30EE808E6 for ; Mon, 6 Nov 2023 20:10:37 +0000 (UTC) X-FDA: 81428622114.30.E8B5A8A Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by imf25.hostedemail.com (Postfix) with ESMTP id 3519BA0021 for ; Mon, 6 Nov 2023 20:10:35 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BE0rMBjP; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699301436; a=rsa-sha256; cv=none; b=4jraiaq2kH24sH63/sTbH7V/Uw2ZOfC/RT5aAjticu5BOmAAVISWJKoODvlNxKvxeugz+O 0N0kZaxZ81gWxMQzXV8Rt3sqWe6Mk7elvBC31AmKFTb2gCXJt6YiyIcHmqAuIXKKRRrvtd Bu7k5ZXps/vbzTuYKwfLH7mWRaFV2SI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BE0rMBjP; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.175 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=1699301436; 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=2N8dClZX4LkeO9h3I7+1TV9x58bgqnnBtKmXGx6mG/E=; b=g6mLoKNC1XzhBOQfmdpRAcTUw7/JKPez2v+fJyxRfmLPMDZe6zsWN+3oQiwtadxMduubI+ 7DB9tWBNFSSnaCeqen6E2DF7/sA91N9m4QIW5+6D3m1YEn8IRyr3yGw+f1NH0Ff0XhylA0 TBG/oDZK5Lh64tMS3m8YwBtFGbOgnvk= 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3519BA0021 X-Stat-Signature: trpmwkakqdigp95bx7hefujkzp7uored X-HE-Tag: 1699301435-434482 X-HE-Meta: U2FsdGVkX19qEfEt1gdYm4uNa+gic4hpEFRSndgiQju2ziIWxalxAvPHQWp+csGkVrWDSzXak9FoT7sO47cD4IbUtrGD2GSJ1wr7gcLrPupDu2bW1MGyon2cryGJZLa6ImKFGRlj5HcMBMTGLFsmdSERlmYmSLpOopmZ+D/sqZKTC0Rc46BPOoBjSWv+M06nWWST6AKximyYX3ittRenEHC31G3vkQngZv2IE4/r39pT+Ba2m7urHnBBQZLd2BcrGoW+/cN8Q0xc6aWOM7g1Sl4yEwsMxOl/GJAI9U0LnqSjff6IqYaAzDydbiBR3PlRSBWYM4dSG//BQgyNm8iibnOJ8uEuzDBQhUW3isCtETa85LzIWE8OCP2uj3LeZeKnZ6/d1QCeuPjI3EW3jT7TT5rFIlrqDl799d/ONE95+iuCMhVu4e8J1fxDEuuzPG7nNSw/TNG8MdbG1ooMJhX2aVmUyYXeYiK8NatlmPgwpU/Mx13h2+ZXbHOGJSiBFDofMtI2IswofHivVQMbdVzEas2eV9Bz2r8MAyN7+vdyZQnQfoa4uPtZ9AKsike6kd9T/KH19MvXKvlLDSkOB5b/8/un5bFJh0cGPHeSYP4q0LdQZCUHWfETqw2K6ME5zuNhM6FwviPpUt9O7c8YoEgKrnZnUuPcLLQaj39q9kILMt+1huRjYc8VLn+8nIXq3ObO5Ve9V9omGANywPLcVAMKLuGIjfBVFhOoWo8HuCnigUND3Cz5LBSIBs5+W38tdW9sCLVFxMQjlmDpj4t8TvqMZkLhKjTioD63g/yMO+uSxoNEtUdu97OQPUQzlPOghWgIjLzoOQz3vvJbEl7tcSFjjH36lB5YK8jV+WcMZp6KapsOV+mTwI1VAeZo7tZeD+LYlP03ea+bEftp2ZKZVgBzuOtWssmBRtpAwq3OK7yLeXcisoMbuXsa58njUYILmizm5/bcObdqDkliLjR7lNh hMrQMV62 HIgy8SqAyF7tA0OlwixR7f7wnmRAMYASR41xq0X4jz9YiWkYp7bH/P7hbcO9ZKpHtUBwO/1HfqN2rLUKDVDjS0FslJli+nt9sGsFoaj7qn04Ex1uLpx8uUDKh1LgBW3o9+8ppfYmDMGltm8MWxINXdxQX5Pqg5Pf3LMTXUs3n+988X+4= 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. 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(-)