Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp570130ybg; Tue, 28 Jul 2020 13:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxffkbUXvPVXB+oiUNM54S9Dg82TVLceNE761QFLjiNeElKgCpoqf1joxVLvmMvyXhBYa8h X-Received: by 2002:a05:6402:b1a:: with SMTP id bm26mr27254586edb.144.1595966682258; Tue, 28 Jul 2020 13:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595966682; cv=none; d=google.com; s=arc-20160816; b=Fc8zjhgOEj6lvOXYkZQDB1e/aVnfh986JXsHGLWwUT+9jUI8v392chrIki7pO8k1Tx +3Ux1KcleZib8+5522IM6KiiT5JRWyAnc1nMU0laEldFWo1qQP5BCKfDmEPyHOAf6O1B tALuSv2CmexSI56hiyY6OpOUkoA7x3sUdL+AeJxUCLiSTFlEzGZigoa57pWoHM3eDeL/ o8NvIu16DZRqaPHz/4xbR411GdqscaXJ92AbvFninypSclzPVGYeOqLgNKze+psu2N4J 5tX9vuF2V6upZy4YSDWXXeIWLGdqfIB40ysuAh2dAnwwFLyRM1nfzjicb2tRakvLNLjr ObEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W/yJD4WINhIYjHDSpnZ6fTxiwzLWXNf1PH2+o88F2eI=; b=rPIq+IAmh9T29QLZUZgm0zQt5AaZoq4nEnYUb43ffWWyGL596HfbmO7qZYCaeLRa3L W0tefHjpIX44AFUASNaTTJ93XAUtObp8avd+RDtlcKEYt0HUCDxKpqQbU99+/M1xInKj p18tGsSzuXZ2cyg3zVKYj0ORD4SnM/ITJnMMUJR22YTaB2D9mxydqJCQyVNBhJil+V5d xHWwbhQ1Ig09TgkGEDkVJkadLtV95OmUiv6s/G95FLTdn3XN3JJB2dE/yht3E1PlK+QX qcPdwjiQnZNkCdiHJZxr8yzWN1QlJWtKsPw5w7P73c0D5Bn+j+1ZNfoD6g2j1qzsEeC5 VHkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k5XgwmE9; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si7727051ejz.248.2020.07.28.13.04.20; Tue, 28 Jul 2020 13:04:42 -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=@chromium.org header.s=google header.b=k5XgwmE9; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732923AbgG1Tlr (ORCPT + 99 others); Tue, 28 Jul 2020 15:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732919AbgG1Tlp (ORCPT ); Tue, 28 Jul 2020 15:41:45 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 798F2C0619D6 for ; Tue, 28 Jul 2020 12:41:45 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id k1so459655pjt.5 for ; Tue, 28 Jul 2020 12:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=W/yJD4WINhIYjHDSpnZ6fTxiwzLWXNf1PH2+o88F2eI=; b=k5XgwmE9tcOSmpNhY4WIUOwltfP1nOlJSUDS0n99vkcl8B8YnMUbPDxe7YGTs1mMQr 76iSMntY5i+fw5H/RDUwlQ0I8nd8NuTI/QS+tkBn1s8zi+fMQktc83D3xj8tuEDdbWc1 SPGIc7GDjQULMKCEbKzwKWRabOT0dDEOWSj6w= 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:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=W/yJD4WINhIYjHDSpnZ6fTxiwzLWXNf1PH2+o88F2eI=; b=EtUaZiWgx4fiJJhxFgxJqUshKxBnwUp6ooxPXUaJl0bA3hI9KKeYCU8G3jyfbIvzpu mnIaCn22CO97835xTXFasikm4vydizlyv4bfAFPGPw4ISz6koyoDXFw+Tj560FmoM2uh N4G8TZRjcuKqzRG+3i/f9YYF7rK+FR+zX7TJbDUMr3yCiWg0ytewvvdJLzSbnUZX0Vqv cMTOGP/+HMz92GDTSNfUfdv6etz3aUz2lLfGx8URlxmXSfj+aDtRhl6PcqBRftg3QAta Q7LEXp6bj0lJeZxbgI2Rf7I8GM6KObFqL4Yf5l1AAphOWcuW7fqPC/Tq2JOnLG6EtrZi S/2g== X-Gm-Message-State: AOAM533z7OgRLosMtkWpj0jmrxkVVZKkeJYaF2yNuI0SoPq3bEwMvDE2 6KySI5eBicBEg6UppXxHjS2P5g== X-Received: by 2002:a17:902:7244:: with SMTP id c4mr2350434pll.277.1595965304901; Tue, 28 Jul 2020 12:41:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j36sm19509082pgj.39.2020.07.28.12.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 12:41:43 -0700 (PDT) Date: Tue, 28 Jul 2020 12:41:42 -0700 From: Kees Cook To: Mimi Zohar Cc: Greg Kroah-Hartman , Scott Branden , Luis Chamberlain , Jessica Yu , SeongJae Park , KP Singh , linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 11/19] LSM: Introduce kernel_post_load_data() hook Message-ID: <202007281240.4EDD6D2E7B@keescook> References: <20200724213640.389191-1-keescook@chromium.org> <20200724213640.389191-12-keescook@chromium.org> <1595846951.4841.61.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1595846951.4841.61.camel@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 06:49:11AM -0400, Mimi Zohar wrote: > On Fri, 2020-07-24 at 14:36 -0700, Kees Cook wrote: > > There are a few places in the kernel where LSMs would like to have > > visibility into the contents of a kernel buffer that has been loaded or > > read. While security_kernel_post_read_file() (which includes the > > buffer) exists as a pairing for security_kernel_read_file(), no such > > hook exists to pair with security_kernel_load_data(). > > > > Earlier proposals for just using security_kernel_post_read_file() with a > > NULL file argument were rejected (i.e. "file" should always be valid for > > the security_..._file hooks, but it appears at least one case was > > left in the kernel during earlier refactoring. (This will be fixed in > > a subsequent patch.) > > > > Since not all cases of security_kernel_load_data() can have a single > > contiguous buffer made available to the LSM hook (e.g. kexec image > > segments are separately loaded), there needs to be a way for the LSM to > > reason about its expectations of the hook coverage. In order to handle > > this, add a "contents" argument to the "kernel_load_data" hook that > > indicates if the newly added "kernel_post_load_data" hook will be called > > with the full contents once loaded. That way, LSMs requiring full contents > > can choose to unilaterally reject "kernel_load_data" with contents=false > > (which is effectively the existing hook coverage), but when contents=true > > they can allow it and later evaluate the "kernel_post_load_data" hook > > once the buffer is loaded. > > > > With this change, LSMs can gain coverage over non-file-backed data loads > > (e.g. init_module(2) and firmware userspace helper), which will happen > > in subsequent patches. > > > > Additionally prepare IMA to start processing these cases. > > > > Signed-off-by: Kees Cook > > At least from an IMA perspective, the original > security_kernel_load_data() hook was defined in order to prevent > certain syscalls - init_module, kexec_load - and loading firmware via > sysfs. ?The resulting error messages were generic. > ?? > Unlike security_kernel_load_data(), security_kernel_post_load_data() > is meant to be used, but without a file desciptor specific > information, like the filename associated with the buffer, is missing. > ?Having the filename isn't actually necessary for verifying the > appended signature, but it is needed for auditing signature > verification failures and including in the IMA measurement list. Right -- I'm open to ideas on this, but as it stands, other LSMs (e.g. BPF LSM) can benefit from the security_kernel_post_load_data() to examine the contents, etc. Is there anything that needs to change in this patch? -- Kees Cook