Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5086253pxj; Tue, 22 Jun 2021 14:58:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjbzbR3n5yCHFgxaDNHLH3vz1Vwpd74/ehK4TESxyp2OX/XhKm66QG7L62RMcdBq9tQkbX X-Received: by 2002:a50:a694:: with SMTP id e20mr7926605edc.191.1624399132698; Tue, 22 Jun 2021 14:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624399132; cv=none; d=google.com; s=arc-20160816; b=hHsxqX3Z6X7/dWB19Hqiidmx4NKE7mM/I6Ni74XQztdFsXFGUAB5QEJjTREsKliRaW IFkLXJ4bPGkApZ7etldYzmNzxXYWm+Ralsx4n3GQwA+KWSctqy7nrytLqMRT5PhZs9ua PFxudUJDUFUJKDkyRdowOeqtlfYNozHoLUpfr1zMvQykWPh/a8nNj0d9Q6yFqzVENUP3 DtY8QfOsP+0enh8cFckY3N63GkyDY4w8Jm+3HO7YSgKMCc1XqtkOCpwP9iSQwLf67R5f 9wpuCYz1Fni2d0AfznycRc2X6bxt5KOjDwk0LYFTaGvXH8CV2xdrORE2L6ypt+Q6JNHL KCSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=q3sSzRhIYRc08dnfAfmCyTORkqMDLuhDq0YQcDshAkw=; b=JH0siEfPEXHgfuVVQApcoPD8NfwIetyYKsYYzq7jOmy7WJhNEYeOl4CiqHxs8Ny+E1 M8n/cc/i3cGOuRCADy/r+2x76ZNIwE8yv5Hfp1Z79HOjyzWdjGD9q3Xtht4q9Hljyukv qo4NtZgIR/43xfu6CPmysbe0KA20lPFjwxR0YhX67CyAa1tkiLVksQ5cRO15BwnbolkF 2XDgLLWa8996psN6B75xN5/XPUeczW+/t/WhaMtTOSwPX7T6xqQpadyN/sJNizERp2Fm j3MWyfaSSshX1AvhxiF2pRjvQD36ZgrXsSdImUyygL9H6BwoVU6yeWFobW2t3Fiw3JZF Bscg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="b7F/isKg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 28si14335486ejk.601.2021.06.22.14.58.30; Tue, 22 Jun 2021 14:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="b7F/isKg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbhFVV7v (ORCPT + 99 others); Tue, 22 Jun 2021 17:59:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbhFVV7v (ORCPT ); Tue, 22 Jun 2021 17:59:51 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93FD3C061756; Tue, 22 Jun 2021 14:57:33 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id c7-20020a17090ad907b029016faeeab0ccso2542627pjv.4; Tue, 22 Jun 2021 14:57:33 -0700 (PDT) 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=q3sSzRhIYRc08dnfAfmCyTORkqMDLuhDq0YQcDshAkw=; b=b7F/isKgmlnCGn7ktKvQiwQaGkX//vxpblPW5Aj3zNKiPyoIi7L6xPA0H+VD3mmaV2 KK3ZmsT5Kx0XYBSi6rAJB6yf4y+ypdpaF4k8xNGxuXiRoWYyzkzKrFOsZB2bTfuWyz1V pIZ6u6YjIWAFEzdxEpXck55WHYWnXfeO9tM4jXryNbRGP8x9lTwwMV7z1J5rYgQIb11J bwCo2XoKzw1Byt5bpTGrEVmHlrjyhQd9lRLB1mkL3qgJ/mZ4MLBh6HcydQ5giJyPyUg0 o3lLcUur7tND7+LxDLyXT5AbbRNWGXXKNCuI54z4x98prRHyaHRJSFwZZyGaonB77FJq fE8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=q3sSzRhIYRc08dnfAfmCyTORkqMDLuhDq0YQcDshAkw=; b=WP/CrrTo8XaACEBNUMQrZpjOUT61SUPd4t3q/Y6YkCCnPikoO+qGLxIpC8G8kW7JFM yeh4fU8hZ+KxGcZCi632kJtytUH/LhgbRWgyyN/Kb1CeBk3L//9IUfBnFd6f9eA+Yubk /f+zXz6xsR0wgARthk6cB23F7ZVbAG4o4qLwlcH94f8Xj8VaNZ5D9R+F8hQ7IdqLS3ft hoAfO4/I5ZsQLEe4o1K0rqCMoNK6MmkcCe9Dw/5NPRyB/umV0oPtKdDAA62Z9rjcN9wV 0R1UNKEm/fma1WeNBDCzxP/mTngh7WHnsax5Nd7D4Lw1QMNiAFbtNlgRC+GD1ebEouik dqoQ== X-Gm-Message-State: AOAM531iePzEY5IT25Vv7IGiAd2UbSwWGjp+u4IOfUSh79Qs/RS2qGTa wSNIjhQHkpfuKsE5EceWOiM= X-Received: by 2002:a17:90b:3581:: with SMTP id mm1mr5936783pjb.98.1624399053199; Tue, 22 Jun 2021 14:57:33 -0700 (PDT) Received: from ?IPv6:2001:df0:0:200c:9491:40e4:164d:6ab3? ([2001:df0:0:200c:9491:40e4:164d:6ab3]) by smtp.gmail.com with ESMTPSA id z9sm270622pfa.2.2021.06.22.14.57.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 14:57:32 -0700 (PDT) Subject: Re: Kernel stack read with PTRACE_EVENT_EXIT and io_uring threads To: Al Viro Cc: Linus Torvalds , "Eric W. Biederman" , linux-arch , Jens Axboe , Oleg Nesterov , Linux Kernel Mailing List , Richard Henderson , Ivan Kokshaysky , Matt Turner , alpha , Geert Uytterhoeven , linux-m68k , Arnd Bergmann , Tejun Heo , Kees Cook , Tetsuo Handa , Andreas Schwab References: <87eed4v2dc.fsf@disp2133> <5929e116-fa61-b211-342a-c706dcb834ca@gmail.com> <87fsxjorgs.fsf@disp2133> From: Michael Schmitz Message-ID: <8badff67-64c9-ca03-7af1-de73d0d75285@gmail.com> Date: Wed, 23 Jun 2021 09:57:23 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Al, On 23/06/21 8:18 am, Al Viro wrote: > On Wed, Jun 23, 2021 at 08:04:11AM +1200, Michael Schmitz wrote: > >> All syscalls that _do_ save the switch stack are currently called through >> wrappers which pull the syscall arguments out of the saved pt_regs on the >> stack (pushing the switch stack after the SAVE_ALL saved stuff buries the >> syscall arguments on the stack, see comment about m68k_clone(). We'd have to >> push the switch stack _first_ when entering system_call to leave the syscall >> arguments in place, but that will require further changes to the syscall >> exit path (currently shared with the interrupt exit path). Not to mention >> the register offset calculations in arch/m68k/kernel/ptrace.c, and perhaps a >> few other dependencies that don't come to mind immediately. >> >> We have both pt_regs and switch_stack in uapi/asm/ptrace.h, but the ordering >> of the two is only mentioned in a comment. Can we reorder them on the stack, >> as long as we don't change the struct definitions proper? >> >> This will take a little more time to work out and test - certainly not >> before the weekend. I'll send a corrected version of my debug patch before >> that. > This is insane, *especially* on m68k where you have the mess with different > frame layouts and associated ->stkadj crap (see mangle_kernel_stack() for > the (very) full barfbag). Indeed - that's one of the uses of pt_regs and switch_stack that I hadn't yet seen. So it's either leave the stack layout in system calls unchanged (aside from the ones that need the extra registers) and protect against accidental misuse of registers that weren't saved, with the overhead of playing with thread_info->status bits, or tackle the mess of redoing the stack layout to save all registers, always (did I already mention that I'd need a _lot_ of help from someone more conversant with m68k assembly coding for that option?). Which one of these two barf bags is the fuller one? Cheers,     Michael