From 3669fd4d8a718b0ea2e6ba166716f383c695e1d1 Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Tue, 2 Oct 2018 15:29:09 +0100 Subject: [PATCH] zkey: Add initramfs hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add hook script to allow zkey utilities to be used in initramfs. Closes: https://github.com/ibm-s390-linux/s390-tools/pull/42 Signed-off-by: Dimitri John Ledkov Reviewd-by Ingo Franzki [hoeppner@linux.ibm.com: removed / in Makefile and updated commit message] Signed-off-by: Jan Höppner --- zkey/Makefile | 1 + zkey/initramfs/Makefile | 21 +++++++++++++ zkey/initramfs/hooks/s390-tools-zkey | 45 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 zkey/initramfs/Makefile create mode 100644 zkey/initramfs/hooks/s390-tools-zkey diff --git a/zkey/Makefile b/zkey/Makefile index 93b3ddbc..b5681791 100644 --- a/zkey/Makefile +++ b/zkey/Makefile @@ -104,6 +104,7 @@ zkey-cryptsetup: zkey-cryptsetup.o pkey.o cca.o ep11.o utils.o $(libs) install-common: $(INSTALL) -d -m 755 $(DESTDIR)$(USRBINDIR) $(INSTALL) -d -m 755 $(DESTDIR)$(MANDIR)/man1 + $(MAKE) -C initramfs install install-zkey: zkey $(INSTALL) -g $(GROUP) -o $(OWNER) -m 755 zkey $(DESTDIR)$(USRBINDIR) diff --git a/zkey/initramfs/Makefile b/zkey/initramfs/Makefile new file mode 100644 index 00000000..6140e47c --- /dev/null +++ b/zkey/initramfs/Makefile @@ -0,0 +1,21 @@ +# Common definitions +include ../../common.mak + +INITRAMFSDIR := /usr/share/initramfs-tools +HOOKDIR := $(INITRAMFSDIR)/hooks +INITTOP := $(INITRAMFSDIR)/scripts/init-top + +# HAVE_INITRAMFS +# +# This install time parameter determines whether the zkey initramfs support is +# installed (HAVE_INITRAMFS=1) or not (default). When installed, the module +# performs the following functions when mkinitramfs is run: +# +# - install a hook to include zkey related utilities and zkey repository in +# the initramfs +# +ifeq ($(HAVE_INITRAMFS),1) +install: + $(INSTALL) -m 755 -d $(DESTDIR)$(HOOKDIR) $(DESTDIR)$(INITTOP) + $(INSTALL) -m 755 hooks/s390-tools-zkey $(DESTDIR)$(HOOKDIR) +endif diff --git a/zkey/initramfs/hooks/s390-tools-zkey b/zkey/initramfs/hooks/s390-tools-zkey new file mode 100644 index 00000000..3d7267c6 --- /dev/null +++ b/zkey/initramfs/hooks/s390-tools-zkey @@ -0,0 +1,45 @@ +#!/bin/sh +# +# Copyright IBM Corp. 2022 +# Copyright Canonical Ltd 2018 +# +# s390-tools is free software; you can redistribute it and/or modify +# it under the terms of the MIT license. See LICENSE for details. +# +# hooks/s390-tools-zkey +# This hook script adds zkey related utilities and zkey repository +# in the initramfs +# + +# Needs to run after udev or resulting udev rules could be overwritten +PREREQ="udev" + +prereqs() +{ + echo "$PREREQ" +} + +case $1 in + prereqs) + prereqs + exit 0 + ;; +esac + +. /usr/share/initramfs-tools/hook-functions + +# Add zcrypt modules +zdev_modules="pkey paes_s390 zcrypt zcrypt_cex2a zcrypt_cex4 zcrypt_pcixcc" + +for x in $zdev_modules ; do + manual_add_modules ${x} +done + +# copy utils +copy_exec /sbin/chzcrypt +copy_exec /sbin/lszcrypt +copy_exec /usr/bin/zkey +copy_exec /usr/bin/zkey-cryptsetup + +mkdir -p "${DESTDIR}/etc" +cp -a /etc/zkey "${DESTDIR}/etc/"