From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 53B4B399019; Mon, 20 Apr 2026 13:04:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776690243; cv=none; b=d0ChDkqQL6WSyRRSebFzlQDPsL8Ia54XoNAltW2NeQMWRDxRa9nTd4bLY4j04PRqjHD3Q/4v3zkCI7dHCaXv7Bu1fyNr9CX5ein2dQJHSpD5fCAAIho9sHlA65yTG+efhhWqYXd7k3dyZ+1PtwGP1AL9GSATP55MUZev/2+uFUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776690243; c=relaxed/simple; bh=6l/uKiHJ2TRLu8+eUqPvROgTVTLN+Kie5LYERHfBn3Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rTcHcbR5MDlZXJVjsRNZXi3RrbXFgLf49QdRjcCMDZkangk04FeLYBDJRSOsQOTlr51IQc9tmY4t684pHBRirMuhYw6zCwGzRtf7obRpC1Htx3iFfpjA1QTVzWB/y9t1KLzboeqqQeiNf2X9RgXW42OHggce747muulUqJvvydg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TENHAvJl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TENHAvJl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B68B2C19425; Mon, 20 Apr 2026 13:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776690243; bh=6l/uKiHJ2TRLu8+eUqPvROgTVTLN+Kie5LYERHfBn3Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TENHAvJlSR5HWZdXlH+qS8mibevUTztLgJ316ztE2xRMjxHu53WL+v7VEYffTzC2F 7jVF51Gb+oxB2RKPT+juxNZ7OXlqp1psb8A9VE1XB+NmSUf1B7ZWRymG2B29NXkEtd jBt94Z4aRfDUu3pGSbNrZ3ei6HYUxqHv/U4H2Xx7LKuXKfxbogdOAjX11YaYGKikhg QmE5bRgUgkqsYONQ/aqy6nt8kKHCYeptNSopGUZkrAl96+WPQgp77Qq8SBUdETKhBS 91pZ9YlSpIblGFnw+sorFkeZsffdpqTI+vD9Kvhfjbppm50N1JIxaxJEgcKAtDf0LZ Boj/1q6sqtuRw== Date: Mon, 20 Apr 2026 22:04:01 +0900 From: "Harry Yoo (Oracle)" To: Marco Elver Cc: Vlastimil Babka , Andrew Morton , Uladzislau Rezki , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Vitaly Wool , stable@vger.kernel.org Subject: Re: [PATCH] vmalloc: fix buffer overflow in vrealloc_node_align() Message-ID: References: <20260420114805.3572606-2-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260420114805.3572606-2-elver@google.com> On Mon, Apr 20, 2026 at 01:47:26PM +0200, Marco Elver wrote: > Commit 4c5d3365882d ("mm/vmalloc: allow to set node and align in > vrealloc") added the ability to force a new allocation if the current > pointer is on the wrong NUMA node, or if an alignment constraint is not > met, even if the user is shrinking the allocation. > > On this path (need_realloc), the code allocates a new object of 'size' > bytes and then memcpy()s 'old_size' bytes into it. If the request is to > shrink the object (size < old_size), this results in an out-of-bounds > write on the new buffer. > > Fix this by bounding the copy length by the new allocation size. > > Fixes: 4c5d3365882d ("mm/vmalloc: allow to set node and align in vrealloc") > Cc: > Reported-by: Harry Yoo (Oracle) > Signed-off-by: Marco Elver > --- Looks good to me, Reviewed-by: Harry Yoo (Oracle) Thanks a lot for fixing it! > mm/vmalloc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 61caa55a4402..8b1124158f54 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -4361,7 +4361,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align > return NULL; > > if (p) { > - memcpy(n, p, old_size); > + memcpy(n, p, min(size, old_size)); > vfree(p); > } > > -- > 2.54.0.rc1.513.gad8abe7a5a-goog -- Cheers, Harry / Hyeonggon