Re: [PATCH v2] coredump: exit_files() in coredump_wait() if MMF_DUMP_MAPPED_SHARED is not set

From: Xin Zhao

Date: Thu Jun 18 2026 - 20:45:17 EST


On Thu, 18 Jun 2026 18:19:16 +0100 Pedro Falcato <pfalcato@xxxxxxx> wrote:

> > > + if (!mm_flags_test(MMF_DUMP_MAPPED_SHARED, tsk->mm))
> > > + exit_files(tsk);
> >
> > Memory mapped files keep their own separate references to the files
> > (in struct vm_area_struct::vm_file), so there is no need to attempt to
> > work around this. Unless I'm misunderstanding what you're attempting
> > to work around.
>
> Waiit, I think I get it - you have a flock on a file, and you're scared
> that if you unlock early, some other process can lock it and modify some other
> file we have mapped? If so, that does make some sense. Please add that as
> a comment and/or into the git log, because it feels very much non-obvious
> to me.

I did forget that mmap also increases the reference count, but the case
you mentioned is one we also want to work around. I will add this
information to both the commit log and the comments as below:

Early unlocking a flock on a file allows other processes to lock and
modify the mapped data protected by the flock.

Thanks
Xin Zhao