Re: [PATCH 4.19 41/48] x86/unwind/orc: Prevent unwinding before ORC initialization

Josh Poimboeuf
2020-05-14T20:28:54Z

On Thu, May 14, 2020 at 10:13:40PM +0200, Pavel Machek wrote:
> > > > @@ -563,6 +560,9 @@ EXPORT_SYMBOL_GPL(unwind_next_frame);
> > > > void __unwind_start(struct unwind_state *state, struct task_struct *task,
> > > > struct pt_regs *regs, unsigned long *first_frame)
> > > > {
> > > > + if (!orc_init)
> > > > + goto done;
> > > > +
> > > > memset(state, 0, sizeof(*state));
> > > > state->task = task;
> > > >
> > >
> > > As this returns the *state to the caller, should the "goto done" move
> > > below the memset? Otherwise we are returning partialy-initialized
> > > struct, which is ... weird.
> >
> > Yeah, it is a little weird. In most cases it should be fine, but there
> > is an edge case where if there's a corrupt ORC table and this returns
> > early, 'arch_stack_walk_reliable() -> unwind_error()' could check an
> > uninitialized value.
> >
> > Also the __unwind_start() error handling needs to set that error bit
> > anyway, in its error cases. I'll fix it up.
>
> I did this in the mean time. It moves goto around memset, and I
> believe that 8 in get_reg should have been sizeof(long) [not that it
> matters, x86-32 is protected by build bug on.]
>
> Signed-off-by: Pavel Machek <pavel@ucw.cz>

I already have the same memset patch (along with other error-handling
fixes) which I'll be posting shortly once it runs through my testing.

Since the sizeof(long) thing isn't really a bug, I'll make that change
later, along with some other pending improvements I have.

--
Josh