From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A086C433EF for ; Fri, 11 Feb 2022 20:15:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348926AbiBKUPm (ORCPT ); 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-Google-Smtp-Source: ABdhPJwxuRGJlb59/HO/KFupbtqn1lGMApRIpVAemnjvZ04sgT9KZ9Pb8LdGhWzkwKG7zykKNWEL3OKZw+Qxo0VpISY= 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 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...