Received: by 10.213.65.68 with SMTP id h4csp1195734imn; Sat, 31 Mar 2018 22:44:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/r4qE827BoNWqnm25zzy2skEE3VogAZMCUfHTp2yk8dspHvNtTWcA2IcSMhUEG1/HR14KY X-Received: by 10.99.178.88 with SMTP id t24mr3395201pgo.212.1522561474693; Sat, 31 Mar 2018 22:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522561474; cv=none; d=google.com; s=arc-20160816; b=W+q/17kBnIZUkWVghdcjXquFRZdnGkVCFhJB18i+C1XDSP3fhL6OixaQW2+IPvkpjv g22pIdV+y0pK+gcgbtaRaPfPv728zkjlFgP5Cid8FCDkwdPHuR1l61as2Y0qBrROI8Su 8kfkZ/1jpbapxzRSSrFsx7exitfBsYRF5JFycneI9ZN56504qiQmuKTWaEvZYMssOCGh QD3+B6JEV/KqrRH3KjTlmz2uwO8UOhjGDlBQDmpdHrfNtK3HenUQd8CEQOgHgTVTiJiR Rbe1xrEo7lgYLs9t8KqkBa2XoVaQ8/9TgJwCLWACe0chF50h962c/9O26gbwBytfWk4R fhEg== 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=8Yo8rprJab+JAqQlAWWHcKAavxZ7LGNTKPnBh1aRIbs=; b=z7C8rDi5YlM1VnXURUMHM01KKDJ6zIigfKCbbQwfCd8TOlpMAvoyZQqMo1gAsiUpMK u6rhJZRRwg91ukVlltpcoepG9+INhj/YadaMCkeZMmf6qUiubYG8jdOvSeYrhtTT+spB ZOMBmL4RPSETQhszNd+YHdhSc8zThiGdsvHIWrVYECAjssq5BMNhU1Wu0J/0OhnzlS2q bBORLKI8qQX/B8NPSZlzHiSBqFVL61y4zC6d808QCdRuuJfPC2l+rHo41ZrLW+hjSMIM N0JGa/OIAWnVHP8diVyOKZitLf91elSOSXGQXBhuHKxsbVALC+zITcrY320i7T2WZ+9p lV/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=SL5SRscT; 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 i35-v6si7291615plg.504.2018.03.31.22.43.53; Sat, 31 Mar 2018 22:44:34 -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=SL5SRscT; 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 S1750910AbeDAFlG (ORCPT + 99 others); Sun, 1 Apr 2018 01:41:06 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:45567 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbeDAFlE (ORCPT ); Sun, 1 Apr 2018 01:41:04 -0400 Received: by mail-io0-f195.google.com with SMTP id 141so14865614iou.12 for ; Sat, 31 Mar 2018 22:41:04 -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=8Yo8rprJab+JAqQlAWWHcKAavxZ7LGNTKPnBh1aRIbs=; b=SL5SRscTautRD22Q6QDqDI5WfVYaBtxD59fEL8vR9EeQ0x/m1kvr43LFh79xWCnjn7 pCYoqYw35k/hau9M7M0mWdXYaKhgup0IX7x/eRsdBhT5bPFcwwwCcL5LZLtxUcpCyYbS j9/qYXIGsREa7Lc3dBCTDP/ozjRefHWpwTxfM= 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=8Yo8rprJab+JAqQlAWWHcKAavxZ7LGNTKPnBh1aRIbs=; b=IIxhnx+ZCRl6utayPac1y8mGJZ4fhm4fejt0Oq/LOOhCGtHUi+5igc2O+7hEQ8BiAF 5buRFzoqISwjMRPn8Flan0BQ8HqkP4YkoOp2nEB43Hn5is7qEyck9GQzSTzNhBZbo+He GNjorhvNgRQ9Osp9I8l5xgxOKHofaPXkni5GtS8TstkcwallY+q3KqUtI6YyG3WAonyW tjl38kDfkM15wtVL4e1Y83qFvxRx3UqkqL2kYCRwlQqth9/UV3rDvcwTVjliIQifFeYq AJb8UBG7iMlpRLKHTaZeRu94hYT/dzPHQSxnxvtA8+SidtEYlOTBr48Pjd5ZShMF0dhD yd6g== X-Gm-Message-State: ALQs6tBp/uSzV2SIh717tcHArHlDveclhvNESHPmlX0xh3auOOEFxiJ9 xhxIwPSHb+GJTPDWMExY9F0Vhg== X-Received: by 10.107.59.8 with SMTP id i8mr4361369ioa.110.1522561263911; Sat, 31 Mar 2018 22:41:03 -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 15-v6sm4076031iti.9.2018.03.31.22.41.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Mar 2018 22:41:03 -0700 (PDT) Date: Sun, 1 Apr 2018 05:41:01 +0000 From: Sargun Dhillon To: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: penguin-kernel@i-love.sakura.ne.jp, keescook@chromium.org, igor.stoppa@huawei.com, casey@schaufler-ca.com, jmorris@namei.org, sds@tycho.nsa.gov, paul@paul-moore.com, plautrba@redhat.com Subject: [PATCH v4 0/1] Safe LSM (un)loading, and immutable hooks Message-ID: 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 biggest 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 compled 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. In order to provide safe code-unloading, there is a shared SRCU between all security hooks. 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 prior to trying to load. Thanks to Casey to providing great feedback on the patchset. Changes since: 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 | 24 +-- security/Kconfig | 2 +- security/security.c | 206 ++++++++++++++++++--- security/selinux/hooks.c | 451 ++++++++++++++++++++++++---------------------- 4 files changed, 424 insertions(+), 259 deletions(-) -- 2.14.1