Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1615942rdb; Sat, 3 Feb 2024 14:25:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNxzZoaH41tyv2l2YEKxxg8UryajJQPzHsbwqrQm88jdGUMkQkZduC9ColIRdS1IRNIiip X-Received: by 2002:a05:6a20:2a0f:b0:19e:30b0:6ad4 with SMTP id e15-20020a056a202a0f00b0019e30b06ad4mr9224209pzh.55.1706999130850; Sat, 03 Feb 2024 14:25:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706999130; cv=pass; d=google.com; s=arc-20160816; b=i8U8LjTsjMgFFpk4FzMR78bhVY2C8SNrvFDF8Gl9eEeEz6oSdYsJBvpNonCRpS/DFS bCxdPP2R4dxRHC4ntsx2u6ddWg89WzSl1XHSqb/J0MC8VTgqGL24Q3tcI6O8pSRf4gkn L7Wd10WKEzSrpecvsPaC9DuHxIvjinuaoSpqvXsMbgaVPO+Z7pxcSgnaTE9erkOA6L1p pxPOHG4h7m5ELlQ90758Y4XjqmRvPgi1afkWs/iCmj5YXQ3fHi9yc0laP074iJWnsiFw vmfg/ZOqVFbFJtUhLUWIAd7vhjqLwtZNkXg/00q6KmjxiEHFHCbihme3h9cJqyvndIhU GkKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=DnWesDs8xRNqrKgsSJ7fCUj/XnlBG4IvaiEQPBxCK/I=; fh=QGr4ViTFzTBn8IsrNKaVqJ27Ygg1gQJszLhzM4v2MXY=; b=hZH7vz4xrM0g4a366JvmRCnWezUH7pTmbGfee1Zbco85kMYUuBnArG9qvT3cBEZh9f +ZY8pBY/rONDaZrrGXshD8sL47i673q89mXUIEy05SRkXmEC5tiTQyERgpHRrGEJujyN kS/wKlObEWQh/1YGqQ4MZNJWkXbcaJ7PlStDKcj28sv84rzIZvFzSo59UkCX0MLDJrKm ikpBs1l0geR9GM1YXtzY1riyUPHOu6ySkG6rvlXFW19twIUetcT+KgAPnQY413PAdbyA GOXhR8KxTLJG1nqNz6U3KR67qaMhB0dJoq08BmaxXpgvTX5/e0HEIERvhhEbq+Aq4wSn W6Bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=UslhFOVg; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-51309-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com X-Forwarded-Encrypted: i=1; AJvYcCXAXzpirGIYHGN+ydOQRNag2XnyssxzkvM9Z+hKQG+0ziRVB/3MOrjj7OfT/Uo09hXJlAYhUoM1ErCW8v+ymEvX3bg8KCecZf99fHwB7Q== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id g14-20020a62e30e000000b006e035133b6bsi590513pfh.247.2024.02.03.14.25.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 14:25:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51309-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=UslhFOVg; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-51309-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.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 7EA9E2847BD for ; Sat, 3 Feb 2024 22:25:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6DF217571; Sat, 3 Feb 2024 22:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="UslhFOVg" Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89851134D2 for ; Sat, 3 Feb 2024 22:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706999112; cv=none; b=QP9JbB0+ZP/DNgnJfedERtA+yogTMVZtyd/RY+XhZJ4tCbvObMZLtUqCr65mpzabIPla7API0SmT33NpQnrTU0/qfvZcvV5BRNrmtBvslehJKsvX1xHDFmRohP5PAbradDTpN+nOnpjDnxZjHt0RPCmPguzyCOXwL8HsTasbAT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706999112; c=relaxed/simple; bh=Akk3yfd0skBsyfpDvBuTijI4DTSE1uDMrPs5axVSpcY=; h=Date:Message-ID:MIME-Version:Content-Type:Content-Disposition: From:To:Cc:Subject:References:In-Reply-To; b=fYdnHq/LfuPA2FZ5wJlniTJdTXmV6m3IzQNXMho4+4azVxPM1N34yAF9Ye5C2seI01vr9HxpVZRlExhvstNd9Qp+pObJPBKWrha3MfMe19ctInSRvBLvt8u0FXzyAsKAaWR317iXFnrMEkDTbrY1MDd3wpURlU7oKx7zhzpxaX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=UslhFOVg; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7853fcc314bso218479085a.1 for ; Sat, 03 Feb 2024 14:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1706999109; x=1707603909; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-disposition:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=DnWesDs8xRNqrKgsSJ7fCUj/XnlBG4IvaiEQPBxCK/I=; b=UslhFOVg8WFUzqld2FRyTxItmLSnj0ByEQAtAEokRfNrtL65h4jolouj4Q0KaXgy7I dwWBbtq75NLmwEzjqHnxX6ovf74HGb/+eQ1u5u3cDuR962nRMBIQAHO2pklMJs5VEtFF J2KCZKGZqiH1GAnqMx/jR6Kw1zADG154LUO/sPqRF9z5CqmPx0YjEUQsIW35qgmWb16q 3UaVjFXAR/V/Ibmrl6bz95E4lv1HC+gW2jdbko6h6uNedJrm2Y8zlf0v1gBV7qgbdbqz HidKBzGH5j3uX3pnyQRpaiw5EN+leF/d42mepu7qrwQGlfYFPxBsNV0AKjK0W8M46hI/ AMkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706999109; x=1707603909; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-disposition:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DnWesDs8xRNqrKgsSJ7fCUj/XnlBG4IvaiEQPBxCK/I=; b=goHcr5rnMsFU277YybG5O9n4qNtPgNORqPG6vod0Syv1E0UQV+AhKBsiU405GfMjIv KPZkN1B3e4Ei4GmVRIjlptSrPW7gdPbUtFhbYOuUXgS5ZiP1MyGCIsufMFPBd+UMyqeq cis442Pi1AL8YSJgBbuhZLnO4lTNQ2QUyeCmff5ab39Qes7wciMwrdiOiG2rIe7OURF9 FT2zYEdtzQte6Tcd0XMKka58Rmp9DUfO0rcoqI5Y0+YWDdFSMXdL3DpPF/1atqbJjv9n PzMG+hHm8OGbi6xHH4Uyhu1KH9HQlNHTot5kYDQxt9AJpmbX8nXECV6+kXye/QavmDdE bQrA== X-Gm-Message-State: AOJu0Yzawb75nSxO7wfnJgs8qehqGdzwzJ0h10R+nwmkOVqZ1uhmYe8D idlZHURrZVP3/xcPPfHWtygelivqwVaBOO8bXGcIeJBJ7Uy82PgVED0druZs3g== X-Received: by 2002:a05:620a:2e3:b0:783:b038:d1a1 with SMTP id a3-20020a05620a02e300b00783b038d1a1mr9095773qko.39.1706999109324; Sat, 03 Feb 2024 14:25:09 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVwYaZbKyqip0VIR8GONQxXUcX8op8aMPNo2Ap1p+jdcI0F9O4QdFtfkXUh2izlay/UPxQX4uTdUnml1eWFaVIu3sl4cZN0o9MEZYPtDzuPUBt8ISFeQUgk//7oOgSqTo+LWz7pHI783WZUe7avWlFl2g4RV0ALfs6fSYnt9PmcP3V5e5UUC9OHfUN1hGOhFCEIHdwZdid79pfUdFyuN0HQ1asimEWyLDwYPGdfmyK0n3vX204PQ6L6I7qS+XYcc2+4FDbFfrLjHojE/EkYwAYSDsPcTayfqX5R0GGth4PTwEABerphUsn9JY6Cz1DdD0rhuTOjEi/XLpHp1AvDca0BRlY13p7V9uUBl5XxTmPDaaLTbmdbuj1e2I3b+GHRn4+Guw1TVTp0wlUYUAdXRnJPf1jp9/Mte8sgyYSGDJVgBLodRU8oGcMpA5MLWsHMPY5+8w5xv6eKGe3vsfBvHJH92nrGbL7ODZl7dWe1CNUDc7uQPTJqnToEqjD5Yl1fzWFBuCEy7dobme80FhUuQ9F8QqZX8GC19w5DGqXnrHRf6FF81Ob58I7Z4V+OoQ0FbylAMRBpa+pH Received: from localhost ([70.22.175.108]) by smtp.gmail.com with ESMTPSA id g4-20020a37e204000000b00783f534706esm1734412qki.61.2024.02.03.14.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 14:25:08 -0800 (PST) Date: Sat, 03 Feb 2024 17:25:08 -0500 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit From: Paul Moore To: Fan Wu , 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 Cc: linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@lists.linux.dev, audit@vger.kernel.org, linux-kernel@vger.kernel.org, Fan Wu Subject: Re: [PATCH RFC v12 5/20] initramfs|security: Add security hook to initramfs unpack References: <1706654228-17180-6-git-send-email-wufan@linux.microsoft.com> In-Reply-To: <1706654228-17180-6-git-send-email-wufan@linux.microsoft.com> On Jan 30, 2024 Fan Wu wrote: > > 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 > --- > include/linux/lsm_hook_defs.h | 4 ++++ > include/linux/security.h | 10 ++++++++++ > init/initramfs.c | 3 +++ > security/security.c | 12 ++++++++++++ > 4 files changed, 29 insertions(+) > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index 185924c56378..b247388786a9 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -425,3 +425,7 @@ 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 */ > + > +#ifdef CONFIG_BLK_DEV_INITRD > +LSM_HOOK(void, LSM_RET_VOID, unpack_initramfs_security, void) > +#endif /* CONFIG_BLK_DEV_INITRD */ Let's just call it "unpack_initramfs", the "_security" part is somewhat implied since we are talking about a LSM hook ;) > diff --git a/init/initramfs.c b/init/initramfs.c > index 76deb48c38cb..075a5794cde5 100644 > --- a/init/initramfs.c > +++ b/init/initramfs.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > > static __initdata bool csum_present; > static __initdata u32 io_csum; > @@ -720,6 +721,8 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) > #endif > } > > + security_unpack_initramfs(); Given the caller, what do you think of changing the hook name to "security_initramfs_populated()"? I think this not only matches up better with the caller, "do_populate_rootfs()", but since in using the past tense we help indicate that this hook happens *after* the rootfs is populated with the initramfs data. > done: > /* > * If the initrd region is overlapped with crashkernel reserved region, > diff --git a/security/security.c b/security/security.c > index ddf2e69cf8f2..2a527d4c69bc 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -5581,3 +5581,15 @@ int security_uring_cmd(struct io_uring_cmd *ioucmd) > return call_int_hook(uring_cmd, 0, ioucmd); > } > #endif /* CONFIG_IO_URING */ > + > +#ifdef CONFIG_BLK_DEV_INITRD > +/** > + * security_unpack_initramfs() - Notify LSM that initramfs has been loaded > + * > + * Tells the LSM the initramfs has been unpacked into the rootfs. > + */ > +void security_unpack_initramfs(void) > +{ > + call_void_hook(unpack_initramfs_security); > +} > +#endif /* CONFIG_BLK_DEV_INITRD */ > -- > 2.43.0 -- paul-moore.com