Re: [PATCH 2/2] mm: memfd_luo: preserve file seals

Pratyush Yadav
2026-02-10T13:15:58Z

On Mon, Jan 26 2026, Mike Rapoport wrote:

> Hi Pratyush,
>
> On Mon, Jan 26, 2026 at 01:47:21PM +0100, Pratyush Yadav wrote:
>> Hi Mike,
>>
>> On Sun, Jan 25 2026, Mike Rapoport wrote:
>> > On Fri, Jan 23, 2026 at 10:58:51AM +0100, Pratyush Yadav wrote:
>
> ...
>
>> >> - file = memfd_alloc_file("", 0);
>> >> + /*
>> >> + * The seals are preserved. Allow sealing here so they can be added
>> >> + * later.
>> >> + */
>> >> + file = memfd_alloc_file("", MFD_ALLOW_SEALING);
>> >
>> > I think we should select flags passed to memfd_alloc_file() based on
>> > ser->seals (and later based on ser->seals and ser->flags).
>>
>> Not sure what you mean.
>>
>> I think the only seal we can set via memfd_alloc_file() flags is
>> MFD_NOEXEC_SEAL, which is really a F_SEAL_EXEC and plus a change of the
>> inode's mode. And now that I think of it, that is a valid use case that
>> we might as well support. But I think that should be done by preserving
>> the mode of the inode directly, and then copying the seals back. The
>> main reason for that is that the mode can be changed after the memfd is
>> created too.
>>
>> Other than that, all other seals are set by fcntl (via
>> memfd_add_seals()), so I don't see what else we can pass to
>> memfd_alloc_file().
>
> Hmm, "using ser->seals" was bad phrasing :)
>
> Now we add support for creating memfd with MFD_ALLOW_SEALING and at some
> point we'd want MFD_HUGETLB and huge page size.
> So I think we should have a field in ser that will define what flags should
> be used for creation of memfd and based on the value of that field pass the
> flags to memfd_alloc_file().

I am not planning to re-use any of memfd machinery we have now for
HugeTLB. The main reason is that the HugeTLB support is different enough
that any shared code or data structures aren't worth the extra
complexity.

So HugeTLB gets its own serialization structures and file handlers.
struct hugemfd_ser in [0] has a field for order which we can use to
decide the flags.

[0] https://lore.kernel.org/linux-mm/20251206230222.853493-11-pratyush@kernel.org/

>
> For seals support this field can be hardwired to MFD_ALLOW_SEALING at preserve
> time.
[...]

--
Regards,
Pratyush Yadav