Re: [PATCH 1/2] mm/memfd_luo: reject memfds whose page count exceeds UINT_MAX

Pratyush Yadav
2026-05-04T08:05:09Z

On Fri, May 01 2026, Pasha Tatashin wrote:

> On 05-01 20:26, David CARLIER wrote:
>> On 2026-05-01 18:59, Pasha Tatashin wrote:
>> > I think, the fix should be first done at memfd_pin_folios() to
>> change
>> > max_folios to 'long' or 'unsigned long', and then just updated
>> > memfd_luo.c to match.
>>
>> Even with memfd_pin_folios() widened, memfd_luo_preserve_folios()
>> still
>> kvmalloc_objs()s the folios array up front -- at UINT_MAX entries
>> that's
>> already ~32 GiB of pointer array, which won't realistically succeed.
>> So
>> the guard here still makes sense, just on allocation grounds rather than
>> interface truncation.
>>
>> Happy to widen memfd_pin_folios() as a separate patch, but I'd keep
>> the
>> -EFBIG check regardless. Or did you have a different shape in mind?
>
> Ah, Good point about kvmalloc_objs(), I am not against this, even though
> it is a very theoretical issue.

Yeah. I plan to get rid of the pinning anyway and do this via the page
cache directly (might be easier said than done though), so this should
be fine for now I think. I suspect we might run into a lot more problems
if we get a memfd like this anyway.

Reviewed-by: Pratyush Yadav <pratyush@kernel.org>

>
> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>

--
Regards,
Pratyush Yadav