Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4778687pxb; Sat, 12 Feb 2022 19:00:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx60KlNNHNBfV8MIiagozNrR7viDuZz3WAE3cXrRJ95sbbu5mVrUOkFcrNBFtg7WKseb0yU X-Received: by 2002:a17:907:8a16:: with SMTP id sc22mr364619ejc.755.1644721230848; Sat, 12 Feb 2022 19:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644721230; cv=none; d=google.com; s=arc-20160816; b=mJnlzE1LX83c82vfK//WDoQFqiGsHF4GrBXormodW/o9Yl3+jFFXKrrM8UM0r2VsoQ 7tGgNwpn9mhTc4hOg+sD3TquYlHHf5LVHCu7oCMKK8T5qi7ymnNVzciXGhNuRrr/6AQ8 aXUTHejfWQKf4JaFvAA2xYdMgw5cLFxD1IZ8gnXFIIFFm4K9X8yO6ssn6o72mCsn9IzN PMu1eIgyP9ri/+uSplWZ0n2uyVI8PZPdBfSSGdULgUA9UybSaSBa+DomfjX0tSiS0Go/ IDzfWEEzaalVPqwyUbSiaIU9A68ZKfQSJmMOUVURwzv/Mtc8x3SZbjwq4+wq0wlrOIq2 aWKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=akw+F2hkLlIx1zx4pGqLno/WqoCLfLF+9C33bhKHXXA=; b=aqY2AvcBFaVFoZA2PAtqKQr0h+DPrGQTa0h8UM0pdHJKxLtWOh2CbeUwUukHyUWG/s laJe+dKNAalqutANpCTwtPjZoNT3Nvfjtx5mgmWqheN0OjRAtw4aoz8iY9WiNait1dAI JAR61sk5L2rC4iV8qOQ6O0JGZQGBexoOGBZyoP6rQnqu/wx1MSbHMDUGC6CrY56BO7i3 ehBxTdE+RkDXEGyRxnF9vVIhfHTusJV0UM5BzvRtTiefsAUFdIpYbAe4AWtBbbdqGY8V k3qkr3bKIDdrfe0lF8xb8nUO9oa96DIJUIOezeBk12YTFJhAn4kEZjU+nklsNliBNQYy 2Wzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HUU6SdkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho14si8896736ejc.687.2022.02.12.19.00.08; Sat, 12 Feb 2022 19:00:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HUU6SdkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348878AbiBKUPm (ORCPT + 93 others); Fri, 11 Feb 2022 15:15:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229967AbiBKUPi (ORCPT ); Fri, 11 Feb 2022 15:15:38 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369E4CF5 for ; Fri, 11 Feb 2022 12:15:36 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id i34so18742594lfv.2 for ; Fri, 11 Feb 2022 12:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=akw+F2hkLlIx1zx4pGqLno/WqoCLfLF+9C33bhKHXXA=; b=HUU6SdkM6LBsvdup/PD0lWZgy6/ryJ47CutLjO78bSfQjk58z09KwVzWhty+y5iViA vfi9/F4l8vCsLg7iCMNjFKjOgZacD9q+CuVyF+U/WnInP0soTdRar79I8dc/Duc7d4Aw tHCRHyNSm7bRx9v6yPM5H5DtDMBHBB5CbS3c2HcG07IPaIq5T8Nwl1w170zcS/b8eQsB RBuH+ilHUprX4knao6DxzesRQHN2VGIL4o23zshaUr2pYhZPpfjsfmbsGdToAFXLz2Tm 20lHlnz/Ld2GMxxmqhpf3cNmTLKsXyUp/DMuHQJNB6TLfmFqI2WRaXkJJq9AOWH00GnA nECg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=akw+F2hkLlIx1zx4pGqLno/WqoCLfLF+9C33bhKHXXA=; b=wvBPQoo9DM3jxASwF7AsWQl7YfZF3MdwrJQ5AiuJrwMsKgCwFdmy83oC0TicbQug3F eJyCdiQkTCFyj48jACYQHjBRigdXy7bqFjehUAOfcYlEfXqWv7TAM+rOl9VVKjpduJov fh3TeEFfCMNuU3zWem879E4RDpEv+bZibvPti5sE8RorVIh5Y+cGFucnt73LRfka1oJ2 UZXGLcmuiSccQ9L3qELnc4VYMGRe+jpZBaYz8kODPZTahbxQFY6Eru9WM17wkqJR+ErK /WRZQV/gzoIwSU1ED5smSrMYCDHjYM0p+RhzS3Au4boPv9rjl0oJCIWEAY9RW/jlBIiG h/GA== X-Gm-Message-State: AOAM530/yruxiRM0SDQ/2iMnwzkQnFBwvi3F8TUBtnunYdHrLOIn/GrB aJ1ahg6LWIYgxdDFrVv6qRGWUnevXr8tlfLXvt1Dew== X-Received: by 2002:a19:ee13:: with SMTP id g19mr2315780lfb.288.1644610534329; Fri, 11 Feb 2022 12:15:34 -0800 (PST) MIME-Version: 1.0 References: <20220210025321.787113-1-keescook@chromium.org> <20220210025321.787113-2-keescook@chromium.org> <202202100935.FB3E60FA5@keescook> <202202101254.1174AB2B@keescook> In-Reply-To: <202202101254.1174AB2B@keescook> From: Jann Horn Date: Fri, 11 Feb 2022 21:15:07 +0100 Message-ID: Subject: Re: [PATCH 1/3] signal: HANDLER_EXIT should clear SIGNAL_UNKILLABLE To: Kees Cook Cc: "Eric W. Biederman" , =?UTF-8?B?Um9iZXJ0IMWad2nEmWNraQ==?= , stable@vger.kernel.org, Andy Lutomirski , Will Drewry , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Oleg Nesterov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 10, 2022 at 10:09 PM Kees Cook wrote: > On Thu, Feb 10, 2022 at 07:01:39PM +0100, Jann Horn wrote: > > On Thu, Feb 10, 2022 at 6:37 PM Kees Cook wrote= : > > > On Thu, Feb 10, 2022 at 05:18:39PM +0100, Jann Horn wrote: > > > > On Thu, Feb 10, 2022 at 3:53 AM Kees Cook w= rote: > > > > > Fatal SIGSYS signals were not being delivered to pid namespace in= it > > > > > processes. Make sure the SIGNAL_UNKILLABLE doesn't get set for th= ese > > > > > cases. > > > > > > > > > > Reported-by: Robert =C5=9Awi=C4=99cki > > > > > Suggested-by: "Eric W. Biederman" > > > > > Fixes: 00b06da29cf9 ("signal: Add SA_IMMUTABLE to ensure forced s= iganls do not get changed") > > > > > Cc: stable@vger.kernel.org > > > > > Signed-off-by: Kees Cook > > > > > --- > > > > > kernel/signal.c | 5 +++-- > > > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/kernel/signal.c b/kernel/signal.c > > > > > index 38602738866e..33e3ee4f3383 100644 > > > > > --- a/kernel/signal.c > > > > > +++ b/kernel/signal.c > > > > > @@ -1342,9 +1342,10 @@ force_sig_info_to_task(struct kernel_sigin= fo *info, struct task_struct *t, > > > > > } > > > > > /* > > > > > * Don't clear SIGNAL_UNKILLABLE for traced tasks, users = won't expect > > > > > - * debugging to leave init killable. > > > > > + * debugging to leave init killable, unless it is intende= d to exit. > > > > > */ > > > > > - if (action->sa.sa_handler =3D=3D SIG_DFL && !t->ptrace) > > > > > + if (action->sa.sa_handler =3D=3D SIG_DFL && > > > > > + (!t->ptrace || (handler =3D=3D HANDLER_EXIT))) > > > > > t->signal->flags &=3D ~SIGNAL_UNKILLABLE; > > > > > > > > You're changing the subclause: > > > > > > > > !t->ptrace > > > > > > > > to: > > > > > > > > (!t->ptrace || (handler =3D=3D HANDLER_EXIT)) > > > > > > > > which means that the change only affects cases where the process ha= s a > > > > ptracer, right? That's not the scenario the commit message is talki= ng > > > > about... > > > > > > Sorry, yes, I was not as accurate as I should have been in the commit > > > log. I have changed it to: > > > > > > Fatal SIGSYS signals (i.e. seccomp RET_KILL_* syscall filter actions) > > > were not being delivered to ptraced pid namespace init processes. Mak= e > > > sure the SIGNAL_UNKILLABLE doesn't get set for these cases. > > > > So basically force_sig_info() is trying to figure out whether > > get_signal() will later on check for SIGNAL_UNKILLABLE (the SIG_DFL > > case), and if so, it clears the flag from the target's signal_struct > > that marks the process as unkillable? > > > > This used to be: > > > > if (action->sa.sa_handler =3D=3D SIG_DFL) > > t->signal->flags &=3D ~SIGNAL_UNKILLABLE; > > > > Then someone noticed that in the ptrace case, the signal might not > > actually end up being consumed by the target process, and added the > > "&& !t->ptrace" clause in commit > > eb61b5911bdc923875cde99eb25203a0e2b06d43. > > > > And now Robert Swiecki noticed that that still didn't accurately model > > what'll happen in get_signal(). > > > > This seems hacky to me, and also racy: What if, while you're going > > through a SECCOMP_RET_KILL_PROCESS in an unkillable process, some > > other thread e.g. concurrently changes the disposition of SIGSYS from > > a custom handler to SIG_DFL? > > Do you mean after force_sig_info_to_task() has finished but before > get_signal()? SA_IMMUTABLE will block changes to the action. Yeah, that's what I meant. Thanks, I missed SA_IMMUTABLE. Ugh, this is not pretty code...