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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3065AC433EF for ; Thu, 18 Nov 2021 01:21:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1810761B64 for ; Thu, 18 Nov 2021 01:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242203AbhKRBX5 (ORCPT ); Wed, 17 Nov 2021 20:23:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242198AbhKRBXp (ORCPT ); Wed, 17 Nov 2021 20:23:45 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA95DC061766 for ; Wed, 17 Nov 2021 17:20:45 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id w1so19351464edc.6 for ; Wed, 17 Nov 2021 17:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=N9zDLh8C4cET9vcP6JDNqTwr8KRqom/U2tw34i8nOWk=; b=JmVrz1Q1JKnr3TIhwHYaaONqjgaCaxJbX6wpl2/o1si/vnDnx6hqBqr4EPPBjM+x3F LkNmbmLpkML3JJdCnnfcUb5amc+ZxL/ThtJRS6j8oeqHI7RHsaM18dUqbPOhlyTuUKQf a5K/CDsgD3d7RvY2tdcKZ+/3vhTMHSWgSoUwA9zVjCqdRfBSqlZ8hNaLievgJvfI9G1W jBvGJZz0UsP+lFQrb7M9nYOmorWqaJV7QDlmK2Lkyqlv6ZflnMMzD7N7h8eTrvpBgluK 4LB6k2+fT7d9zvz0pYEAPBxbYleF+tM4WzRScj0JNUExt5XzvwHmRwCScGK5fRgT/Ijs +BgA== 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; bh=N9zDLh8C4cET9vcP6JDNqTwr8KRqom/U2tw34i8nOWk=; b=RNWqgb+fBfH4JQQr2VPsGgkykve/1H6w7CcPdSHeo62sV0cn9HjOUB+RbcTIqtP1KF EHXLY4cdlS6uKNWpRliXGMHnVqpabIEUeR51SzqJ+XdQB3ftcypSJl4kETMNRT2aiLBe gqJ1jewfyHYW/gNMNIAm7Dulfg+2JsgE7qq1s2Lcg3vAVQh/zO36SLqKLMlSMA0tqVp0 fJq8XVxJRjojE9DX/cwvASBAU0vyHREyJxk7Zz7U9fHaF3R9ecawv8BlCmyto6Dkbx/D VUuB87srIAVdQGLPaM3TUJMDRbS8xGoiOwrrKvqXQ+V3EVEJEROnXYodSTo+RJtjEGTr epEg== X-Gm-Message-State: AOAM530r/0IfXFQua1ZGfwYu9zCKpPynh/I4rZbiHPoGfw8vxvISN1Sj qwSOlhe78LyyiM9oapagn0nLaRKiX37JXLGyTb0EGA== X-Google-Smtp-Source: ABdhPJzyZMWRDSNhVRQ+YY93TKx7aUdiyobq666l0LHWxI/JoQTYaZDj9fUjWADvjoy95Rlz9PiMLsZS3aWM6onyeoA= X-Received: by 2002:a17:906:140b:: with SMTP id p11mr27713464ejc.116.1637198444338; Wed, 17 Nov 2021 17:20:44 -0800 (PST) MIME-Version: 1.0 References: <202111171049.3F9C5F1@keescook> <87k0h6334w.fsf@email.froward.int.ebiederm.org> <202111171341.41053845C3@keescook> In-Reply-To: From: Kyle Huey Date: Wed, 17 Nov 2021 17:20:33 -0800 Message-ID: Subject: Re: [REGRESSION] 5.16rc1: SA_IMMUTABLE breaks debuggers To: Linus Torvalds Cc: Kees Cook , "Eric W. Biederman" , Andrea Righi , Shuah Khan , Alexei Starovoitov , Andy Lutomirski , Will Drewry , "open list:KERNEL SELFTEST FRAMEWORK" , bpf , open list , linux-hardening@vger.kernel.org, "Robert O'Callahan" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 17, 2021 at 5:11 PM Linus Torvalds wrote: > > On Wed, Nov 17, 2021 at 4:37 PM Kyle Huey wrote: > > > > This fixes most of the issues with rr, but it still changes the ptrace > > behavior for the double-SIGSEGV case > > Hmm. I think that's because of how "force_sigsgv()" works. > > I absolutely detest that function. > > So we have signal_setup_done() doing that > > if (failed) > force_sigsegv(ksig->sig); > > and then force_sigsegv() has that completely insane > > if (sig == SIGSEGV) > force_fatal_sig(SIGSEGV); > else > force_sig(SIGSEGV); > > behavior. > > And I think I know the _reason_ for that complete insanity: when > SIGSEGV takes a SIGSEGV, and there is a handler, we need to stop > trying to send more SIGSEGV's. Right, in our test we setup a SIGSEGV handler on an alt stack that doesn't actually exist, and then overflow the regular stack, and that would loop forever trying to setup SIGSEGV handlers if it weren't for force_sigsegv and the sigdfl=true stuff. > But it does mean that with my change, that second SIGSEGV now ends up > being that SA_IMMUTABLE kind, so yeah, it broke the debugger test - > where catching the second SIGSEGV is actually somewhat sensible (ok, > not really, but at least understandable) > > End result: I think we want not a boolean, but a three-way choice for > that force_sig_info_to_task() thing: with the following clarifications, yes > - unconditionally fatal (for things that just want to force an exit > and used to do do_exit()) no matter what the ptracer wants > - ignore valid and unblocked handler (for that SIGSEGV recursion > case, aka force "sigdfl") but following the usual ptrace rules > - catching signal ok > > So my one-liner isn't sufficient. It wants some kind of nasty enum. > > At least the enum can be entirely internal to kernel/signal.c, I > think. No need to expose this all to anything else. > > Linus Yeah that's one way to solve the problem. I think you're right that fundamentally the problem here is that what SECCOMP_RET_KILL wants is not really a signal. To the extent that it wants a signal, what it really wants is SIGKILL, and the problem here is the code trying to act like SIGKILL but call it SIGSYS. I assume the ship for fixing that sailed years ago though. - Kyle