From patchwork Wed Oct 16 15:41:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 13838599 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 27B35D2A52C for ; Wed, 16 Oct 2024 15:42:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAFE56B0089; Wed, 16 Oct 2024 11:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A600A6B008A; Wed, 16 Oct 2024 11:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 926C76B008C; Wed, 16 Oct 2024 11:42:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 755406B0089 for ; Wed, 16 Oct 2024 11:42:01 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8FF1980664 for ; Wed, 16 Oct 2024 15:41:52 +0000 (UTC) X-FDA: 82679881116.02.3AF5199 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by imf27.hostedemail.com (Postfix) with ESMTP id B1D2140011 for ; Wed, 16 Oct 2024 15:41:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="daQwXQP/"; spf=pass (imf27.hostedemail.com: domain of feng.tang@intel.com designates 198.175.65.10 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729093246; 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=dgmN9NQot3rIqBZ76hf4jeaZaZSf/C6kNIIS6FtSwZY=; b=raDqYPYDhIgNh9vgpF51qip3LUQ3nOPpwYSHwInDT1wtBrfV0rmykmc1X74AMFuYBGwVM8 4K7ecfNaxU/f6EbVvwngoDucll10ZjLV+KW3lnPzvamiXgKQqIUEBi8oDEO5qxnz2Yqt9N Vdk/eO7icLYvBO7/Uu2xAJ/BqKXKhuc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="daQwXQP/"; spf=pass (imf27.hostedemail.com: domain of feng.tang@intel.com designates 198.175.65.10 as permitted sender) smtp.mailfrom=feng.tang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729093246; a=rsa-sha256; cv=none; b=GxLTy7ZGFCP0UG8NEgyxE5U5aMZixIdl9vs/3vBe+QKQwH/1MV/X7428z+zN4BX1LEFTiU T1yrI8Z3PvXiAzNR8e0kgITIjQemhWKZakQHWQFTEEd2qxutTRBVJeawFdk+/9YOEAUcIf +02btan2kv2VHnP/76h1LTB7JsjvAq4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729093318; x=1760629318; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/grc185rxLSFdU+ikEexjliKOiRIJIi6ABacyFR+WqQ=; b=daQwXQP/f2Key1ypklz7/84Q00hohOBd/4kP7HDmBs57EBoYJ+X+71Ja A40e1IDT46T1Qg9gTc1rRFBW93/LQJnHrEBZUHeM5YC343wY7/GrRjSTz gX9nZaCeemPmsL/Nh2Or34iqgZTT19LILI2UP4KZlzwje3jnBUFlcQE0C cPArndzwFcrm2ETQ8xMerqsCz6rFWotmPCprySgTd5cxRD6axHXQoGRjU n1ezaT/J/RcoukyM9ErMSDG55E3J+IznF3fck1CufxywLuvDfawyPNkET oArmqbTk7m8mzonz9dKeisqn5J1vNGgskZCX8gNd9LEYFQeK+4gSnHKAV w==; X-CSE-ConnectionGUID: IP5+QYP9SvSo/Wa8WXMXtw== X-CSE-MsgGUID: yOUikCLWSVKLXnHGuK20GA== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="46021330" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="46021330" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2024 08:41:57 -0700 X-CSE-ConnectionGUID: Hg18HRddRDSTDV4mNZenXA== X-CSE-MsgGUID: Ej/vS7TOQlqpQHn2zNunUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,208,1725346800"; d="scan'208";a="109018894" Received: from feng-clx.sh.intel.com ([10.239.159.50]) by fmviesa001.fm.intel.com with ESMTP; 16 Oct 2024 08:41:53 -0700 From: Feng Tang To: Vlastimil Babka , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Danilo Krummrich , Narasimhan.V@amd.com Cc: linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Feng Tang Subject: [PATCH v3 0/3] mm/slub: Improve data handling of krealloc() when orig_size is enabled Date: Wed, 16 Oct 2024 23:41:49 +0800 Message-Id: <20241016154152.1376492-1-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: B1D2140011 X-Stat-Signature: n9htzzfp7ncdgbph7u5xy79btgebw7pg X-HE-Tag: 1729093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Z1YbTr0Ukp0PhWyVD9FgbG/LfautGXMeVMbqXDe2CImP3Yxzh9qZP1ouoNzEnLGm6H1WyUrTTBGqx+J6SUMm0/sCG4La03Sm5HvW4GwNQEMSyoOSXCV/2AtDWF3N3AacdJiKy+UFISn3oC35KOUvFcYyLbjV9PjENcyNUL50C5+cTPGBXm3ub2MFfSTlw1hTVoL5o2QeAoW8UvyF98mct6FUAkNVYhSwktNHfGCjZtEvPDnxQCFAo/9Loi98+0suUt9dhLgrQ== 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: Danilo Krummrich's patch [1] raised one problem about krealloc() that its caller doesn't pass the old request size, say the object is 64 bytes kmalloc one, but caller originally only requested 48 bytes. Then when krealloc() shrinks or grows in the same object, or allocate a new bigger object, it lacks this 'original size' information to do accurate data preserving or zeroing (when __GFP_ZERO is set). Thus with slub debug redzone and object tracking enabled, parts of the object after krealloc() might contain redzone data instead of zeroes, which is violating the __GFP_ZERO guarantees. Good thing is in this case, kmalloc caches do have this 'orig_size' feature, which could be used to improve the situation here. To make the 'orig_size' accurate, we adjust some kasan/slub meta data handling. Also add a slub kunit test case for krealloc(). Many thanks to syzbot and V, Narasimhan for detecting issues of the v2 patches. This is again linux-slab tree's 'for-6.13/fixes' branch [1]. https://lore.kernel.org/lkml/20240812223707.32049-1-dakr@kernel.org/ Thanks, Feng Changelog: Since v2: * Fix NULL pointer issue related to big kmalloc object which has no associated slab (V, Narasimhan, syzbot) * Fix issue related handling for kfence allocated object (syzbot, Marco Elver) * drop the 0001 and 0003 patch whch have been merged to slab tree Since v1: * Drop the patch changing generic kunit code from this patchset, and will send it separately. * Separate the krealloc moving form slab_common.c to slub.c to a new patch for better review (Danilo/Vlastimil) * Improve commit log and comments (Vlastimil/Danilo) * Rework the kunit test case to remove its dependency over slub_debug (which is incomplete in v1) (Vlastimil) * Add ack and review tag from developers. Feng Tang (3): mm/slub: Consider kfence case for get_orig_size() mm/slub: Improve redzone check and zeroing for krealloc() mm/slub, kunit: Add testcase for krealloc redzone and zeroing lib/slub_kunit.c | 42 +++++++++++++++++++++++ mm/slub.c | 87 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 105 insertions(+), 24 deletions(-)