From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Schmitz Subject: Re: Kernel stack read with PTRACE_EVENT_EXIT and io_uring threads Date: Mon, 14 Jun 2021 14:05:38 +1200 Message-ID: <6e47eff8-d0a4-8390-1222-e975bfbf3a65@gmail.com> References: <87sg1p30a1.fsf@disp2133> <87pmwsytb3.fsf@disp2133> <87sg1lwhvm.fsf@disp2133> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=+U4GoEm12Mv2KWeNTFflh3iSMJxQvnIQYGnEBokeD3E=; b=bAhH8lpYP7l8LZwdKg5n4tzz+dADfCxOx1lDGRVuMMRc9dYcyt25Ixyes2Xr6G7IC9 mfqt9HfSdeD3+s0RfqxaiJtfYK6DS4SM83//4OdzNK1JLLOmJfCycZrx0BNJB6dnKIQ3 rU1NeM/syVD/5Y4VlJvwx4tJEJfBt93odbs4wxu6S9cXIP3nnpX4FO/0sUySL7C6vkJ1 OoJQcYG8axVj/JnaG/QzNKmFDKgJKtVwzz1IuijO/PepMZ6JFiyuG3blM3h+vUlvDOHm 7w7lLerUmE+wtEKzgHNOFs23F41k0r6Z2JKa3OG6nyoZPU6r41Xd5AZBkllpsWQFwfXD Ivzw== In-Reply-To: Content-Language: en-US List-ID: Content-Type: text/plain; charset="utf-8"; format="flowed" To: Linus Torvalds , "Eric W. Biederman" Cc: 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 , Daniel Jacobowitz , Kees Cook Hi Linus, On 14/06/21 10:18 am, Linus Torvalds wrote: > On Sun, Jun 13, 2021 at 2:55 PM Eric W. Biederman wrote: >> The alpha_switch_to will remove the extra registers from the stack and >> then call ret which if I understand alpha assembly correctly is >> equivalent to jumping to where $26 points. Which is >> ret_from_kernel_thread (as setup by copy_thread). >> >> Which leaves ret_from_kernel_thread and everything it calls without >> the extra context saved on the stack. > Uhhuh. Right you are, I think. It's been ages since I worked on that > code and my alpha handbook is somewhere else, but yes, when > alpha_switch_to() has context-switched to the new PCB state, it will > then pop those registers in the new context and return. > > So we do set up the right stack frame for the worker thread, but as > you point out, it then gets used up immediately when running. So by > the time the IO worker thread calls get_signal(), it's no longer > useful. > > How very annoying. > > The (obviously UNTESTED) patch might be something like the attached. > > I wouldn't be surprised if m68k has the exact same thing for the exact > same reason, but I didn't check.. m68k is indeed similar, it has:        if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {                 /* kernel thread */                 memset(frame, 0, sizeof(struct fork_frame));                 frame->regs.sr = PS_S;                 frame->sw.a3 = usp; /* function */                 frame->sw.d7 = arg;                 frame->sw.retpc = (unsigned long)ret_from_kernel_thread;                 p->thread.usp = 0;                 return 0;         } so a similar patch should be possible. Cheers,     Michael > > Linus