Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp477605pxu; Thu, 15 Oct 2020 08:33:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2pn7DDu2tpxuCdxL2KPSXuRKrxkGA6RQHugH3Lco16TaV5Poh2yae1HNGf5GjsyzHamAb X-Received: by 2002:a17:906:234d:: with SMTP id m13mr5085478eja.497.1602776027976; Thu, 15 Oct 2020 08:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602776027; cv=none; d=google.com; s=arc-20160816; b=nN61Q5FU2M6Qf3Q8/4CJIz6zSRTv7DfCf5fn9kk6sGVD6DcpQ5mHmg94oKqA16lBgD brr6TSv6kq32cnrxO4byjFz+xjZsVBUNCmUNZBG03HAnNLQcx/skkjcRQ85GzcHnBksX LILA8coySXBJWLtAK3n3hDVNPPKQt0Ythx1Utvl+7MbRauKW7x6C1UIRPi3h8yMr3fbQ Huj0s2drCG7TbaDVTyp+Mel4dKKGXpqnrviL5fBGFYM/zym4eEUSw+muSZkWwwf6wsk7 zTuWoQ/Rn5LxRahrs5r0SB2E+oSouyxujTd8WsIcGtYagRoW7tjn3t3jrJ+S2WqNSZse Jsrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=U5q/13K3wQ8DEGV/+NbZ3h88F9rfficFDBhzYf3kbIg=; b=NciVfGgRHSuDyrRjMRYtun1WsudPbSRVulxCg2NfiMKVLL8zX+nb7LG/cQSYGl0KTa O2nfDfxzNPEfFFfSBHV4hbuNwJIl/eSoMbx5XaAIouN9KLxCnhwwRSaJwopDV1x5dEZu a8XhojVjOgG41Dvb+Qnh9XaRh7Co4daCDtJQMYUsKeAWnSh2X2gAcCcjraF5YZZMx28Q 6F1k9tZI4cu7Pw9L6l6vxs2cEL9049v7hc8k0Ud+g3z+ziUb8JDCAFNXQ9Y0GXAkojC2 LFlrY/v93ZZ0TR7gA+nQufWhCzzoDAAYVEJwlI2GxixrzWHiuSxT1y0bWnk+hs13gOfU XYBQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d4si2233039edr.173.2020.10.15.08.33.15; Thu, 15 Oct 2020 08:33:47 -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; 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 S1730878AbgJOPaL (ORCPT + 99 others); Thu, 15 Oct 2020 11:30:11 -0400 Received: from mail.hallyn.com ([178.63.66.53]:47584 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730085AbgJOPaL (ORCPT ); Thu, 15 Oct 2020 11:30:11 -0400 Received: by mail.hallyn.com (Postfix, from userid 1001) id 505261105; Thu, 15 Oct 2020 10:30:09 -0500 (CDT) Date: Thu, 15 Oct 2020 10:30:09 -0500 From: "Serge E. Hallyn" To: Aleksandr Nogikh Cc: jmorris@namei.org, serge@hallyn.com, akinobu.mita@gmail.com, andreyknvl@google.com, dvyukov@google.com, elver@google.com, glider@google.com, keescook@google.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Aleksandr Nogikh Subject: Re: [RFC PATCH 1/1] security: add fault injection capability Message-ID: <20201015153009.GA26517@mail.hallyn.com> References: <20201015104649.2104432-1-a.nogikh@gmail.com> <20201015104649.2104432-2-a.nogikh@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201015104649.2104432-2-a.nogikh@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 15, 2020 at 10:46:49AM +0000, Aleksandr Nogikh wrote: > From: Aleksandr Nogikh > > Add a fault injection capability to call_int_hook macro. This will > facilitate testing of fault tolerance of the code that invokes > security hooks as well as the fault tolerance of the LSM > implementations themselves. > > Add a KConfig option (CONFIG_FAIL_LSM_HOOKS) that controls whether the > capability is enabled. In order to enable configuration from the user > space, add the standard debugfs entries for fault injection (if > CONFIG_FAULT_INJECTION_DEBUG_FS is enabled). > > Signed-off-by: Aleksandr Nogikh > --- > lib/Kconfig.debug | 6 +++++ > security/security.c | 53 ++++++++++++++++++++++++++++++++++++++++++--- > 2 files changed, 56 insertions(+), 3 deletions(-) > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 08c82666cf3e..0c9913ebe1c1 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -1803,6 +1803,12 @@ config FAIL_MAKE_REQUEST > help > Provide fault-injection capability for disk IO. > > +config FAIL_LSM_HOOKS > + bool "Fault-injection capability for LSM hooks" > + depends on FAULT_INJECTION > + help > + Provide fault-injection capability for LSM hooks. > + > config FAIL_IO_TIMEOUT > bool "Fault-injection capability for faking disk interrupts" > depends on FAULT_INJECTION && BLOCK > diff --git a/security/security.c b/security/security.c > index 69ff6e2e2cd4..bd4dbe720098 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > #include > > #define MAX_LSM_EVM_XATTR 2 > @@ -669,6 +670,51 @@ static void __init lsm_early_task(struct task_struct *task) > panic("%s: Early task alloc failed.\n", __func__); > } > > + > +#ifdef CONFIG_FAIL_LSM_HOOKS > + > +static struct { > + struct fault_attr attr; > + int retval; > +} fail_lsm_hooks = { > + .attr = FAULT_ATTR_INITIALIZER, > + .retval = -EACCES > +}; > + > +static int __init setup_fail_lsm_hooks(char *str) > +{ > + return setup_fault_attr(&fail_lsm_hooks.attr, str); > +} > +__setup("fail_lsm_hooks=", setup_fail_lsm_hooks); > + > +static int should_fail_lsm_hook(void) > +{ > + return should_fail(&fail_lsm_hooks.attr, 1) ? fail_lsm_hooks.retval : 0; > +} > + > +#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS > + > +static int __init fail_lsm_hooks_debugfs(void) > +{ > + umode_t mode = S_IFREG | 0600; > + struct dentry *dir; > + > + dir = fault_create_debugfs_attr("fail_lsm_hooks", NULL, > + &fail_lsm_hooks.attr); > + debugfs_create_u32("retval", mode, dir, &fail_lsm_hooks.retval); > + return 0; > +} > + > +late_initcall(fail_lsm_hooks_debugfs); > + > +#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ > + > +#else > + > +static inline int should_fail_lsm_hook(void) { return 0; } > + > +#endif /* CONFIG_FAIL_LSM_HOOKS */ > + > /* > * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and > * can be accessed with: > @@ -707,16 +753,17 @@ static void __init lsm_early_task(struct task_struct *task) > } while (0) > > #define call_int_hook(FUNC, IRC, ...) ({ \ > - int RC = IRC; \ > - do { \ > + int RC = should_fail_lsm_hook(); \ seeing 'should_fail' here, kind of out of context, would be confusing to thousands of ppl reading the code and wondering why it should fail. maybe "inject_fail_lsm_hook()" ? > + if (RC == 0) { \ > struct security_hook_list *P; \ > + RC = IRC; \ > \ > hlist_for_each_entry(P, &security_hook_heads.FUNC, list) { \ > RC = P->hook.FUNC(__VA_ARGS__); \ > if (RC != 0) \ > break; \ > } \ > - } while (0); \ > + } \ > RC; \ > }) > > -- > 2.28.0.1011.ga647a8990f-goog