Re: [PATCH v4] coredump: Add /proc/<pid>/coredump_pre_exit for pre-exit before dumping

From: Xin Zhao

Date: Wed Jun 24 2026 - 22:52:33 EST


On Wed, 24 Jun 2026 17:28:44 +0100 Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:

> > + if (file->f_flags & O_TMPCLOS) {
> > + file->f_flags &= ~O_TMPCLOS;
> > + goto close_fd;
> > + }
>
> *blink*
>
> How could that possibly make sense? Many descriptors
> may refer to the same file; what's more, many descriptor tables
> may contain such descriptors, so... just what is that code
> trying to do?

This is yet another serious mistake. Perhaps my test scenarios were not
complex enough, or I was overly confident in removing the logic that
cleared the O_TMPCLOS flag and performed debug printing only when the
reference count dropped to zero during that single close operation,
without conducting further tests.

In v5, I plan to avoid clearing the O_TMPCLOS flag to handle the situation
where multiple file descriptors map to a single file. Of course, there are
some cases where the lifecycle of this file may extend beyond the process
exit, but AFICT such situations either cannot last long or do not involve
memory in the case where i_nlink != 0. Therefore, keeping this flag seems
unlikely to cause any issues.

Since this flag is no longer used temporarily (it will never be cleared),
I would like to rename it to O_PRECLOS.

Thanks
Xin Zhao