Re: [PATCH] ptrace/x86: introduce TS_COMPAT_RESTART to fix get_nr_restart_syscall()

From: Andy Lutomirski
Date: Wed Nov 27 2019 - 00:46:29 EST


On Tue, Nov 26, 2019 at 8:04 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Nov 26, 2019 at 3:08 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > Alternatively we could add ->compat_restart into struct restart_block,
> > logically this is the same thing.
>
> That sounds like the better model to me. That's what the restart_block
> is about: it's supposed to contain the restart information.
>
> I'd much rather see the system call number added into the restart
> block (or just the "compat bit" - but we have that X32 case too, so
> why not put it all there). And then the get_nr_restart_syscall() hack
> goes away and is just "set state from the restart block".
>
> How painful would that be? I guess right now we always just set all
> the restart_block info manually in all the restart cases, and that
> could make it a bit painful to add this kind of architecture-specific
> flag, but it _sounds_ conceptually like the right thing to do.

How about we rename restart_block::fn to __fn, add fields
restart_syscall_nr and restart_syscall_arch, and do:

long restart_block_activate(long (*fn)(struct restart_block *))
{
current->restart_block.__fn = fn;
arch_restart_block_activate();
return -ERESTART_RESTARTBLOCK;
current->restart_block.syscall_nr
}

IMO the ideal solution would be to add a new syscall nr to restart a
syscall and make it the same on all architectures. This has
unfortunate interactions with seccomp, though.

--Andy