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 6667D296BB7 for ; Thu, 9 Oct 2025 07:03:57 +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=1759993437; cv=none; b=pOa2Jmfown6ezP03C9zit4xXYu1ki4UbzqCdAj2CNPDniA1SVD+FSV8vIQHQB3vNIZBxa0ty6HWU44/iTd2R6jjHXoHfrX6LT3aq/WbB8BTzdVStSvbubcY6E5mTJ/pJqMroHiMEpbNO7YrpaZuJibEZiO1bt69eKyhGOnH4WTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759993437; c=relaxed/simple; bh=vq6Gude3pLvvZ45iIJ5I0tbxMA5VkZHO2gu4zBXFz/4=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=LsnkCFchIyKPAyXWyu5jwkFwH66nFKzwg5QUc6uEN2GDHqs1LC8D1PowSDIuo8AbUqFx87Bba0Te9eiHsnVZo/Z0EcMs1eInrqkVhAvEEKQ3pcf1FpUV1+bjfOhafIrjXWydoegcQ22lJFiD9XY6xVH8+obRSrWpbjjD2vX6a/I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=p4/Q/AZe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="p4/Q/AZe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6F42C4CEF9; Thu, 9 Oct 2025 07:03:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1759993437; bh=vq6Gude3pLvvZ45iIJ5I0tbxMA5VkZHO2gu4zBXFz/4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=p4/Q/AZeJWLhcmoXzwBCHZU9JLSuW3AKsQ74uJG+T6HaqlZarJrn8F10CR+jDPrVw pW0o00gG2arQqn4mAc7b2+YDdvsJ0zgf9PyXz03VFK2hZvQlJYqGglC/JEgJGEzYAC r0w/GN/d46xB0uaG3uI/YB/chd8An3eXhQLx3mTI= Date: Thu, 9 Oct 2025 00:03:56 -0700 From: Andrew Morton To: "Huang, Ying" Cc: Yadong Qi , urezki@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: vmalloc: WARN_ON if mapping size is not PAGE_SIZE aligned Message-Id: <20251009000356.8e18395dd9979045e0c66de2@linux-foundation.org> In-Reply-To: <87zfa0tw9o.fsf@DESKTOP-5N7EMDA> References: <20251009061410.820-1-yadong.qi@linux.alibaba.com> <87zfa0tw9o.fsf@DESKTOP-5N7EMDA> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 09 Oct 2025 14:38:27 +0800 "Huang, Ying" wrote: > Yadong Qi writes: > > > In mm/vmalloc.c, the function vmap_pte_range() assumes that the > > mapping size is aligned to PAGE_SIZE. If this assumption is > > violated, the loop will become infinite because the termination > > condition (`addr != end`) will never be met. This can lead to > > overwriting other VA ranges and/or random pages physically follow > > the page table. > > > > It's the caller's responsibility to ensure that the mapping size > > is aligned to PAGE_SIZE. However, the memory corruption is hard > > to root cause. To identify the programming error in the caller > > easier, check whether the mapping size is PAGE_SIZE aligned with > > WARN_ON(). > > > > Signed-off-by: Yadong Qi > > Reviewed-by: Huang Ying > > --- > > v1 -> v2: > > * Use WARN_ON instead of BUG_ON > > --- > > mm/vmalloc.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > index 5edd536ba9d2..2cad593e4677 100644 > > --- a/mm/vmalloc.c > > +++ b/mm/vmalloc.c > > @@ -100,6 +100,9 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, > > struct page *page; > > unsigned long size = PAGE_SIZE; > > > > + if (WARN_ON(!PAGE_ALIGNED(end - addr))) > > + return -ENOMEM; > > + > > EINVAL? > If this errno gets returned to userspace somehow, programmer is going to wonder what was invalid about the arguments which the program passed to the kernel. But either way, the callers of vmap_pte_range() should be audited, to verify that they take appropriate action when this happens.