linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: <yadong.qi@linux.alibaba.com>
To: "'Uladzislau Rezki'" <urezki@gmail.com>
Cc: <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <ying.huang@linux.alibaba.com>
Subject: RE: [PATCH v3] mm: vmalloc: WARN_ON if mapping size is not PAGE_SIZE aligned
Date: Thu, 9 Oct 2025 18:57:48 +0800	[thread overview]
Message-ID: <001401dc390b$8d074680$a715d380$@linux.alibaba.com> (raw)
In-Reply-To: <aOeEYHzXUVOpu174@milan>

> -----Original Message-----
> From: Uladzislau Rezki <urezki@gmail.com>
> Sent: 2025年10月9日 17:46
> To: Yadong Qi <yadong.qi@linux.alibaba.com>
> Cc: akpm@linux-foundation.org; urezki@gmail.com; linux-mm@kvack.org;
> linux-kernel@vger.kernel.org; ying.huang@linux.alibaba.com
> Subject: Re: [PATCH v3] mm: vmalloc: WARN_ON if mapping size is not PAGE_SIZE
> aligned
> 
> On Thu, Oct 09, 2025 at 05:37:06PM +0800, Yadong Qi wrote:
> > 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 <yadong.qi@linux.alibaba.com>
> > Reviewed-by: Huang Ying <ying.huang@linux.alibaba.com>
> > ---
> > v2 -> v3:
> >   * change error code from ENOMEM to EINVAL
> >   * modify callers of vmap_pte_range to handle return code
> > v1 -> v2:
> >   * Use WARN_ON instead of BUG_ON
> > ---
> >  mm/vmalloc.c | 29 ++++++++++++++++++-----------
> >  1 file changed, 18 insertions(+), 11 deletions(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 5edd536ba9d2..1fa52f203795 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)))
> >
> And it might be worth to use WARN_ON_ONCE() otherwise there is a risk
> that a kernel buffer would contain only such warnings.
> 

Sure, will change in next version.

Best Regard
Yadong



      reply	other threads:[~2025-10-09 10:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-09  9:37 Yadong Qi
2025-10-09  9:46 ` Uladzislau Rezki
2025-10-09 10:57   ` yadong.qi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001401dc390b$8d074680$a715d380$@linux.alibaba.com' \
    --to=yadong.qi@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=urezki@gmail.com \
    --cc=ying.huang@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox