Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp215640rdb; Tue, 19 Dec 2023 14:29:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKyzZ07PZVGOqVND795QDrNlOAHB3lBnuNQz1myCi8THPTnpvT7kL/dd7FFUtJT09So3ge X-Received: by 2002:a17:902:680f:b0:1d3:e636:f722 with SMTP id h15-20020a170902680f00b001d3e636f722mr987537plk.74.1703024978768; Tue, 19 Dec 2023 14:29:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703024978; cv=none; d=google.com; s=arc-20160816; b=zpTW+30f33B8dIAGwwLVWjk6CZtlHNcuUmAoqv3F0WcEyG0smUdgVScxP54rIX+bLg xN0vDp0cV9X0bFigxe83SLc9fMBFgJSBNW+qQlkfRq0JM+DZYCxr3/GtAQNCCx7a7lEZ zF12i3Twu+D3+gDXelhQDGhaQT9d35mH+tsCCI/XVpWNTd7J+gkV6jeXhdOTjoyb+t7o rIdYyVm9S3gUH8QIe1ramlnDooGh6zgTjjEsHJ/IDtIDD3+ROsmMJ1ZjeXch2IKPQkwm D05e+ApQZl825EypqOX6kHwEp2pgxU8q6MHbHQOFob4V7WvTaVuhu2ecC8I3zCp/fRxu dRYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=4hIWKlq3vwUHvNMJIcXvuTboO6P/RRCs5XS67UMRG18=; fh=AIzsiqkKUtrB7QnM+XRgAblgvDINIC5pDvD0mg8EzrU=; b=bxbGid3hjYITNlCg+Lbnm33hivsUO3+SFRc/GujyvPE70luSjZKgFAvZjgSjQkQ2kC 7egP8pKpONWmCOcIMyAxpljl63DcDzt/NkVy/bOGQ8Sh48dwtk4SawCzRVPJyntZo6gT /YC4nqx+m/e//N7MM2Frnrt+mPXFONGo7sRneeSHfO2TcrWO1R75K0hCafasciGeawm8 Plg4oD6HrJsE/UY+OD4Qumve9saAk0PWN1pV0KFRevurAPm8GWY6ZWg77/+dAUbM7jmn US6nWjblcSqKezMN51Y2kTvt6nVt77WQrmHbCYVtr0S2gcejhreLbB5BiKgGdRkRq/fm yqnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cmqIC4mq; spf=pass (google.com: domain of linux-kernel+bounces-6041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k10-20020a170902694a00b001bc162f3318si19937141plt.640.2023.12.19.14.29.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 14:29:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cmqIC4mq; spf=pass (google.com: domain of linux-kernel+bounces-6041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6041-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DCAC0285C2D for ; Tue, 19 Dec 2023 22:29:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10D7F3D0CB; Tue, 19 Dec 2023 22:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cmqIC4mq" X-Original-To: linux-kernel@vger.kernel.org Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64D113D0A2 for ; Tue, 19 Dec 2023 22:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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(-) -- 2.25.1