Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp673973pxx; Thu, 29 Oct 2020 11:37:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZrFSmDsR/KfiwDmP/ipnwbKKRmLak52HjhPGcJjfQ0+hIm9NVe4gvENeYimsd8+XQVVpN X-Received: by 2002:aa7:ca4d:: with SMTP id j13mr5347084edt.119.1603996665870; Thu, 29 Oct 2020 11:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603996665; cv=none; d=google.com; s=arc-20160816; b=mVkalUInxObKoD343O3yhvD/USfZZ5S/TkadvHhfZBmvlqbwQ0tJfXULlcD7nbYvFN xuZgGSbpynalyN3OcWeqFTN+OHFw9KFWk2KSZ7WVzB02PiuYkDwW1MBh9LmMkz8K+Mxa DLdAyVoxOyV8bjFg6oQ6rS0vhDY0CPE5HUzx3hLfy/JP6Epb4ZXPUarE/n0BVxMbRPlo 5os9R/izw+Sg4xpPRf99X3Xfxq4jRP1XwLlON6oZm0t/7JXTh7EbsotZ0rO5pgNMsHTu AYR1IqDZpZ/kcJVrSIQKo0pbjF1Dx8OYlvYIG0rnoPJCq79vtBxqSCipwiG2RltHzeTR yhtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w8mwNG6QMyXuJ+ivtb4CUHNuJO9DxREq+55PstukYGQ=; b=wTEX6bRi4sj/eCawZexwvBlS3QsAifSwnayIKiJRxcphxGLkotNsf/tLz4dBCeBqI7 pEhEPJw4FdnB/aP2oTgQOMWYOxt/m3SQCiLNXm8yobnN1uG4cnF67oQ2O9ngOOxf2csa TlcIid6iY6tOv01MSaOiPEYxCMROpo5btPeUkYDAZ+b6qyVe2BqaJGE+PLIawP74g3VD SEXOqr4yRxnlRU7HXFCAW2pqWv6lzsQggm9SQGqDB3t31oyS35w0EityfWwtuLI1VZQI 1MxTcgbRZtMNpeAYsvo8f333pcfd7exhFdwXYPJtPDqN8nyUpVQjPwoqC7lU7Kt0rmlF PMxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="W/8nB9ki"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si2865369ejm.262.2020.10.29.11.37.23; Thu, 29 Oct 2020 11:37:45 -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=@gmail.com header.s=20161025 header.b="W/8nB9ki"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725940AbgJ2Sfx (ORCPT + 99 others); Thu, 29 Oct 2020 14:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbgJ2Sfv (ORCPT ); Thu, 29 Oct 2020 14:35:51 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 955E7C0613CF; Thu, 29 Oct 2020 11:35:51 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id k10so2540001wrw.13; Thu, 29 Oct 2020 11:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w8mwNG6QMyXuJ+ivtb4CUHNuJO9DxREq+55PstukYGQ=; b=W/8nB9kiRr68G8VfevQBmXOIky2SdJql0ywaRfKd4Pxmi83ARpm+KwVJ1H4rjnbHPd n9l9MsGe0cNWXaVGE3TnoWf9pzAYSxnwRNq5I33WVFE2vSweZC+IU8bzwtNDmBouOtBh WTDHWhfntaJePyuwcCPT9yxajvQVAMFvqSyi6lsZXkbjgTAURQZETrXKrgrEhinoUTHE fTrTSwnA96ulc3cc0zZaMjuWyhY/h0HqdzaAgFtebcqCVHU6wP15d5pgH7REGMOdlk2l GLi8FdrP3V7wdbVcxGhLFVCMslNdGORVrNIc1CQ9zj06iPGfu275flx5LG83wFc6cBKU 9BWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w8mwNG6QMyXuJ+ivtb4CUHNuJO9DxREq+55PstukYGQ=; b=gALhhO0l8mu9JzIOfaBBpQN42E0zyJWHHgTouZp+EIqaG3djWEVmKRmOVgkLK5ohXd ls0kVAq3cZ6A/RdBHkMndOSPjPz0ZTLehiMb/uvlFpQuGqATcsxi4wzALQknl0/BpwwN IQXVt2LQGuQdOweanASSQgWNbnJSkiWuV+rOw47Tikv9mxFs88ATpeUeu6QydpPYphHD AKS77XxqkvOdvrUAlwWYmfHqMcJ/doD7hkkyCaDlJHqqKommOr0zaDqGgiFg/AFCQiRh 11SmvLIiKAXrpic/0EGdyAjDmLJENeKngc9evkPHct3VlaNQAIf9PVDXB5VtbN9IjvH4 UVdg== X-Gm-Message-State: AOAM530di/LlGMv8Tz5HEjnGTKtHeAd9nrST+XZPhgi6uSLr+mQTdX8/ qZJQbG2jE94fa1sBuHzwDSU= X-Received: by 2002:adf:f482:: with SMTP id l2mr7297025wro.26.1603996550404; Thu, 29 Oct 2020 11:35:50 -0700 (PDT) Received: from nogikh.c.googlers.com.com (88.140.78.34.bc.googleusercontent.com. [34.78.140.88]) by smtp.gmail.com with ESMTPSA id f4sm5800982wrq.54.2020.10.29.11.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 11:35:49 -0700 (PDT) From: Aleksandr Nogikh To: jmorris@namei.org, serge@hallyn.com, akinobu.mita@gmail.com Cc: andreyknvl@google.com, dvyukov@google.com, elver@google.com, glider@google.com, keescook@google.com, casey@schaufler-ca.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Aleksandr Nogikh Subject: [PATCH v3 1/2] security: add fault injection capability Date: Thu, 29 Oct 2020 18:35:25 +0000 Message-Id: <20201029183526.2131776-2-aleksandrnogikh@gmail.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201029183526.2131776-1-aleksandrnogikh@gmail.com> References: <20201029183526.2131776-1-aleksandrnogikh@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v2: * Renamed should_fail_lsm_hook() to lsm_hooks_inject_fail(). --- 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 537cf3c2937d..80d289591e29 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..1105ad0f6891 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 lsm_hooks_inject_fail(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 lsm_hooks_inject_fail(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 = lsm_hooks_inject_fail(); \ + 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.29.1.341.ge80a0c044ae-goog