Subject: Re: [PATCH v13 (resend) 2/6] x86/entry: Add STACKLEAK erasing the kernel stack at the end of syscalls References: <1529686717-16017-1-git-send-email-alex.popov@linux.com> <1529686717-16017-3-git-send-email-alex.popov@linux.com> From: Laura Abbott Message-ID: <3e319e96-e942-7c87-7b72-a5c3f520f234@redhat.com> Date: Fri, 22 Jun 2018 11:58:00 -0700 MIME-Version: 1.0 In-Reply-To: <1529686717-16017-3-git-send-email-alex.popov@linux.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit To: Alexander Popov , kernel-hardening@lists.openwall.com, Kees Cook , PaX Team , Brad Spengler , Ingo Molnar , Andy Lutomirski , Tycho Andersen , Mark Rutland , Ard Biesheuvel , Borislav Petkov , Richard Sandiford , Thomas Gleixner , "H . Peter Anvin" , Peter Zijlstra , "Dmitry V . Levin" , Emese Revfy , Jonathan Corbet , Andrey Ryabinin , "Kirill A . Shutemov" , Thomas Garnier , Andrew Morton , Alexei Starovoitov , Josef Bacik , Masami Hiramatsu , Nicholas Piggin , Al Viro , "David S . Miller" , Ding Tianhong , David Woodhouse , Josh Poimboeuf , Steven Rostedt , Dominik Brodowski , Juergen Gross , Linus Torvalds , Greg Kroah-Hartman , Dan Williams , Dave Hansen , Mathias Krause , Vikas Shivappa , Kyle Huey , Dmitry Safonov , Will Deacon , Arnd Bergmann , Florian Weimer , Boris Lukashev , Andrey Konovalov , x86@kernel.org, linux-kernel@vger.kernel.org List-ID: On 06/22/2018 09:58 AM, Alexander Popov wrote: > + /* > + * Now write the poison value to the kernel stack. Start from > + * 'kstack_ptr' and move up till the new 'boundary'. We assume that > + * the stack pointer doesn't change when we write poison. > + */ > + if (on_thread_stack()) > + boundary = current_stack_pointer; > + else > + boundary = current_top_of_stack(); > + > + BUG_ON(boundary - kstack_ptr >= THREAD_SIZE); > + > + while (kstack_ptr < boundary) { > + *(unsigned long *)kstack_ptr = STACKLEAK_POISON; > + kstack_ptr += sizeof(unsigned long); > + } > + > + /* Reset the 'lowest_stack' value for the next syscall */ > + current->lowest_stack = current_top_of_stack() - THREAD_SIZE / 64; on_thread_stack() and current_top_of_stack() are x86 only functions currently defined in asm/processor.h. There are similar functions in arch/arm64/include/asm/stacktrace.h which I think I can use to build those functions. Should I just throw the arm64 versions in processor.h or do we want to consider abstracting these into something like asm/stackleak.h? I'd like to know a direction before I start ripping apart stacktrace.h. Thanks, Laura