mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shubhang <sh@gentwo.org>
To: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Uladzislau Rezki <urezki@gmail.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	 Shubhang Kaushik <shubhang@os.amperecomputing.com>,
	 "Christoph Lameter (Ampere)" <cl@gentwo.org>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/vmalloc: reject overflowing vm_map_ram page counts
Date: Fri, 23 Oct 2026 10:02:32 -0700 (PDT)	[thread overview]
Message-ID: <a8931158-460a-9ec0-28d2-44f3a4956153@gentwo.org> (raw)
In-Reply-To: <y5yuwnmvq5nouoitqj6lloz6hepha6cf6vmh42rer2zhgv32au@vbvr3ohn24tf>

Hi Anshuman,

On Fri, 23 Oct 2026, Anshuman Khandual wrote:

>>
>> +	if (count > ULONG_MAX >> PAGE_SHIFT)
>> +		return NULL;
>
> Could vm_map_ram() ever be called with such a large number as count ?
>

Yes. I checked the direct callers while respinning this.

udmabuf can build such a count from userspace-provided, page-aligned
ranges. It stores the accumulated count in ubuf->pagecount, and its
DMA-BUF vmap callback passes that value directly to vm_map_ram():

 	vaddr = vm_map_ram(ubuf->pages, ubuf->pagecount, -1);

On a 32-bit PAE kernel, the default udmabuf size limit permits a count
in the overflowing range, subject to sufficient backing memory and
successful pinning. For example, 1048577 pages with 4 KiB pages is a
4 GiB + 4 KiB udmabuf request.

There is also an in-tree import route which invokes this callback.
DRM drivers using DRM_GEM_DMA_DRIVER_OPS_VMAP call dma_buf_vmap() while 
importing DMA-BUF through PRIME, which reaches udmabuf's vmap operation.

The same overflowing conversion makes udmabuf advertise a one-page DMA-BUF 
size and build an SG table with a one-page byte length. Therefore, this 
establishes that vm_map_ram() can receive a userspace-derived overflowing 
count. However, I have not found a current in-tree importer that then 
accesses the returned mapping as if it covered all 1048577 pages.

The v2 using check_mul_overflow() is here:

https://lore.kernel.org/lkml/20261022-vmalloc-reject-overflow-v2-1-0db7a20c53f0@gentwo.org/

Regards,
Shubhang Kaushik

      reply	other threads:[~2026-10-23 17:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 23:35 Shubhang Kaushik (Ampere)
2026-10-23  3:19 ` Andrew Morton
2026-10-23  6:12   ` Shubhang
2026-10-23  6:54 ` Dev Jain
2026-10-23  7:37   ` Shubhang
2026-10-23 11:22 ` Anshuman Khandual
2026-10-23 17:02   ` Shubhang [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=a8931158-460a-9ec0-28d2-44f3a4956153@gentwo.org \
    --to=sh@gentwo.org \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=cl@gentwo.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@gmail.com \
    --cc=shubhang@os.amperecomputing.com \
    --cc=urezki@gmail.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

all inboxes | Powered by JetHome®