From patchwork Tue Dec 19 22:28:57 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: 13499307 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 CDE2AC46CD3 for ; Tue, 19 Dec 2023 22:31:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A73F8D0010; Tue, 19 Dec 2023 17:31:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9555F8D000D; Tue, 19 Dec 2023 17:31:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F7378D0010; Tue, 19 Dec 2023 17:31:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6B4A78D000D for ; Tue, 19 Dec 2023 17:31:27 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2437B402FF for ; Tue, 19 Dec 2023 22:31:27 +0000 (UTC) X-FDA: 81585015414.21.093876E Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf18.hostedemail.com (Postfix) with ESMTP id 5B0861C0025 for ; Tue, 19 Dec 2023 22:31:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Kt1rNfuv; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703025085; a=rsa-sha256; cv=none; b=O9HQfOniKjcpnwCwAktcln9ekAIFPFROQyVXAGBGAtmld5Sl712gfebxDJOmZMH2W8lnvH 0Uce7Bb8I2ac4d96kNjNGV3IfFjPwpEYbxR5AsNSER42cFEZCMguYhol+MWxxuCsqAp8s6 woWhE6vq8E4WD3Bumd8Tnl65ua7uFFk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Kt1rNfuv; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703025085; 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:in-reply-to:references:references:dkim-signature; bh=KVsX1wYh/u3bsgXc0v6541Y+g0kgoewEBIuD2sVrVOE=; b=MY8eQkRL4o1nYPOeEJhkAM/+ZqHd3VUA1wgt24mNTAARCCcTIRwSWlk/j7ucQzDY+GtrNN OcItTZ4fnIyqibscFAlfQJ7KSqS1J0jnrWa2T7WcRk+SUzHYxtzpl3IcV39uwXaJyBzaen IgU26IVcrGRbSsT2z+n76krKfLxPSCA= 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=1703025084; 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: in-reply-to:in-reply-to:references:references; bh=KVsX1wYh/u3bsgXc0v6541Y+g0kgoewEBIuD2sVrVOE=; b=Kt1rNfuvx7+wT5H8UNOgwHCeTbOEvaDygKRpZZi3u1FYmus+bD/11ubTVW79B+oIdiaNwz JlwOYJnlQA+xJy+dqmZh3LmC25rgn5CNTohHAkyMco9Blc+/P3IIuddLLDTvM6CJy8A9+O KeuWbai25yfJ/zAiqqyvZxcC5VTNrDs= 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 13/21] mempool: skip slub_debug poisoning when KASAN is enabled Date: Tue, 19 Dec 2023 23:28:57 +0100 Message-Id: <98a4b1617e8ceeb266ef9a46f5e8c7f67a563ad2.1703024586.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5B0861C0025 X-Stat-Signature: eo6zudjx93qkgtao8fa9n9t7hjzwhcsw X-Rspam-User: X-HE-Tag: 1703025085-851281 X-HE-Meta: U2FsdGVkX19bIT8z9ysyFEEGxMdidQlzZEgb9BHu9mHBH/uy5G+KWujCJVzr5q79WpvN1rpNXTrrTywo+sM8kOPdUPPOX494qped6rByFEGDojZGXJrLmLYMz0Ev3GuVaRtWNy4Gp/hkmJ2cK26sm9uA5/52+cQfNkzdJtbDqpK2PGPaF7kE1djvxGbaoVJI0zhJ1PWOVFeoHyXggcX1K6vZg8I0kN6IuGu0uLFxNm8g4cJf/9MRkckgZW7TXm82opENXJR8xb7XkBXXQcIgMGHVrJw49Art/l5VdOQBJdlI2TkqIKNc5bmvJIqjkfFEfOtAnDt+/IsQSQscDvzmcvh2VICAZxXtBc0rFAnwBPRE+7tx6e1NJ7rIF8cPXkycCJYCJFim2oFbbHYXqFt5T3fcE5GEcTFvchYE+nYMVNk1X2w//nE1EN/kZ1oBwwKXL03+O5bSq6BC7z87gAclcCkkyGRlMWGqqzCk5M93BkJ+2/xXCNb9To+pYb+aFfdUH5KmKKUDw4GnkThoyI3l0KHvT5l/nTAd81pynlDl0b2O42C7QBj9NEomoliUPdtEp5mZi6SWwYzG3qeCSUT6Sx77yAJRaWa/j94Zl/8KcLjHk6gVeVUTP9tVc5Zihx1nBvLr4ixG9j5LTkOPu0N8YILNNP9AxOxzGv2KhrZJ8xY+QDJ0guHL6haB5hZ0F/YdQRjFM2e4TX7Taxcra4g/BoNune2lOoh7bYKNhfpcZ4QEWD1GaSIqgw+J2zVBOUUwoHHtywUSFJkg1KOBaO52Zw94U38i4pT3P4JtHIoJlpaCvPTjGlTKmCLsP7cy1jqKgw73lCoVRGqtma+B/qEd3ksTMYe1N4A6sWQ6qVvJm7hSrm6w/cQB3+tImsvCij91AcUbkS47L/KfaFKQiP3KRAZUk1xbpBYmqMY3U8SxqVwdif1aCU4wZb6w2mhlPjfnfyJVi2orw2e5FIb3F5W car26xPa 2qK2QrU8xzsY6HvoNsn+9nVAU0k+6XsIK0i4YeOdTlUxp+GUJuyVJeoNkyrPUT5svKqOl0Uy411Yb0p1E5ELrEaQH7OckAj2nLXUxY6EYnw/CB4Eq36AV39sHD/cbigXeM6rkKm1GzrMBWsjgMiHrtfe8BFcicHbmWVP0/hHQVr56+KbtxlxpsNEAhFUGcVK+eacUp+3w2FTKMTmrGdHD+x2D3A== 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 With the changes in the following patch, KASAN starts saving its metadata within freed mempool elements. Thus, skip slub_debug poisoning and checking of mempool elements when KASAN is enabled. Corruptions of freed mempool elements will be detected by KASAN anyway. Signed-off-by: Andrey Konovalov --- Changes RFC->v1: - This is a new patch. --- mm/mempool.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/mempool.c b/mm/mempool.c index 7e1c729f292b..1fd39478c85e 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -56,6 +56,10 @@ static void __check_element(mempool_t *pool, void *element, size_t size) static void check_element(mempool_t *pool, void *element) { + /* Skip checking: KASAN might save its metadata in the element. */ + if (kasan_enabled()) + return; + /* Mempools backed by slab allocator */ if (pool->free == mempool_kfree) { __check_element(pool, element, (size_t)pool->pool_data); @@ -81,6 +85,10 @@ static void __poison_element(void *element, size_t size) static void poison_element(mempool_t *pool, void *element) { + /* Skip poisoning: KASAN might save its metadata in the element. */ + if (kasan_enabled()) + return; + /* Mempools backed by slab allocator */ if (pool->alloc == mempool_kmalloc) { __poison_element(element, (size_t)pool->pool_data);