Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp801738lqb; Fri, 24 May 2024 13:50:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqPgk+iUgAfqMhC3gUn8AoCKCZmg+lxdusRAMhpHaOY9JzQQFPq+54W+wUfIEqT3XUDZPBCWaZy2J/grEM1dlquzoAOfb2N1FODiz12Q== X-Google-Smtp-Source: AGHT+IHmpJOl227dGh/oGXbKfwUttYe5Ak+kz7+f7544p3PVvDJDSUwtT+k9pJwmsb6OfntBNFF9 X-Received: by 2002:a05:6a21:3994:b0:1b2:a69:f68f with SMTP id adf61e73a8af0-1b212b774dbmr4397737637.0.1716583803804; Fri, 24 May 2024 13:50:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716583803; cv=pass; d=google.com; s=arc-20160816; b=cKBx6v1UI/Lzs4u/9Ke9bxDBQDRaqVu5vRcbSC4HzM5fM6Cz+H23EJvHUU09NeVLw5 +42BCOhCGy4RjJPHQPpl3MKc0spF4+ecDf9si6f+oJd2jHLT1MCcjlkHBOomZdz9wbsB rYe9+uZxaS+KB8kXTNnNP8WYOeQv25w1LSXb1OIxwsrD+IUsBkuP1UOqM5/GU14uXmcr peF1gBj7QTzwnxhjVTXYl1YOB9tcs5ELxZx2mRANu2Z8IHBDJh4q46LRO83YhKuFK+ea KBkvwlSoGgBXtsMo0ktemL5nqPHE85ACBPvPKsSzywP5r6QBXnRruauIIsmOgcpSZ86K nDoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=W/H9mE8XSjBve9No8rLIcvhirJdJGHgqkLIeqqsizvc=; fh=OlkHRnschcmalg77Gt0o0+JloawjlN2zARXEVTidFzI=; b=uxxOAvEO4TBVSBdCEOVJFqqhp7u+P6Lie5ZcomiB1kLPzHObedwp/Yc6o1U8vA9LZq r3xGIKvLoeO1ukhzRjEuf1uedgFsatQtHWGrYfoaydh7KwH4zIb7lRUZVhXt1HAcsyKE cCwaz2+4pIn6RMhgn4WQEbywUHDNmenp8UzbKI4w3mIGI4XyxvOizHFEII9zjITCWzxc MUZICqG/2M68ZcLgQAPqs/OlGeqYnKM11C8F/x3BHKwN3In2C4bWPerUBqogJMTJwlq0 OFCDlhfKK6UDSeAF8uZYp3YXkxnjsZvAFx57OaFY7b7xmT76wCO0cTrO4b5Dvs49nLyW BBbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="pbl1jry/"; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-189104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-682288e6836si1850605a12.491.2024.05.24.13.50.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 13:50:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="pbl1jry/"; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-189104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6A0562824CA for ; Fri, 24 May 2024 20:50:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0008131756; Fri, 24 May 2024 20:47:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="pbl1jry/" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48BF486621; Fri, 24 May 2024 20:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716583621; cv=none; b=Z1vPSEDZlq+ic10IP2hxmA5LxjWVhxWJWIg6SO5Urh7PbNrNaclfMV86sNNQv/Qa3bvatJDb3iW/bgEv6rHJWRw9sM5otu5g7t06yZTELDO5sPeV45XWF6BpFQHV7uIWe98d3hqB9nK5Kq+/8fKzKS1/CYImH9VmEe7RZuAyIzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716583621; c=relaxed/simple; bh=Pz6gAsd+oNjMtMjNBdaGsyTanurgBtx/hsmruxHPvv0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=hPoqopiCMeNn8NeVn58j0qMtIzhTeLZEqb9wwwPWQBnBvbG8CqEmonNRIUgj4C0K0202oMW13PEZiwDhvMW0nfYK4XEP6ncI5x46gzJIBTiRQjlKf4vjDg7F4q/I+eTh828lAeOTodDdl86zMj+wclqsQ7wQ4hqv2nE6CwRa1L0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=pbl1jry/; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1052) id 670242067B4F; Fri, 24 May 2024 13:46:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 670242067B4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1716583611; bh=W/H9mE8XSjBve9No8rLIcvhirJdJGHgqkLIeqqsizvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pbl1jry/Zn2ms04Urn4Csos9l7/aQkBTa4k5xYRQCluYXX9gwql5LF0MMyeygjtOa NAi/ppodTgKFG6svQgBOdpoL8tG4JPhNkGFE02UYvNqunR8Cl5A3e0Ks0KYfXgNkd7 tdRfwXJ14ht0qayABm/BGC6G5UFvTzxuOIJifHrc= From: Fan Wu To: corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, eparis@redhat.com, paul@paul-moore.com Cc: linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, fsverity@lists.linux.dev, linux-block@vger.kernel.org, dm-devel@lists.linux.dev, audit@vger.kernel.org, linux-kernel@vger.kernel.org, Fan Wu Subject: [PATCH v19 05/20] initramfs|security: Add a security hook to do_populate_rootfs() Date: Fri, 24 May 2024 13:46:34 -0700 Message-Id: <1716583609-21790-6-git-send-email-wufan@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1716583609-21790-1-git-send-email-wufan@linux.microsoft.com> References: <1716583609-21790-1-git-send-email-wufan@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This patch introduces a new hook to notify security system that the content of initramfs has been unpacked into the rootfs. Upon receiving this notification, the security system can activate a policy to allow only files that originated from the initramfs to execute or load into kernel during the early stages of booting. This approach is crucial for minimizing the attack surface by ensuring that only trusted files from the initramfs are operational in the critical boot phase. Signed-off-by: Fan Wu --- v1-v11: + Not present v12: + Introduced v13: + Rename the hook name to initramfs_populated() v14: + No changes v15: + No changes v16: + No changes v17: + Fix ocumentation style issues v18: + No changes v19: + No changes --- include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 8 ++++++++ init/initramfs.c | 3 +++ security/security.c | 10 ++++++++++ 4 files changed, 23 insertions(+) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index f804b76cde44..040d046ba92c 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -451,3 +451,5 @@ LSM_HOOK(int, 0, uring_override_creds, const struct cred *new) LSM_HOOK(int, 0, uring_sqpoll, void) LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd) #endif /* CONFIG_IO_URING */ + +LSM_HOOK(void, LSM_RET_VOID, initramfs_populated, void) diff --git a/include/linux/security.h b/include/linux/security.h index 21cf70346b33..2caa4c9b81ff 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -2255,4 +2255,12 @@ static inline int security_uring_cmd(struct io_uring_cmd *ioucmd) #endif /* CONFIG_SECURITY */ #endif /* CONFIG_IO_URING */ +#ifdef CONFIG_SECURITY +extern void security_initramfs_populated(void); +#else +static inline void security_initramfs_populated(void) +{ +} +#endif /* CONFIG_SECURITY */ + #endif /* ! __LINUX_SECURITY_H */ diff --git a/init/initramfs.c b/init/initramfs.c index 814241b64827..64c59dd67d26 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "do_mounts.h" @@ -711,6 +712,8 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) #endif } + security_initramfs_populated(); + done: /* * If the initrd region is overlapped with crashkernel reserved region, diff --git a/security/security.c b/security/security.c index 2b7c18a1a2af..b419166979da 100644 --- a/security/security.c +++ b/security/security.c @@ -5676,3 +5676,13 @@ int security_uring_cmd(struct io_uring_cmd *ioucmd) return call_int_hook(uring_cmd, ioucmd); } #endif /* CONFIG_IO_URING */ + +/** + * security_initramfs_populated() - Notify LSMs that initramfs has been loaded + * + * Tells the LSMs the initramfs has been unpacked into the rootfs. + */ +void security_initramfs_populated(void) +{ + call_void_hook(initramfs_populated); +} -- 2.44.0