Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1565866pxk; Sun, 13 Sep 2020 07:36:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybH6Da0rxUat1n+qhPknig2Ni9QSbu3xnJZvsqd8ZoECfhe4WyTjBJ+H6lax4py6JiHc4g X-Received: by 2002:aa7:c61a:: with SMTP id h26mr12757267edq.254.1600007778526; Sun, 13 Sep 2020 07:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600007778; cv=none; d=google.com; s=arc-20160816; b=zXJrP2OVnNE6eIZ/NTXmfRkYOQ6hq3bczRxlI8Pq3gWTn7v2kVOjEVatvSW3cTfXvJ EI/ZXb8BTVvPh4kujHIM5mW8Z4dTdmfpI8tXX51B+ACTSeliBxoKzrqctv88rS8F6rUi lishT1l5qIi40RQEnlYPlMqALFdC3/AqITmqNNVfhIVt2P1MAh9/T0ET1OdRNzyPbqMP ZuWSd7ysASRw0UTr6JKFDZAQhgOJIF192QSST/2nc4Q4tYXX+xmyEP6T6A8Rol/vJRZP UBCt8GgNn+gMEjEcZMgA74o5/mOI1M44og+2pDmkbVX/+PW7CYSGiYRqRD+prXjSWFdi SjDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4pEVes5OF6Vhz5ToW1m+mPYJ2urtBr18jiNCJfxJoUo=; b=KdZ5c7qR6pXxaWyascCnBBbClBwtO8ZI4UdFR2GoFBP8DsVjCN2F70IOQyrVho9qxy 0Pt2lZB3QunekBYCO8nJ/dHLOjrmfQtLHDKNw0SnyvM3NmUbFrFgdnwvLlFdKCxSXviP xJdCcs4RSNCmEgkrKjNwu/aKQiE21m+J9s6ZtwtcfghqP3cZwafEpVjiAVvRtpjPnCmh w/9giIqtEroIBHzd1Gv2wJYq52lM4dR29/gWU1D3mvGutvEYhF5XchA/cWO0QWCEApEU Ho7IRvQBUh4VPj6Gpw33PvxQTBiIjCv0VmXuipM2H3R4VhkIgn2eWNNBdPmoIX3EJIdb 8m6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=bDSoCpaW; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v22si5104124ejb.444.2020.09.13.07.35.55; Sun, 13 Sep 2020 07:36:18 -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=@gmx.net header.s=badeba3b8450 header.b=bDSoCpaW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725956AbgIMOep (ORCPT + 99 others); Sun, 13 Sep 2020 10:34:45 -0400 Received: from mout.gmx.net ([212.227.17.21]:49329 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725928AbgIMOek (ORCPT ); Sun, 13 Sep 2020 10:34:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1600007610; bh=dHflCuyQDEYDcMpnPKECIFyNSbsiT8CytXlxu2bp71o=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=bDSoCpaW9dBsL2Re69QW0Ivh+uMs3Lhd+7aN2ghPtpPeOxQGgPuTPD9VBMY7PScxZ fqWvgD7YnoSPLFPa4dtja62tZuLzBqO6doYWbwW/XlIt2WSkJE4jg7CFoTE71eBj6X F3XnJTHec0KYINrIJadRACkr3dJPNUGbySNy2NZI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from ubuntu ([79.150.73.70]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MWzfl-1k2Nyl2VKr-00XMi7; Sun, 13 Sep 2020 16:33:30 +0200 Date: Sun, 13 Sep 2020 16:33:09 +0200 From: John Wood To: Kees Cook Cc: Jann Horn , kernel-hardening@lists.openwall.com, 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, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [RFC PATCH 4/6] security/fbfam: Add a new sysctl to control the crashing rate threshold Message-ID: <20200913143309.GA2873@ubuntu> References: <20200910202107.3799376-1-keescook@chromium.org> <20200910202107.3799376-5-keescook@chromium.org> <202009101612.18BAD0241D@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202009101612.18BAD0241D@keescook> X-Provags-ID: V03:K1:g34bOsvNGvcdIL3vhD+B4Loro4lpz3d33Rzd1nJZQCi64UltDtY KxXkFlAvpWBqoGc9UEunLZ+B/OmAtjL1rp4M3xrRUyHVKn12OGhCe2skngRwsODg8cbLsHO OHdWHHQb5TJ5/xDAvrL28XWApVU8+vl92dQGrc+yL91F4QwOnGwgm5j3yViHD8UrqUh3mNd V/g/bnSsOi/9Xa3OzjkhQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:0eHgbzh5VJg=:ZD7BwxwgOEUm0hOd/i4YrI Fy51LzGO2bzJr1jUdSDKUlZRJnVkZSwj1v8pheewD47iAw4hWoVTDV84BSunzJQF/BzMeDGBQ BQQycBZFdkD/yVL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L7 q+gMYrHOdM419N0m7Hod+1AZixmf9zmx3sOv8f//MMVKRFtG11SaNrita8N5A1O/Tv+czH0wC c+PSGq3fJJhrf6H/p4UMFzzS6pt3K58QJnF0iaA== 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, more inline. On Thu, Sep 10, 2020 at 04:14:38PM -0700, Kees Cook wrote: > > diff --git a/include/fbfam/fbfam.h b/include/fbfam/fbfam.h > > index b5b7d1127a52..2cfe51d2b0d5 100644 > > --- a/include/fbfam/fbfam.h > > +++ b/include/fbfam/fbfam.h > > @@ -3,8 +3,12 @@ > > #define _FBFAM_H_ > > > > #include > > +#include > > > > #ifdef CONFIG_FBFAM > > +#ifdef CONFIG_SYSCTL > > +extern struct ctl_table fbfam_sysctls[]; > > +#endif > > Instead of doing the extern and adding to sysctl.c, this can all be done > directly (dynamically) from the fbfam.c file instead. Like Yama do in the yama_init_sysctl() function? As a reference code. > > int fbfam_fork(struct task_struct *child); > > int fbfam_execve(void); > > int fbfam_exit(void); > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > > index 09e70ee2332e..c3b4d737bef3 100644 > > --- a/kernel/sysctl.c > > +++ b/kernel/sysctl.c > > @@ -77,6 +77,8 @@ > > #include > > #include > > > > +#include > > + > > #ifdef CONFIG_X86 > > #include > > #include > > @@ -2660,6 +2662,13 @@ static struct ctl_table kern_table[] =3D { > > .extra1 =3D SYSCTL_ZERO, > > .extra2 =3D SYSCTL_ONE, > > }, > > +#endif > > +#ifdef CONFIG_FBFAM > > + { > > + .procname =3D "fbfam", > > + .mode =3D 0555, > > + .child =3D fbfam_sysctls, > > + }, > > #endif > > { } > > }; > > diff --git a/security/fbfam/Makefile b/security/fbfam/Makefile > > index f4b9f0b19c44..b8d5751ecea4 100644 > > --- a/security/fbfam/Makefile > > +++ b/security/fbfam/Makefile > > @@ -1,2 +1,3 @@ > > # SPDX-License-Identifier: GPL-2.0 > > obj-$(CONFIG_FBFAM) +=3D fbfam.o > > +obj-$(CONFIG_SYSCTL) +=3D sysctl.o > > diff --git a/security/fbfam/fbfam.c b/security/fbfam/fbfam.c > > index 0387f95f6408..9be4639b72eb 100644 > > --- a/security/fbfam/fbfam.c > > +++ b/security/fbfam/fbfam.c > > @@ -7,6 +7,17 @@ > > #include > > #include > > > > +/** > > + * sysctl_crashing_rate_threshold - Crashing rate threshold. > > + * > > + * The rate's units are in milliseconds per fault. > > + * > > + * A fork brute force attack will be detected if the application's cr= ashing rate > > + * falls under this threshold. So, the higher this value, the faster = an attack > > + * will be detected. > > + */ > > +unsigned long sysctl_crashing_rate_threshold =3D 30000; > > I would move the sysctls here, instead. (Also, the above should be > const.) If the above variable is const how the sysctl interface can modify it? I think it would be better to declare it as __read_mostly instead. What do you think? unsigned long sysctl_crashing_rate_threshold __read_mostly =3D 30000; > > + > > /** > > * struct fbfam_stats - Fork brute force attack mitigation statistics= . > > * @refc: Reference counter. > > diff --git a/security/fbfam/sysctl.c b/security/fbfam/sysctl.c > > new file mode 100644 > > index 000000000000..430323ad8e9f > > --- /dev/null > > +++ b/security/fbfam/sysctl.c > > @@ -0,0 +1,20 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include > > + > > +extern unsigned long sysctl_crashing_rate_threshold; > > +static unsigned long ulong_one =3D 1; > > +static unsigned long ulong_max =3D ULONG_MAX; > > + > > +struct ctl_table fbfam_sysctls[] =3D { > > + { > > + .procname =3D "crashing_rate_threshold", > > + .data =3D &sysctl_crashing_rate_threshold, > > + .maxlen =3D sizeof(sysctl_crashing_rate_threshold), > > + .mode =3D 0644, > > + .proc_handler =3D proc_doulongvec_minmax, > > + .extra1 =3D &ulong_one, > > + .extra2 =3D &ulong_max, > > + }, > > + { } > > +}; > > I wouldn't bother splitting this into a separate file. (Just leave it in > fbfam.c) > > -- > Kees Cook Thanks, John Wood