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 X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ECDDC2D0E0 for ; Tue, 15 Sep 2020 18:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB26F20732 for ; Tue, 15 Sep 2020 18:39:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=gmx.net header.i=@gmx.net header.b="eeQDvAac" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728015AbgIOSje (ORCPT ); Tue, 15 Sep 2020 14:39:34 -0400 Received: from mout.gmx.net ([212.227.17.20]:50887 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbgIORjc (ORCPT ); Tue, 15 Sep 2020 13:39:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1600191432; bh=NJ6O5rFyFRlQXoAS3XFVS8BQi/rApnd7lWRwhfK2Xlg=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=eeQDvAacH1VlXwy4iH3Fxv2qyTjt32iVfeKBKyzgI7+LGScpg5JNVDryxc0pkFL7N zqoJ1hZ3D0VN3JGismE3Z9ckMhtWuP06kvJvEVLGhRUkTahazF+9UvM7UneJRJLpW9 Z5eKxS0WNWMmopdQzAW4AkXHnNEFwNzlLAhdqHfM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from ubuntu ([79.150.73.70]) by mail.gmx.com (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MEUz4-1kGWkE0klW-00G08s; Tue, 15 Sep 2020 19:37:12 +0200 Date: Tue, 15 Sep 2020 19:36:27 +0200 From: John Wood To: Jann Horn Cc: John Wood , Kees Cook , Kernel Hardening , Matthew Wilcox , Jonathan Corbet , Alexander Viro , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Luis Chamberlain , Iurii Zaikin , James Morris , "Serge E. Hallyn" , linux-doc@vger.kernel.org, kernel list , linux-fsdevel , linux-security-module Subject: Re: [RFC PATCH 5/6] security/fbfam: Detect a fork brute force attack Message-ID: <20200915173627.GA2900@ubuntu> References: <20200910202107.3799376-1-keescook@chromium.org> <20200910202107.3799376-6-keescook@chromium.org> <202009101634.52ED6751AD@keescook> <20200913152724.GB2873@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:+Tv9EY0th3c1INR7wYqsaQT1v7XmqULQmf1mCMF8tBv7us+6tmw 383m5XxCtjIbCae841iMOqJ2Kb5mfB5OzM0d7bWnQ/N2gDAhnuzMcocEglMiEwyJSk3JQJY A8urH8HcByeEI58owhYnERH7vdI+cm29w8O8VDx8RuXDp3riBg1FpBliC3UfpGBZw8KurB1 T/YoWfU4tpzRllQytfgJQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:4Yu2qoJjF0U=:HHZzV9mfG2ygAGqXu5SlIO b6fw//682jHONr9ldrDNb1XyJothxmBz6Vmqu5LRz+VzKi+Iobvg71yk1utVXXrr4ydn7w1i4 Bo8DAIv8PN4nGmuQR0RWyRtNXdKVtbVhLrZ0aZNjY74rEbgcOZ5GvhU03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d5Riwoy7QO8/52Tfoke+fdGEv7LLWDUZxPoEN1TX 78MvWsWqHA0c669IvrfXYcskGlGCPN7xB8N4Bfg== Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, Sep 14, 2020 at 09:39:10PM +0200, Jann Horn wrote: > On Sun, Sep 13, 2020 at 6:56 PM John Wood wrote: > > On Fri, Sep 11, 2020 at 02:01:56AM +0200, Jann Horn wrote: > > > On Fri, Sep 11, 2020 at 1:49 AM Kees Cook wr= ote: > > > > On Thu, Sep 10, 2020 at 01:21:06PM -0700, Kees Cook wrote: > > > > [...] > > > > I don't think this is the right place for detecting a crash -- isn= 't > > > > this only for the "dumping core" condition? In other words, don't = you > > > > want to do this in get_signal()'s "fatal" block? (i.e. very close = to the > > > > do_coredump, but without the "should I dump?" check?) > > > > > > > > Hmm, but maybe I'm wrong? It looks like you're looking at noticing= the > > > > process taking a signal from SIG_KERNEL_COREDUMP_MASK ? > > > > > > > > (Better yet: what are fatal conditions that do NOT match > > > > SIG_KERNEL_COREDUMP_MASK, and should those be covered?) > > > > > > > > Regardless, *this* looks like the only place without an LSM hook. = And it > > > > doesn't seem unreasonable to add one here. I assume it would proba= bly > > > > just take the siginfo pointer, which is also what you're checking. > > > > > > Good point, making this an LSM might be a good idea. > > > > > > > e.g. for include/linux/lsm_hook_defs.h: > > > > > > > > LSM_HOOK(int, 0, task_coredump, const kernel_siginfo_t *siginfo); > > > > > > I guess it should probably be an LSM_RET_VOID hook? And since, as yo= u > > > said, it's not really semantically about core dumping, maybe it shou= ld > > > be named task_fatal_signal or something like that. > > > > If I understand correctly you propose to add a new LSM hook without re= turn > > value and place it here: > > > > diff --git a/kernel/signal.c b/kernel/signal.c > > index a38b3edc6851..074492d23e98 100644 > > --- a/kernel/signal.c > > +++ b/kernel/signal.c > > @@ -2751,6 +2751,8 @@ bool get_signal(struct ksignal *ksig) > > do_coredump(&ksig->info); > > } > > > > + // Add the new LSM hook here > > + > > /* > > * Death signals, no core dump. > > */ > > It should probably be in the "if (sig_kernel_coredump(signr)) {" > branch. And I'm not sure whether it should be before or after > do_coredump() - if you do it after do_coredump(), the hook will have > to wait until the core dump file has been written, which may take a > little bit of time. But if the LSM hook is placed in the "if (sig_kernel_coredump(signr)) {" branch, then only the following signals will be passed to it. SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGSEGV, SIGBUS, SIGSYS, SIGXCPU, SIGXFSZ, SIGEMT The above signals are extracted from SIG_KERNEL_COREDUMP_MASK macro, and are only related to coredump. So, if we add a new LSM hook (named task_fatal_signal) to detect a fatal signal it would be better to place it just above the if statement. diff --git a/kernel/signal.c b/kernel/signal.c index a38b3edc6851..406af87f2f96 100644 =2D-- a/kernel/signal.c +++ b/kernel/signal.c @@ -2736,6 +2736,8 @@ bool get_signal(struct ksignal *ksig) */ current->flags |=3D PF_SIGNALED; + // Place the new LSM hook here + if (sig_kernel_coredump(signr)) { if (print_fatal_signals) print_fatal_signal(ksig->info.si_signo); This way all the fatal signals are caught and we also avoid the commented delay if a core dump is necessary. Thanks, John Wood