Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1493169pxk; Thu, 10 Sep 2020 17:23:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTsYkXuPpai0OHQfOSxM8lDh6u7cVaDKfIQxp6g8bA1OeUU0U7SErn8QSoP2EukP4zhG1e X-Received: by 2002:aa7:d981:: with SMTP id u1mr11765986eds.250.1599783824227; Thu, 10 Sep 2020 17:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599783824; cv=none; d=google.com; s=arc-20160816; b=cFDTNlhFK7mANsjg2NEZi06mNgEWzSqWyRKXSeYy7yLfWRnfVrlbnJmhiXsyqhu3b8 M8O77aMnVZJSFoGcFr2eBL8vhf8C70KfIB2VpLg+AdZKkxO9Ur9PvtwFpQJnXbotKPBU zNZKfB7OzGT59ybSb+hnzMaYGuOh9CDqsQ5bTIYtct2zn+QxlF8k20E1oj5ajekxPC2H TARRZtkgJuC+nStecah6NzWs5GAzNDjf6rfgFH2FtdljWiGExLL+68sJcWlX3Dzt8CUv nQDYdrvAuZqfKkuPFvsmglIj0Ixnlnv5eRTY/iVn+3KBdyy/MUXR5m5Fd6QtpTulbjW4 hKGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IyAAsSx7nFV/dq/SzL35IFpVJ+Yn15D4pJKs31u9n78=; b=hNTT0VSE5xi8sa6GgKDVvljh3zUEm9HkqP0HhTckhc+Ygw94akylYz/WFNCL86J6TK s/CEzTrOrSYSil6MsY8FD6iwYJuAP/s84RlO1Bh0f02O8IjsBhnCG9y/Crtl8aW3lIXv 9YotNGd4muGn7BSWjouRHFP/0qKVayP2HoQSnUAOdPWTEP9iaTN3iqmrZhMs/uvpWQt6 8rf3bcYwv2JnG72ra0LHPoNG62qXRNoToCQuCEK6KnTiKhZS8dk6IlFmodTDJrEhyJN8 31pR5NY3W0D+VEznJjpdsxjGj9ogCd2dIC+yuMLnJAqZ/vZlQmMJIp00s9n1D5h0RYdb OcTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SijTA2JB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v2si187001ejy.65.2020.09.10.17.23.10; Thu, 10 Sep 2020 17:23:44 -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=@google.com header.s=20161025 header.b=SijTA2JB; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725536AbgIKAVA (ORCPT + 99 others); Thu, 10 Sep 2020 20:21:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725280AbgIKAU4 (ORCPT ); Thu, 10 Sep 2020 20:20:56 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E3B6C061573 for ; Thu, 10 Sep 2020 17:20:55 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id r7so11320329ejs.11 for ; Thu, 10 Sep 2020 17:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IyAAsSx7nFV/dq/SzL35IFpVJ+Yn15D4pJKs31u9n78=; b=SijTA2JBh2igQyUFhnGY43n8X9KiE/1xBjEYzMfT6RvTVPBWKIf2S98WFdxu9pntLY 3FWTWsLcOBbZZP+uQKQQFz4ztqRQDTHyvvYDTLpZ/Yx9mHMQtmxixW2u+2Iv/F2pmzx0 9Shwb8Rd2BYkk5HW11A7nj4k+Z9OU+m6AuaF06ISqWp+Wo0Dxl3Ftte6cYPtPbWW1yZR JLLqu2Dvol/xqraTUN3AMxutXgpUnMwIbPWTFot3PWxuMyymTw8Kv6tYWx+E0bQ1fw0S kVuDX8lq+sS+iKyOplLtlkXB4ZB4Y983W8fe/h7lUU2TIMbQmGvwGw79xY/i1sapn5fC JATA== 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=IyAAsSx7nFV/dq/SzL35IFpVJ+Yn15D4pJKs31u9n78=; b=GIBr/eOb7T2PV3I1myVp/GA0yZM3AENgRIROxJeVruwmtmi36owf0usJXZrH/VcXoi uKMwKTybMt8RF2pv6c/hfvvc58dbUoVG/oBqcdW8genIudIPv+Kom5pT1SSBWJO/mgwN jgqDeIYEErMpFCQl+T1jCVa+mNAFfZv2RO1F4JIKBw5NSVNCNwppdQwUhsK+Qz3yHM8O ojxE/3HZZz8EsP0fbi8e9UEkk9vovENUmQ/XXZcjg4u6l/dCZgeaXfHSbREKkinO3EG9 CiShmw8o475OyrMCAfBACsIHbYArTgTpqZAfdxNdvG0lhGAUAskLHz4SMt3e3K91OoEN 9c8g== X-Gm-Message-State: AOAM531sUp2FaA1o9fHlyTkVuastcsxcg63GjkKSSuJR5m9iIheOOyMl pP8gMGEEcJgEtSC872Jf7UJ2r8XniBWh+zh+KEZFFg== X-Received: by 2002:a17:906:a0c2:: with SMTP id bh2mr11898964ejb.493.1599783653707; Thu, 10 Sep 2020 17:20:53 -0700 (PDT) MIME-Version: 1.0 References: <20200910202107.3799376-1-keescook@chromium.org> <20200910202107.3799376-7-keescook@chromium.org> <202009101649.2A0BF95@keescook> In-Reply-To: <202009101649.2A0BF95@keescook> From: Jann Horn Date: Fri, 11 Sep 2020 02:20:27 +0200 Message-ID: Subject: Re: [RFC PATCH 6/6] security/fbfam: Mitigate a fork brute force attack To: Kees Cook Cc: Kernel Hardening , John Wood , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 11, 2020 at 1:56 AM Kees Cook wrote: > On Thu, Sep 10, 2020 at 01:21:07PM -0700, Kees Cook wrote: > > From: John Wood > > > > In order to mitigate a fork brute force attack it is necessary to kill > > all the offending tasks. This tasks are all the ones that share the > > statistical data with the current task (the task that has crashed). > > > > Since the attack detection is done in the function fbfam_handle_attack() > > that is called every time a core dump is triggered, only is needed to > > kill the others tasks that share the same statistical data, not the > > current one as this is in the path to be killed. [...] > > + for_each_process(p) { > > + if (p == current || p->fbfam_stats != stats) > > + continue; > > + > > + do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_PID); > > + pr_warn("fbfam: Offending process with PID %d killed\n", > > + p->pid); [...] > > + > > + killed += 1; > > + if (killed >= to_kill) > > + break; > > + } > > + > > + rcu_read_unlock(); > > Can't newly created processes escape this RCU read lock? I think this > need alternate locking, or something in the task_alloc hook that will > block any new process from being created within the stats group. Good point; the proper way to deal with this would probably be to take the tasklist_lock in read mode around this loop (with read_lock(&tasklist_lock) / read_unlock(&tasklist_lock)), which pairs with the write_lock_irq(&tasklist_lock) in copy_process(). Thanks to the fatal_signal_pending() check while holding the lock in copy_process(), that would be race-free - any fork() that has not yet inserted the new task into the global task list would wait for us to drop the tasklist_lock, then bail out at the fatal_signal_pending() check.