From mboxrd@z Thu Jan 1 00:00:00 1970 From: ebiederm@xmission.com (Eric W. Biederman) Subject: Re: [PATCH 1/2] alpha/ptrace: Record and handle the absence of switch_stack Date: Wed, 16 Jun 2021 15:57:19 -0500 Message-ID: <878s398r4g.fsf@disp2133> References: <87sg1p30a1.fsf@disp2133> <87pmwsytb3.fsf@disp2133> <87sg1lwhvm.fsf@disp2133> <6e47eff8-d0a4-8390-1222-e975bfbf3a65@gmail.com> <924ec53c-2fd9-2e1c-bbb1-3fda49809be4@gmail.com> <87eed4v2dc.fsf@disp2133> <5929e116-fa61-b211-342a-c706dcb834ca@gmail.com> <87fsxjorgs.fsf@disp2133> <87zgvqor7d.fsf_-_@disp2133> <87mtrpg47k.fsf@disp2133> <87pmwlek8d.fsf_-_@disp2133> <87k0mtek4n.fsf_-_@disp2133> Mime-Version: 1.0 Return-path: In-Reply-To: (Linus Torvalds's message of "Wed, 16 Jun 2021 13:37:29 -0700") List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Linus Torvalds Cc: Michael Schmitz , linux-arch , Jens Axboe , Oleg Nesterov , Al Viro , Linux Kernel Mailing List , Richard Henderson , Ivan Kokshaysky , Matt Turner , alpha , Geert Uytterhoeven , linux-m68k , Arnd Bergmann , Ley Foon Tan , Tejun Heo , Kees Cook Linus Torvalds writes: > On Wed, Jun 16, 2021 at 1:00 PM Linus Torvalds > wrote: >> >> And even for debugging, I think it would be both easier and cheaper to >> just add a magic word to the entry stack instead. > > IOW, just add a > > unsigned long magic; > > to "struct switch_stack", and then make the stack switch code push that value. > > That would be cheap enough to be just unconditional, but you could > make it depend on a debug config option too, of course. > > It helps if 'xyz' is some constant that is easyish to generate. It > might not be a constant - maybe it could be the address of that > 'magic' field itself, so you'd just generate it with > > stq $r,($r) > > and it would be equally easy to just validate at lookup for that WARN_ON_ONCE(): > > WARN_ON_ONCE(switch_stack->magic != (unsigned long)&switch_stack->magic); > > or whatever. > > It's for debugging, not security. So it doesn't have to be some kind > of super-great magic number, just something easy to generate and check > (that isn't a common value like "0" that trivially exist on the stack > anyway). Fair enough. I was thinking for a moment that do_sigreturn might have a problem with that but restore_sigcontext makes it clear that struct switch_stack is not exposed to userspace. Do you know if struct switch_stack or pt_regs is ever exposeed to usespace? They are both defined in arch/alpha/include/uapi/asm/ptrace.h which makes me think userspace must see those definitions somewhere. Eric