From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F564175A5 for ; Mon, 20 Apr 2026 12:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776687433; cv=none; b=CRpB+KxOVei4skTWXKuOQDinpkpKpHT22muwXmZilELpzgAZ5srrRO1Onzax1qgjXwQ3nSyc7/jR3CFpqzraevSKHI7b0ub6eeFBbNdEPyDzLUDI1ljX2ljbtccC8FMPfpL5ZtHoaUApqFa6dBNF93YjAUv7hY1mzh1GQUpL2c4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776687433; c=relaxed/simple; bh=4VuMnrHpW+Ys9pSu9mAz1veXiKY9spgI1R+SpeNWJA0=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VwjDKtdNhgCJ/1teLGMxhLfp6JAWFpIQa55+nIaykxM8wF3JZ0tNvkEluxJuA33fahjq+WDmeQ+6A6dQtNfSrXrUYR9zw3a+wd/Z2FX2DP2aiF8v7yiEnIDfk2SNlg6xFHE1pqgFsDwaiQ+KtMx3DCYRCpGw4Hm0kh1VYxo/KKE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D8I5zClr; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D8I5zClr" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-59dcdf60427so2624950e87.3 for ; Mon, 20 Apr 2026 05:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776687430; x=1777292230; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=drkslkYKwh8bl2BohU7oUu2nJDGY7lLZqg96VgbKXeA=; b=D8I5zClrpfFMhcy4xFrJ6qq3L4Dcha9lvOuhYN5RjvqAxR7VFScLsoyF0YfL2NsfAR ORtHF5jjv/sOQMCIQhuguf/amEQPC7MgEbZOXTDwX8+yYraJong0LK5M+wfflQmiTAVG chJI/Sd6aTGhOIUZXQygD4nLaOqNNhjmn8rnOUHZ9SHfuCfrd37EkpiLXwHJ3G0PsiEY 5b7zN1YckwydtbiD3OusAzmfXrrZh8FuVUwSVScqvug5IPkc5ACkZsT2T5oiiCtjS92S ti07BOIy2qM5d/Y+hD+chlgHTh0OGiSkZEEFaI8obwtiTBHJLIsDqkGVLoONPDtGfd75 dwyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776687430; x=1777292230; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=drkslkYKwh8bl2BohU7oUu2nJDGY7lLZqg96VgbKXeA=; b=iINw0MfT9QWDr0m9UcsHdgurIKoASk/C6Mn7kQWMzQ42g44gQQ+jZxMdaec7CdfooQ 4yhlfNytCiEZFTxQHLLlebynhEROobuoNDaQ+EaESx4+vxREvIh1XIlBhgmqXuAV5X0E C/F0W0f/slzjKVegj4M1CTiy+7/i2S9UY/DWTyL8rDasUVq2LRNx5OHdZMcCHZQlyAjs uFsLqqydTNdDIxdUM2p2lRYZsa3R/vdZL5Zoohjo7HljSFsa50nCPDVQW2qj3/GmgpgF tYaniaFMsaNXyZ/oqTXXNtvj8cbqn3b0l5Y0StUgrJd2d8cMwJAM0laJGa96PeQeGqPD Oscw== X-Forwarded-Encrypted: i=1; AFNElJ8rXOqP2D/CMHH54PlmSfgoFXm2YWY40usetURdgzSWT4wu1VNEutUfwYLqsH4xS8sFSN9PZ2q4AA0aQCI=@vger.kernel.org X-Gm-Message-State: AOJu0YxwMPuGkwhexo9txSwxDpz9LL5q9HOpNjDPuVp7dMJdKJ5jM19+ mAn9h57qhujRxM/hMXF+I0HBnLLmD/VocxzenPWTGlB4H67C6zQbD7bJ X-Gm-Gg: AeBDietkqJL7+B8oMQZoZtL+FQuCpsBKwilrzfGnNkdEaxVl9h6+QG21U/FAPDWyYq7 +dOzyi04dI81BHBmGTaspgp7WPvDGYDBU4hgQkyQK+JhHJhLCkGzV+l1kE9PYbQjWw3cHPcV3Qe oGiAteu/h6x7LzJiFa4hzUzRHUcHiVX2DkEUJKVhv8NZgK3Ho7Hj3gV38Cw4iGyyim94e6W5Gu/ gUOnYXwZIj7ANI0LKPc6c9RF3cObQPePcCuWDa/3N8WFqWGYn40Zh4Hu/eB4TMm5FcuYyvbWnNI Xr1mMwHWk19qNz8P5DquherYA71+x8ob13IagH49Xhszl4OxsI45OhMrlnoZX928eXdH992xc6B yVlKn4PLNl6vXPAaLuH1mjPuMn8JehJyAw99XCRFswIp4YVXdLrCsXIr9NXnoH9HsOSXv+6DcvZ k= X-Received: by 2002:a05:6512:a8b:b0:5a2:c289:3337 with SMTP id 2adb3069b0e04-5a4172fabccmr4256296e87.42.1776687429463; Mon, 20 Apr 2026 05:17:09 -0700 (PDT) Received: from milan ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a4185ad2f4sm2965771e87.17.2026.04.20.05.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2026 05:17:09 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 20 Apr 2026 14:17:07 +0200 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, "Harry Yoo (Oracle)" 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 > --- > 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 > Agree with a problem described in commit message: Reviewed-by: Uladzislau Rezki (Sony) Thank you for fixing it! -- Uladzislau Rezki