Re: [PATCH 15/20] signal/sparc32: Exit with a fatal signal when try_to_clear_window_buffer fails
From: Eric W. Biederman
Date: Thu Oct 21 2021 - 12:57:11 EST
Kees Cook <keescook@xxxxxxxxxxxx> writes:
> On Wed, Oct 20, 2021 at 12:44:01PM -0500, Eric W. Biederman wrote:
>> The function try_to_clear_window_buffer is only called from
>> rtrap_32.c. After it is called the signal pending state is retested,
>
> nit: rtrap_32.S
>
>> and signals are handled if TIF_SIGPENDING is set. This allows
>> try_to_clear_window_buffer to call force_fatal_signal and then rely on
>> the signal being delivered to kill the process, without any danger of
>> returning to userspace, or otherwise using possible corrupt state on
>> failure.
>
> The TIF_SIGPENDING test happens in do_notify_resume(), though I see
> other code before that:
>
> ...
> call try_to_clear_window_buffer
> add %sp, STACKFRAME_SZ, %o0
>
> b signal_p
> ...
> signal_p:
> andcc %g2, _TIF_DO_NOTIFY_RESUME_MASK, %g0
> bz,a ret_trap_continue
> ld [%sp + STACKFRAME_SZ + PT_PSR], %t_psr
>
> mov %g2, %o2
> mov %l6, %o1
> call do_notify_resume
>
> Will the ret_trap_continue always be skipped?
The ret_trap_continue is the break out of the loop. So unless the code
is not properly setting the signal to be pending the code should be good.
> Also I see the "tp->w_saved = 0" never happens due to the "return" in
> try_to_clear_window_buffer. Is that okay?
It should be. As you point out the w_saved value is only used in
generating signal frames. The code in get_signal should never
return and should call do_group_exit which calls do_exit, so building
signal frames that happens after get_signal returns should never be
reached.
Further this is the same way the code makes it to do_exit today.
Also looking at it I think the logic is that w_saved == 0
says that the register windows have been saved on the user mode stack,
and that clearly has not happened so I think it would in general
be a bug to clear w_saved on failure.
> Only synchronize_user_stack()
> uses it, and that could be called in do_sigreturn(). Should the "return"
> be removed?
Of course I could be wrong, if David or someone else who knows sparc32
better than me wants to set me straight I would really appreciate it.
Eric