Re: [PATCH v4 08/19] liveupdate: Let file handlers retrieve into an existing file
From: Pratyush Yadav
Date: Fri Nov 20 2026 - 06:36:16 EST
On Fri, Nov 20 2026, Christian Brauner wrote:
> On Wed, Nov 11, 2026 at 12:23:46AM +0000, David Matlack wrote:
>> A file that is restored into an existing file is already open in the
>> caller, so installing a new file descriptor for it would just leave
>> userspace with two file descriptors for the same open file. Retrieving
>> the token again later still returns a new file descriptor, like for any
>> other file that was already retrieved.
>
> Thanks, this looks way better.
>
> One thing: Please just install a new fd like for every other retrieve.
> I think it's pretty meaningless to return the fd number the userspace
> just passed to the ioctl.
>
> The fd number is also not useful as it's not tied to anything. The shmem
> handler looks the fd up once and LUO keeps a reference to the struct
> file:
>
> CLASS(fd, target)(arg->fd);
> [...]
> args->file = get_file(file);
> args->fd = arg->fd;
>
> Which means, another thread can close() that fd or dup2() something else
> over it before the ioctl returns and the fd you hand back refers to a
> different file fucking over the caller (shared fdtable etc pp).
>
> That also gets rid of @fd in struct liveupdate_file_op_args and the
> special case in luo_session_retrieve_fd(). And a retrieve into an
> existing file then behaves exactly like retrieving the token again.
I suggested this approach because I found it odd to return a FD that
userspace already asked us to retrieve into. Any sane userspace would
just end up closing one of the two. I didn't think of this race though.
I reckon we could return -1 in the FD that LUO returns, and let
userspace use the FD it already has to work around this. If userspace
wants to close the FD in the meantime, that's their problem. They don't
get the file they asked for.
While I like this more, it's not a super strong preference. So if you
still insist on having a new FD, that's fine too I suppose.
--
Regards,
Pratyush Yadav