Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp155189lqb; Fri, 15 Mar 2024 20:40:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUZ3RuEF8B9F8JaK9XgRly01D+YyJuOzz3yxvdUxXhkir2d99t+HP5Llv5kSm4S6T208brviJt9RuNycl/QtcI7QLSrW+414Ylw0jThQ== X-Google-Smtp-Source: AGHT+IHWDLJHaNG1H7eGo7v65lDOlEGNAuudiukGdAd+H2K4iGyflFaT8rl8oqdbkrh6zoSKeJs9 X-Received: by 2002:a17:902:f607:b0:1dc:d515:78db with SMTP id n7-20020a170902f60700b001dcd51578dbmr6057776plg.58.1710560405197; Fri, 15 Mar 2024 20:40:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710560405; cv=pass; d=google.com; s=arc-20160816; b=DEAWtrz77fnuFF4QAajyex6ml3daZYK/lBMFkmQQLfuH4yjT2D0qZVevW2ziENNwh9 Ny2k3Geked/344wcrsXuuprc7iRyd2NVGg0/2zBXvSUOpY65K4njrZ2AaSo8+AAti9pl MbqgaNqTJsPIyzaK6ev01edIIlKeinac0VGjcQBtiq6Ppf4Ko/L4zxSj7ZeaDoyubSOl huPrigpsqhP49SHG44fuS016Z/ZKi7Zkjf3bp4fHKsRParUVuen7i5U8jjvGmdRA6Q+6 SNetkr5sR53SWH47bqF4oS08JN7FweLXeQzM0F/FWpHiaj7xhA1snhITnRmqnMReKuDC 6uEg== 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=XUFAeDoQu4MS45dwITDdpPTQllJiUB3rkbOaO7Uw83U=; fh=AghapWq4JPbtw/+GjhWyKvJDXDWh1etonmqDYgtmcRM=; b=jbLUFAxZamrMy5wcD/hBmbcuEMPjmsz//B//JwYeV0fU3P5f2kfKGHoFjCei6tkGAY jHljQCBm1tR1/gTVpEUEQBYlqB4sUzRFcEMRDSJhL9/YGDi3KR46avP1GNxcqbozJQWT 2vTq3BZjRihVmeOzb/6bDtQw/bCCUL3Wb3JbacG/a+l+ax0NlExah8xNdtOR+bkX+EIF 8R8+ki2vsyFo8mKLyHtmv3pJcZNBNCpPa1BlswbP9/4u7PIQoAkkAlpM04rB2WYzwhJP r1eayvVnEkroQm+XAZHiFeING7chs4qT/KH/2/3syM7PJnoZz4NC7chn+giqeY4Z6tR/ XFGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=C+bfmT1X; 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-105052-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105052-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 x12-20020a170902a38c00b001deff843d5fsi1057558pla.12.2024.03.15.20.40.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 20:40:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105052-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=C+bfmT1X; 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-105052-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105052-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 DA709282EE2 for ; Sat, 16 Mar 2024 03:40:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D20A42052; Sat, 16 Mar 2024 03:36:05 +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="C+bfmT1X" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C64B5221; Sat, 16 Mar 2024 03:35:56 +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=1710560158; cv=none; b=OZCb5s0ZlY0T3yRHpPdtkeG6IjyHo0SggoRwFfqSWRu2vCJdx88HU4moD3V/GpPhoAiZ+pyVxuYtXo0KJ22cG8iB3RT1LqlCsW48+FCa6AP6DMwQhPHHy0mInflNMUFRPaU12WsRN8vJkVz9ueKq+PO5JDZtLJKgRn2d6XTm0Ss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710560158; c=relaxed/simple; bh=PkdGWqPXZdv2BNylhvbB7CCtderTbMk5DulNNSY1DlM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Dm96ozFVJijEvEevqSCSlIO6tbx4FJON+Hi7ke4O0omJ2jZ8J04/VEm0/1xR50bj37D/iCV0ld6JHleuxvgYNGq6nzXOZ1Ks1z8mwzPLlmwWv1iN+Io0otxkORtnNTmly02UUE23TS/3fkS1arAANtVDgymGUTAtRWOm6GPS5g8= 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=C+bfmT1X; 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 7474D20B74C9; Fri, 15 Mar 2024 20:35:53 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7474D20B74C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1710560153; bh=XUFAeDoQu4MS45dwITDdpPTQllJiUB3rkbOaO7Uw83U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C+bfmT1X69h7uTpuDDHKUmtnAXo4UMKsJrvCB+I54jUQ5A9MGCIaDUI+MBFJwh4Tx zDp2HWyIloFD6e55i+yFA9jZoiKwDwkXi0dcHjb58CnxJ1Fz+88YdxPS7IYm4R+kBB xJ7eEv7qkSTkpuqIWzW6YRh+vDf8aIN4HTdUTVDY= 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, 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: [RFC PATCH v15 05/21] initramfs|security: Add a security hook to do_populate_rootfs() Date: Fri, 15 Mar 2024 20:35:35 -0700 Message-Id: <1710560151-28904-6-git-send-email-wufan@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1710560151-28904-1-git-send-email-wufan@linux.microsoft.com> References: <1710560151-28904-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 --- 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 334e00efbde4..7db99ae75651 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -450,3 +450,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 41a8f667bdfa..14fff542f2e3 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 da79760b8be3..cc9115117896 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "do_mounts.h" @@ -719,6 +720,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 287bfac6b471..b10230c51c0b 100644 --- a/security/security.c +++ b/security/security.c @@ -5675,3 +5675,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