Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4198771pxj; Mon, 21 Jun 2021 16:16:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4ef1iNtol8DPT2u6hovOnlBYkxVvNbeUTnIGqI72aoGgQGxCZBAxWSvKJS2xKyp91NvLa X-Received: by 2002:a05:6402:2694:: with SMTP id w20mr948855edd.287.1624317377156; Mon, 21 Jun 2021 16:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624317377; cv=none; d=google.com; s=arc-20160816; b=dPnFUzu6RvBz6R3yECdz+ZuPNG4wjdzrGw0UJECIv4+QYVpnrn4PG0/GNR+4TcVGDf mx7scECnr6Hpzw+8Tbv5iriS/Gw8k+1MOkOx1d6PeUYYYqC5mHla9KEm2nN4L5XKSdma REcegFYG0UMKcshcHrDoVKTO4/8Ak2HfW2NZi4OgrpYutEbS/mmuBW8hxN5HAV74xcPr 4dKjktmK90ehWmufGdQhxMG+ZTnCETa8FbqeTYsvlTRG37bu78F4UdZUrrY3LLlSQZd6 usThI6rgOautZX3/K06gxxECP01rzz8YtKD7m9ixjgMGMsV1lVRl/pPCAR0Y2JRn4RxF Ilwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cSpCTvtqwlFJ06T40MsJFhKBN6aTybvqDQph3piqU3c=; b=qicx9eqe2YF+XyNyideSfTi5P0deiqvabT/P9GiBHoSJkYGqwzjBhD4e3giOyizgh2 Wyh+FH8a3inci9By6FmCdLYTYNlLhd8QKqDekMC35kresGxmAszhRkE5eQsySX92/LbZ +wQQiYvavBAhoFi9EcWFEouEf0C6vVhCp3lYRik94W5MChvg1Q3V6jq1kX3+pE6lx8Sn XoyuS0im9mMIm0ZftPxtTVw1kOUcepZFn8voxxS9uPup4gmutb7hlwug33nAUeDuQeq2 9QG73ZVH4sTBidFQpQUz+8SBcTxFMT3o/FLuAP3hTIAcBiFEdAAb+bsZq9pqUy2L+Aqn 3/aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ej8PSbPX; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b18si302922edd.11.2021.06.21.16.15.52; Mon, 21 Jun 2021 16:16:17 -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=@linux-foundation.org header.s=google header.b=ej8PSbPX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231127AbhFUXRL (ORCPT + 99 others); Mon, 21 Jun 2021 19:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbhFUXRK (ORCPT ); Mon, 21 Jun 2021 19:17:10 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51BECC061574 for ; Mon, 21 Jun 2021 16:14:54 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id p7so32699972lfg.4 for ; Mon, 21 Jun 2021 16:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cSpCTvtqwlFJ06T40MsJFhKBN6aTybvqDQph3piqU3c=; b=ej8PSbPXAb0zIPa9apzD7OWAABcayKzztY2Gl8qbjCjYcakYI2cbU1Xi2FhqAdGS23 7NquMnu4HBnT8zfyZ8CSmagToFSLIKrWjMMs8/+Ru7rfccWvgOKMc4CMWM1hXZDx2u2Y vd34mqkS+oueuqgdEbosrH2qeR1zCtN6Gblvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cSpCTvtqwlFJ06T40MsJFhKBN6aTybvqDQph3piqU3c=; b=ryk3NklGt42rPvlwS5pYmjvcv6sBXSpRwXVizUqFZSmEqEKomBHFTvCkqyV9O0X7Eg gylPx9s/syY0bIFJLmuOZAGecTOU6Gzk+JnKa6f+deQGSQ8MiC1VVCXo5JX8/Ucc475F 4n/stUsKA3g+QaPBkQTLmRBg0rvw7XSPFhsDw0vn8vGoo6Pvp4bDTlrQ9m46lB/W+ALZ nPKSCk9MuwA1XZcAsIVxps6WEcu6+OH0uYiWHcxsRcPz9S5Gol+FcxI5+G2ZSRFHTRC8 JYKXZ8Fxem6O3iG3aNpNFLeLJAg1Y1G363z+xKc3B3kn6cm/0nj40Fmt9vDO+i2d2eED er1Q== X-Gm-Message-State: AOAM530k6DJntDJtTmJs5ja6cLt9W+8/b8IEIiKQM/Ca7qaX1RpKHpM0 yx0OTYXdY8bd5LKk7oIPKjnuqZxS2nRXhQvsD+U= X-Received: by 2002:a19:ae0f:: with SMTP id f15mr473099lfc.363.1624317292605; Mon, 21 Jun 2021 16:14:52 -0700 (PDT) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com. [209.85.167.51]) by smtp.gmail.com with ESMTPSA id b11sm2010429lfi.292.2021.06.21.16.14.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Jun 2021 16:14:52 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id t17so12666231lfq.0 for ; Mon, 21 Jun 2021 16:14:52 -0700 (PDT) X-Received: by 2002:a05:6512:374b:: with SMTP id a11mr470683lfs.377.1624317291959; Mon, 21 Jun 2021 16:14:51 -0700 (PDT) MIME-Version: 1.0 References: <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> In-Reply-To: From: Linus Torvalds Date: Mon, 21 Jun 2021 16:14:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Kernel stack read with PTRACE_EVENT_EXIT and io_uring threads To: Al Viro Cc: "Eric W. Biederman" , Michael Schmitz , linux-arch , Jens Axboe , Oleg Nesterov , Linux Kernel Mailing List , Richard Henderson , Ivan Kokshaysky , Matt Turner , alpha , Geert Uytterhoeven , linux-m68k , Arnd Bergmann , Ley Foon Tan , Tejun Heo , Kees Cook , Tetsuo Handa Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 21, 2021 at 12:45 PM Al Viro wrote: > > > > Looks like sys_exit() and do_group_exit() would be the two places to > > do it (do_group_exit() would handle the signal case and > > sys_group_exit()). > > Maybe... I'm digging through that pile right now, will follow up when > I get a reasonably complete picture We might have another possible way to solve this: (a) make it the rule that everybody always saves the full (integer) register set in pt_regs (b) make m68k just always create that switch-stack for all system calls (it's really not that big, I think it's like six words or something) (c) admit that alpha is broken, but nobody really cares > In the meanwhile, do kernel/kthread.c uses look even remotely sane? > Intentional - sure, but it really looks wrong to use thread exit code > as communication channel there... I really doubt that it is even "intentional". I think it's "use some errno as a random exit code" and nobody ever really thought about it, or thought about how that doesn't really work. People are used to the error numbers, not thinking about how do_exit() doesn't take an error number, but a signal number (and an 8-bit positive error code in bits 8-15). Because no, it's not even remotely sane. I think the do_exit(-EINTR) could be do_exit(SIGINT) and it would make more sense. And the -ENOMEM might be SIGBUS, perhaps. It does look like the usermode-helper code does save the exit code with things like kernel_wait(pid, &sub_info->retval); and I see call_usermodehelper_exec() doing retval = sub_info->retval; and treating it as an error code. But I think those have never been tested with that (bogus) exit code thing from kernel_wait(), because it wouldn't have worked. It has only ever been tested with the (real) exit code things like if (pid < 0) { sub_info->retval = pid; which does actually assign a negative error code to it. So I think that kernel_wait(pid, &sub_info->retval); line is buggy, and should be something like int wstatus; kernel_wait(pid, &wstatus); sub_info->retval = WEXITSTATUS(wstatus) ? -EINVAL : 0; or something. Linus