Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp195656pxx; Mon, 26 Oct 2020 06:38:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznQ0ipSIIKzAchiSJ9d6KwzDiPudDzMWofVEXnzyHtRL4MXAwZyxbxH34anq3+nLaR9mRl X-Received: by 2002:a17:906:fad8:: with SMTP id lu24mr15503524ejb.486.1603719481792; Mon, 26 Oct 2020 06:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603719481; cv=none; d=google.com; s=arc-20160816; b=f6F6qpqm16IhDM+ZcuE4TeUbgYQ5gh9iGysp//U49yLZLYlvyOavnU6wvOB0bdpY8Y aa5Uq/D6ZIpzguT5WOg7uSllLDzPzlkqfMZaqTFcXzxaX215J+KqXoTnguYPx73kEurK vJdBodQzApa3gfLKUf1iFYycCCzCRa5jARnWUeN+F8ymqXoFExbo6KlJ+1Wrlhyy8Rpg X7pe6Ojro63zdiC5bc6ffEFyyTfBqsjVr5XNk+Q7qu7YV2iyf6/xpbp5zYzuJYT0uaSl BnIZr3iTRj2mkjJTEcUVvWn6wvXPE2xwey1sR/DveXo1kXM71ATO29P6vNloZ6PV7SB1 Ligg== 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=zIZSI5eymRh7YleTXMPveAGwP5JgMGOTN1Kj60Qisgw=; b=e9KegXCo2o6A7Z8Gs/oyiSFksBKzDpqeirO6yvtKo37wxhOkJ9dJx+Qr9+KDlfkGqJ f3sAy7c4ePrA99sqiMNVDRfdmwms4RsgCaMdeDhOV5PDd8CtP2g2nDkRBfTPTup17X5b yITWLhwcz0VF6XfcCUCiqyVHUr0fBDxo9XRhIWMUnOCw8TR/NnyZQWXy2kfL8BSzFY7W SQfbznzdmNW6giqhC/XrljKItHglDXNr+O+rK0dX6aZFG/y2et/GiuY6ZkO4i+ZSykGf t4UaorqA8bVeS/NLHg3P2ZJMZ6P9tn6uF6dl/tK7+QYcN2IgkzWSNbn9fOH06jvGlUtT /Z4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Wh9KLOGg; 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 gs18si5486998ejb.225.2020.10.26.06.37.39; Mon, 26 Oct 2020 06:38:01 -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=Wh9KLOGg; 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 S1775741AbgJZMxE (ORCPT + 99 others); Mon, 26 Oct 2020 08:53:04 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51035 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1775702AbgJZMwr (ORCPT ); Mon, 26 Oct 2020 08:52:47 -0400 Received: by mail-wm1-f66.google.com with SMTP id 13so11520502wmf.0; Mon, 26 Oct 2020 05:52:46 -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=zIZSI5eymRh7YleTXMPveAGwP5JgMGOTN1Kj60Qisgw=; b=Wh9KLOGg6biS1w0GfT8TZ3i/0yZCu5gbkCT89jb7Vt6NZRdYTD1EM30crU5xXFD5dd OBnWh50eHsPR0xpWZ9ul3AaEqGVHC12nJ78rDbuKfWPNehjBUCEcqonD1RyBAXn/6kUj g9Vf1Sp9by4n4laduAxA6qWm2FQZrJ7sqKe16nvCQI/kFEcg72HAbjni+NY77VaaTIFh oeffbQpSyulFeghqvNl9krhJCC7FuN8fqQm4gW5KNbjB8uSEzN7o3JX2o9jJmINTZ3Ym FT8gCwCOt+5BycHLYXD3qleRdLNJSYYpReNCtJFr76LCT7fAT5MvR0FwBAiv0eFC+y/Q 7OnQ== 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=zIZSI5eymRh7YleTXMPveAGwP5JgMGOTN1Kj60Qisgw=; b=h6mUFhjVT0OYQRrIhSmrpA+mRlkZdaTQ4wzyjKkg2mw+7Z0a9dAP71GQWPNQuTebOI Kg2W6iq0DMTBobK5bkbFW8x4G5KfcqbzNaBmlkgS9+cwduJ29qQowWygdpP0Zz4SSgYz WYLcX0SCQLy8fEwCKigbGQ+Un8W+BmXAQngumIlVVAMjKoAWxBKKwr2zY6436JPe5tF8 xJQVLNMifp8UMAXEOd03mMu7RZN/+nXDa4AzeedCnOBpSiLBD9MKGClMS8CpBxNPKYOF iYNRVQNnmcDjtqEb5je5GuOfxu5c4zutz4CWJxRgkikqLMjNFaw4coU2eJSnsCTk2Bb/ fb2A== X-Gm-Message-State: AOAM530XvlfRiZPZ2wq+vzkVcfDCp2GavSS1+5UwiC8dwB+IqlZcW7An XhiSXUHI/+bsHEKXqLT5kek= X-Received: by 2002:a1c:4085:: with SMTP id n127mr15399157wma.183.1603716765582; Mon, 26 Oct 2020 05:52:45 -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 a3sm23551139wrh.94.2020.10.26.05.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 05:52:45 -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, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Aleksandr Nogikh Subject: [RFC PATCH v2 1/2] security: add fault injection capability Date: Mon, 26 Oct 2020 12:52:26 +0000 Message-Id: <20201026125227.54520-2-a.nogikh@gmail.com> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201026125227.54520-1-a.nogikh@gmail.com> References: <20201026125227.54520-1-a.nogikh@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 should_fail_lsm_hook(). --- 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.0.rc1.297.gfa9743e501-goog