Re: [PATCH v2] rust: file: handle fd table teardown in file descriptor APIs
From: Al Viro
Date: Tue Sep 29 2026 - 13:03:34 EST
On Tue, Sep 29, 2026 at 05:07:40PM +0100, Gary Guo wrote:
> The reproducer that Georgios posted on GitHub is some cleanup job being added to
> task_work, which drops FileDescriptorReservation. And since exit_task_work()
> happens after exit_files(), put_unused_fd in that cleanup observe that
> current->files is NULL.
>
> So it's not from random thread, it's from the current task. And I find that
> particular case of doing per-task cleanup not unrealistic.
FWIW, descriptor reservation ought to be tied to specific files_struct
instance; note that dup_fd() can be called when there are outstanding
reservations and the copy does *NOT* have those reserved.
What rules would you suggest for such delayed put_unused_fd() wrt e.g.
files_struct unsharing?