Re: [PATCH RFC POC 00/50] file: handle files on syscall exit

From: David Laight

Date: Wed Sep 16 2026 - 05:53:49 EST


On Tue, 15 Sep 2026 12:08:57 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Tue, 15 Sept 2026 at 10:52, Jann Horn <jannh@xxxxxxxxxx> wrote:
> >
> > Is this mainly about stuff like "we installed a file descriptor and
> > then the following put_user() failed"? Because if so, I think a nicer
> > fix would be to have a policy of "if userspace provides unwritable
> > memory to a syscall, just keep going and pretend the access worked",
> > and maybe have a sysctl that kills the process when this happens to
> > emphasize that userspace should not be doing this.
>
> We've done that before, where we just ignore put_user() errors and the
> user gets whatever the user gets.
>
> It is maybe not optimal, but it's fine. You can find quite a lot of
> unchecked put_user() calls with a pattern like
>
> git grep '^[[:space:]]*put_user(.*);'
>
> and some of them are in core code - see the two in kernel/fork.c, for example.
>
> One of them says "if userspace has not set up a proper pointer then
> tough luck". The other one doesn't even bother with a comment.

I think the code should try to return EFAULT (IIRC that is too hard
in one of the exec cases).
Otherwise very unexpected things might happen if the memory is just
readonly.
If you ignore the error and the pointer is invalid the application will
get a SIGSEGV and (usually) die.
But winding back kernel data because a user copy failed is likely to
be problematic/difficult and at best have error path code that isn't
really tested.

As well as writing fd numbers to userspace, some sockopt code tries to
wind back if the write to optlen fails (which has been read earlier).

I've forgotten which Unix converted EFAULT to SIGSEGV in the system
call exit code - I'm sure one of the ones I've used did.

David

>
> The scheduler has two cases too, although one of them is admittedly
> for another error case.
>
> So yes, saying "if you pass bogus arguments, you get what you get" is
> a valid model. It's perhaps not the *preferred* model, but it's not
> wrong.
>
> It *would* be wrong to take code that already has error handling and
> remove the error handling, though.
>
> Linus
>