Received: by 10.213.65.68 with SMTP id h4csp1304629imn; Sun, 8 Apr 2018 00:02:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx489KOUaVw9NwIxZslD1E+aOWKUA8Lrr4j5KCo1y4dI26kDh5iGPfCYYZcmVBvim5Sv/gJQR X-Received: by 10.99.8.194 with SMTP id 185mr775515pgi.17.1523170953200; Sun, 08 Apr 2018 00:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523170953; cv=none; d=google.com; s=arc-20160816; b=tCHes2cKi4kTep3G+158ukyR6zrrx0aao3uI4g+QlZo+2rjGbG3AzRkEIDGmgYuCjn w+Y0lsF8V8+9eZhsfxOFIwmzgg9pWiPM+oud339eZk8cc3j9ikX5Giwv6YRdmYzUfjPs gomUZkX5mmm7y85x3BmvTXBgONGIDupftMT66JlAri4J/jqb9UBVN2N1D9/Cprjf4Rw/ iweNYfQlQUEye6BedkZLO+21C6gH20MX7XzFHsScKrXuj7qUafgeuqXAVhNaMxRA5uuM FmDs1AfvGX/aYU3t3i3INoLaA9a6hf1rICkMyMPonJf2RyIWI6QdKP+2yt2xkt7QaD94 vnsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=aVlUZcnNFq3nlcwbl+pxwyvwxgaZH3f4FPaaSeiW09A=; b=peWcKUTZ1ze4+ekhCQtKnCcRixee0QMaze5Tt2rOLVlaVqu6iG/VUqmHPmgLTj9kEA 3EWbw0LJu1W7ojJCLcbCZfAFOXXfJpN0Q6dFvy4CMXH8Hsw1d/OdwL7rpBDtUVIu0BBW T0ulypS1jFbOkjR+oE5OXjs2/sO8Gw4olhHn61qo0kf3DYqdJ7FhnHyoEiFIepZEy3HB O/UcZlqPSn86+OFaTZpZwdJf9eWYOdENUCNXrZ3gV31FEMzArues0SNQmjrbfa247+Np QUj+mpJLaPPxxwAqbjF+R3R41hgrWVF/ydx054zwTyKLv4nocK5z3Sp8/yt5dNNN+sit ZzCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=1Vo3DQpG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 128si9476733pgh.189.2018.04.08.00.01.54; Sun, 08 Apr 2018 00:02:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=1Vo3DQpG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751629AbeDHG7K (ORCPT + 99 others); Sun, 8 Apr 2018 02:59:10 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:34029 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750892AbeDHG7I (ORCPT ); Sun, 8 Apr 2018 02:59:08 -0400 Received: by mail-it0-f66.google.com with SMTP id t192-v6so8803351itc.1 for ; Sat, 07 Apr 2018 23:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=aVlUZcnNFq3nlcwbl+pxwyvwxgaZH3f4FPaaSeiW09A=; b=1Vo3DQpGQJO1HQ8aRlc11ZLUdxbAN86B0eVu4pOS+heaS/8BT17D8lH3BkSYuaCPtc iNvYk2roEu9rRDIt6mz4fYHcklqm84nZrR9cgy7yvuUzBq969ffBSLyBBQ9x9z4+XtX2 FlP5LwOSvG7yZ2KB3hSewabUqRkA+zWQ2mKU4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=aVlUZcnNFq3nlcwbl+pxwyvwxgaZH3f4FPaaSeiW09A=; b=K/KYy0WXr7Cy82eY9Vn/8s21bQlHDkTZ5fQ3OhH9pTvnEqMLmfbTJHkodaDPk82VnW 2dqD0fOeLPrhYdIp9LIv2phS6QtVvxM2tgF/U1x1tH43LzdkneWeh5an9t5zWrPoOa6P S3vWcZZoXxS5nc5iT6GSVRn2HjiuGIFHX5MtVOXhNhjhsFZFrhHQcxxTuvYuBnd9qIbW SNNvPDOxTlmf7lNkGex/+vR5agYipVWc9CO7SG1MizWQLav5gYAyWhAju8sIgsx7nV7q iG29pai27IsXEtaMAslk1pAFFEDCc21fN1XY80arXaEZMNqIjCiVk1Ubq4XR5AKgAjIt rWwQ== X-Gm-Message-State: ALQs6tCGr1Cvk/xivWDMJlsRYN/HRbyKzbA2JI41igaEmyaLQJR4nmCG I8S/GkabShg5b4tXF2J1NV4YSw== X-Received: by 2002:a24:45a2:: with SMTP id c34-v6mr25638368itd.31.1523170747766; Sat, 07 Apr 2018 23:59:07 -0700 (PDT) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id t25sm3672632ioc.50.2018.04.07.23.59.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Apr 2018 23:59:07 -0700 (PDT) Date: Sun, 8 Apr 2018 06:59:05 +0000 From: Sargun Dhillon To: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: penguin-kernel@i-love.sakura.ne.jp, casey@schaufler-ca.com, jmorris@namei.org, oiaohm@gmail.com, igor.stoppa@huawei.com Subject: [PATCH v5 0/1] Safe LSM (un)loading, and immutable hooks Message-ID: <20180408065902.GA2823@ircssh-2.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The primary security benefit of this patchset is the introduction of read-only hooks, even if some security modules have mutable hooks. Currently, if you have any LSMs with mutable hooks it will render all heads, and list nodes mutable. These are a prime place to attack because being able to manipulate those hooks is a way to bypass all LSMs easily and to create a persistent, covert channel to intercept nearly all calls. If LSMs have a model to be unloaded or are compiled as modules, they should mark themselves mutable at compile time, and use the LSM_HOOK_INIT_MUTABLE macro instead of the LSM_HOOK_INIT macro, so their hooks are on the mutable chain. There is a shares SRCU between all security hooks to facilitate safe LSM- unloading. This SRCU is very cheap for runtime overhead on reads, but there is synchronization around it for unloads. There is only a cost to pay at unload time, which is based on the execution time of longest chain of callbacks after synchronization begins. Because of all of this, we can now load LSMs at runtime, so those APIs are exposed. It is up to the module author to check if CONFIG_SECURITY_WRITABLE_HOOKS is enabled before trying to load. Even if this flag is set to true at compile time, to unload modules, the CONFIG_SECURITY_UNLOADABLE_MODULES flag must be enabled as well. This behaviour of allowing modules to unload at runtime can be can be disabled either at boot time or runtime by changing the security.allow_unload_hooks kernel parameter. Once module unloading is disabled, no longer will users be able to call delete_module on their LSM's LKM. It still allows LSMs themselves to trigger unloading, as to not break the existing (SELinux-utilized) API. Changes since: v4: * Introduce the configuration flag "CONFIG_SECURITY_UNLOADABLE_MODULES" to disable module unloading * Introduce the kernel parameter security.allow_unload_hooks v3: * Instead of taking the approach of a "null hook", using the approach of a second set of hooks -- this was mostly done through the FOR_EACH_SECURITY_HOOK_MUTABLE macro, which gets compiled out if CONFIG_SECURITY_WRITABLE_HOOKS is disabled. v2: * Split out hlist_head patch * Apply Tetsuo's changes to clean up functions which are not covered by call_int_hook / call_void_hook * Disable NULL hook checking when uneeded v1: * Add SRCU to allow for code-unloading * Add concurrency control around hook mutation Sargun Dhillon (1): security: Add mechanism to safely (un)load LSMs after boot time include/linux/lsm_hooks.h | 36 ++-- security/Kconfig | 13 +- security/security.c | 280 ++++++++++++++++++++++++++--- security/selinux/hooks.c | 448 ++++++++++++++++++++++++---------------------- 4 files changed, 518 insertions(+), 259 deletions(-) -- 2.14.1