Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp264532lqp; Fri, 12 Apr 2024 17:59:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfD/LroKpx9VtF5D8+DHg39Arrwx6Xz8+v1HRFqBMt5vqonCOltc41NwZjS8q8zq4F4T9Cx6LLyIOCGwoH3vytTZAQPLGSoNhTcifbfA== X-Google-Smtp-Source: AGHT+IELGHQU5h8YSJRReJtgYAsdkCB0Y1+49CrPjbfY9SElV/zLJqhfcpA82DRnEAd21qkbMdLK X-Received: by 2002:a05:6a00:3a0e:b0:6ea:ad5e:f4b3 with SMTP id fj14-20020a056a003a0e00b006eaad5ef4b3mr5639132pfb.23.1712969977213; Fri, 12 Apr 2024 17:59:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712969977; cv=pass; d=google.com; s=arc-20160816; b=BiwNdcXfODx4rkTJ4Ck4hBr+u91Rr1SQeozvhzfqsCDo45CZxaCGPUpXlWlBDo34N+ tS6FL5L7Z/GlPUwy5Q7cvm1PX29i+yYqreg4shndObjm7AVEridPfTvySHMYoZkduQdX egluQhqnj2MCw4idBe4HD80jez1eaA48TA/TgJyTXsnaIi76hSw5o3++Ehml0R9CrLdb FCnAt1FF73ZPzFJpFTJlJggqGcBrJwFZwaLK9Wdg+hlcr87wl0Q3ytHHaw+5R9C1Jig8 GnzRrswa5QKhbFcUusefKo1Vfg4TYVHGpy7bZRkXbSgn8J2cVTANtOyR5CnA2qDwzUE8 GZSA== 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=CBTFK3KrsGTrn+prErhAJwRVbssSwYdjlBDBKa+A8D4=; fh=AghapWq4JPbtw/+GjhWyKvJDXDWh1etonmqDYgtmcRM=; b=mr1UPifi3nF0BQaiEpimsaon9zyxIDr3VI4wMx0yFEi0mI3s2GoDfGANN3Rl6XjcID xUDBR6BDmM37H/+FeLXwVwK8908fL/pV4ZYJEMmSTGFhW48KRLbcIoFl3gDtbmtJq+1f 3QXEVzZMY/Zvzkb8hiqH7tFWN+cT8JpLJlnnlc1Tyc2BQbNd+xM6LWLZEJYAF++DbG+Y c9SgUba5Hg99olsf4DDs4imgVpH7f5q72UlrK31HlXcVx+rtraQoy84BGHQNpzASgiYk FZjOtUnFaI0BobWhsChqVXYwNshCN4BVf0nvx7/bVngD9B2Zps7GIEg9Y34qUDTSIi+v g+Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=WFNjQuOg; 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-143467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143467-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 s80-20020a632c53000000b005db9566a62fsi4147574pgs.697.2024.04.12.17.59.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:59:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143467-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=WFNjQuOg; 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-143467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143467-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 DC16B284805 for ; Sat, 13 Apr 2024 00:59:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1979156B66; Sat, 13 Apr 2024 00:56:17 +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="WFNjQuOg" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD41163C8; Sat, 13 Apr 2024 00:56:07 +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=1712969769; cv=none; b=Y6nI+SjZghLzKaeR6qkbWYKnovRryzzTXpGoOrUxcndhSd+xf0PSnBSVhbxioTslJJshX/qqrBs7xGW/GB7RQ6mtCwZHEGxVB/mexnqrbmIJqpG+0FeWJ/kLPIhxRgeDms1OOvLS+ucJ+YRYzAAzvDpjPbT0UP81BXj7GW3DPjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712969769; c=relaxed/simple; bh=m5Kz6kJ4CrfXX6/Z5HMC0WcjyIrA1GmlYuyeYtJlPUs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=SdOSJX2dXU0TNq5gdzEvXH3GAwGyHkvHlIUjzvwh7pbMDMbLBwK3H6AoGAKaaEc+JlVJBjH8/hoB0x4XiYMsUrAkN8risN74CUzf+NgFbPHR71KqbwNnXntzYJid1Mbw5UA4OcmeKzwWOL6RTMNRaQvtbpGSuUnd7LuM6OURspE= 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=WFNjQuOg; 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 BD1D620F32BE; Fri, 12 Apr 2024 17:56:05 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BD1D620F32BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1712969765; bh=CBTFK3KrsGTrn+prErhAJwRVbssSwYdjlBDBKa+A8D4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WFNjQuOgT1a1n3gXogI2Xbc1we2gO7L+g8jTdOWyrjP5EYMlEwUxfztQxpDZIk/Jb UDFStxSWQdQ1yv5R1aGSoXPfMNtpF6VxPHPck78yADdS+RLZbGuC3j62mghOEsPVXe 0BOnVPTFttWX0nRP+MnnTX1OV7UWpVbKEaJKRIJU= 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: [PATCH v17 05/21] initramfs|security: Add a security hook to do_populate_rootfs() Date: Fri, 12 Apr 2024 17:55:48 -0700 Message-Id: <1712969764-31039-6-git-send-email-wufan@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1712969764-31039-1-git-send-email-wufan@linux.microsoft.com> References: <1712969764-31039-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 --- 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 a298a3854a80..feedb47d0f55 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 820e0d437452..0db5a6b32aab 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