From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796228760; b=00YpbQsb5jBpKFqVohjdCVUyGqnvlFG5szVK1BJgpGZiaohD/qqr7bEW+IHCYrhEeloV 3smWYNFWOsynbBKYhd5bwKOU/Ky2q8UwHvKVtOMy/7Rrr7b9YChFIVzAmbGFeZR5ioUTJ uBd+LfqGw0qotLv527pA13kzL3Re5G06giu2/ru+BYcw6YcXkHt7DDcomKLtivx+e6Rxg D94Ec7GrT6huJVvlX1pgJ93aXOzomqi7gbloOmETqwfH0Z1xOAZydKA8De+pCKYp1JPyF F4wwRxSZAuWccBrJVN1cmnW1H6CnUqreAKvkVgWhQtp2RAfEqNXBFQXxQ3p1r5aA0Fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796228760; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=VjKVi0q0TlWEaK7ZVj+IuY0d7uOPJMWl1MzOLXQYKcE=; b=K2T+3RpUPoE+olrjl5SsaAP6XsEKiKmcc9E7aIlODlJwe4ZL2IEIm79Ofl31pOgfHfQ5 XlWDCBI701dfUMEkyla65zvKL50sdrMnqCceqRxCh9yAVe/O+2OL4cl6HiQ/CjWSSCMct ePXJK92UjSdX3U8H94e0r6pDJJQcclFvIdEeuhivFTtdN9ZN3FZf+g+QI3zPHNI96y1Bm pk7n1sPJUSwkWaeg9X05NTwD6oZiQf9KVtpnr+2hF4Z6NCyrxmrhlzeAv9SlgdFfDxr7l h4oEwVpOSUIHPhDyfq+Effu5hDQJZFJ2E2X3DDmjB9rtuG9WtuLb+1TbUNS7QGWlySg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R+GyouOi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1827606A322 for ; Wed, 2 Dec 2026 16:25:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R+GyouOi Received: by smtp.kernel.org (Postfix) with ESMTPSA id 151CA1F0089C; Wed, 2 Dec 2026 16:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796228759; bh=VjKVi0q0TlWEaK7ZVj+IuY0d7uOPJMWl1MzOLXQYKcE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=R+GyouOiAxdHlrTeTKKxQ/h2p+eokSHjRs2sBftynXFOY6gitCgCJNvTiYRrn56zm K71nRLOe/f+Bxo83oxN92gEkGO+qF2pWt7KrppxAr8aQN0b5Kj8S5sI3TjTQ+7YolL ccJbX9W9ASHu1cAZO7+TEU1HH7zOum5L0Ju5QGiDDOoRXIShH1sOJkbw5aFf7HUhPa UluBDH0AWUdvZ7W3hAznkjqX+qqjj025Z12eUkWPfedPMtA846BNlCno9rRV4RrI2f LkP/fiEdK5y1PxbBYuHeLvSw5RGEPIG8ZlLUWRIcALvPG2E1FLtlTaEkkCMGLAW1hv TcBcKvMG94J5A== Date: Wed, 2 Dec 2026 16:25:57 +0000 From: Harry Yoo To: Sang-Heon Jeon Cc: Vlastimil Babka , Andrew Morton , Christoph Lameter , Danilo Krummrich , David Rientjes , Hao Li , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Roman Gushchin Subject: Re: [PATCH 3/3] mm/slub: copy only the requested size in kvrealloc() Message-ID: References: <20261201165256.1286791-1-ekffu200098@gmail.com> <20261201165256.1286791-4-ekffu200098@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Dec 03, 2026 at 01:04:56AM +0900, Sang-Heon Jeon wrote: > 2026년 12월 2일 (수) 오후 11:51, Harry Yoo 님이 작성: > > > diff --git a/mm/slub.c b/mm/slub.c > > > index 8e6e900fc39b..9742c2825a06 100644 > > > --- a/mm/slub.c > > > +++ b/mm/slub.c > > > @@ -7272,10 +7272,18 @@ void *kvrealloc_node_align_noprof(const void *p, DECL_TOKEN_PARAMS(size, token), > > > if (!n) > > > return NULL; > > > > > > - if (p) { > > > + if (!ZERO_OR_NULL_PTR(p)) { > > > + struct slab *slab = virt_to_slab(p); > > > + size_t old_size; > > > + > > > + if (!slab) > > > + old_size = ksize(p); > > > + else > > > + old_size = get_orig_size(slab->slab_cache, (void *)p); > > > + > > > /* We already know that `p` is not a vmalloc address. */ > > > kasan_disable_current(); > > > - memcpy(n, kasan_reset_tag(p), min(size, ksize(p))); > > > + memcpy(n, kasan_reset_tag(p), min(size, old_size)); > > > > Do we really need this when kvrealloc() frees a slab object and > > allocates a vmalloc object(), why? > > The case that i identified is below, SLAB_STORE_USER enabled: > > 1. process A allocates with kzalloc(80). write something to it and free. > 2. process B allocates with kzalloc(70). get the same object from A > allocated. still 70-80 bytes have data from process A > 3. process B calls kvrealloc() with __GFP_ZERO and allocates a vmalloc object. > 4. then copy ksize(p) = 96 bytes which might include non-zero and did > not originate from B. Oh, I see. I overlooked that. > So, if you feel the existing logic is not harmful to production, I'm > okay with that too. In that case, feel free to drop this patch. A bug is a bug, it should be fixed anyway... 1. Could you please try to extract this to a helper and deduplicate this? __do_krealloc() has the same logic and this patch doesn't handle kfence objects. 2. Please make sure that this issue could be reproduced before this patch and this patch resolves the issue. Thanks! -- Cheers, Harry / Hyeonggon