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

From: Linus Torvalds
Date: Wed Nov 27 2019 - 12:22:06 EST


On Wed, Nov 27, 2019 at 9:02 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> OK, lets add the new restart_block.nr_restart_syscall field, then we need
>
> void set_restart_block_fn(restart, fn)
> {
> restart->nr_restart_syscall = arch_get_nr_restart_syscall()
> restart->fn = fn;
> }

No, I'd suggest just adding an arch-specific "unsigned long" to the
restart data (and not force the naming to something like the system
call number - that's just an x86 detail), and then something like this
on x86:

void arch_set_restart_data(restart)
{
restart->arch_data = x86_get_restart_syscall();
}
#define arch_set_restart_data arch_set_restart_data

and then we'd have in generic code something like

#ifndef arch_set_restart_data
#define arch_set_restart_data(block) do { } while (0)
#endif

int set_restart_fn(fn)
{
struct restart_block *restart = &current->restart_blockl
arch_set_restart_data(restart);
restart->fn = fn;
return -ERESTART_RESTARTBLOCK;
}

or something like that, and we'd just convert the existing (there
aren't that many)

restart->fn = xyz
return -ERESTART_RESTARTBLOCK;

cases into

return set_restart_fn(fn);

and for bonus points, we probably should rename the "fn" field, but
that might be too much work.

It doesn't look *too* painful, because we just don't have all that
many restarting system calls

But the above is handwaving.

And yeah, I never understood why the compat and x32 cases should have
different system call numbers in the first place. The seccomp argument
is garbage, but probably historical stuff that we can no longer
change.

Linus