diff options
author | Lans Zhang <jia.zhang@windriver.com> | 2017-06-22 15:22:01 +0800 |
---|---|---|
committer | Lans Zhang <jia.zhang@windriver.com> | 2017-06-22 15:24:04 +0800 |
commit | 1b3e5944491c315ca99b832bc3afdb6a19d81430 (patch) | |
tree | ffb3469d58e8e203e4bc8a37adc9fe81a48558fb /meta-integrity | |
download | meta-secure-core-1b3e5944491c315ca99b832bc3afdb6a19d81430.tar.gz |
meta-secure-core: initial commit
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
Diffstat (limited to 'meta-integrity')
29 files changed, 1003 insertions, 0 deletions
diff --git a/meta-integrity/COPYING.MIT b/meta-integrity/COPYING.MIT new file mode 100644 index 0000000..fb950dc --- /dev/null +++ b/meta-integrity/COPYING.MIT | |||
@@ -0,0 +1,17 @@ | |||
1 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
2 | of this software and associated documentation files (the "Software"), to deal | ||
3 | in the Software without restriction, including without limitation the rights | ||
4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
5 | copies of the Software, and to permit persons to whom the Software is | ||
6 | furnished to do so, subject to the following conditions: | ||
7 | |||
8 | The above copyright notice and this permission notice shall be included in | ||
9 | all copies or substantial portions of the Software. | ||
10 | |||
11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
17 | THE SOFTWARE. | ||
diff --git a/meta-integrity/README.md b/meta-integrity/README.md new file mode 100644 index 0000000..2efb494 --- /dev/null +++ b/meta-integrity/README.md | |||
@@ -0,0 +1,166 @@ | |||
1 | ### meta-integrity | ||
2 | OpenEmbedded layer for Linux integrity support | ||
3 | |||
4 | #### Integrity Measurement Architecture (IMA) | ||
5 | The Linux IMA subsystem introduces hooks within the Linux kernel to support | ||
6 | measuring the integrity of files that are loaded (including application code) | ||
7 | before it is executed or mmap()ed to memory. The measured value (hash) is then | ||
8 | registered in a log that can be consulted by administrators. | ||
9 | |||
10 | To support proven integrity of the files, the IMA subsystem can interact with | ||
11 | the TPM chip within the system to protect the registered hashes from tampering | ||
12 | by a rogue administrator or application. The IMA subsystem, as already | ||
13 | supported by the Linux kernel, supports reporting on the hashes of files and | ||
14 | commands ran by privileged accounts (and more if you create your own | ||
15 | measurement policies). | ||
16 | |||
17 | In addition, IMA appraisal can even register the measured value as an extended | ||
18 | attribute, and after subsequent measurement(s) validate this extended attribute | ||
19 | against the measured value and refuse to load the file (or execute the | ||
20 | application) if the hash does not match. In that case, the IMA subsystem allows | ||
21 | files and applications to be loaded if the hashes match (and will save the | ||
22 | updated hash if the file is modified) but refuse to load it if it doesn't. This | ||
23 | provides some protection against offline tampering of the files. | ||
24 | |||
25 | NOTE: Extended file system attribute is required for IMA appraisal, but not | ||
26 | all file systems can support it. Typically, the pseudo file systems, such as | ||
27 | sysfs, proc, tmpfs and ramfs, certain disk-based file systems, such as FAT, | ||
28 | and network file systems, such as NFS, don't support extended attribute, | ||
29 | meaning IMA appraisal is not available with them. | ||
30 | |||
31 | ##### Dependency | ||
32 | - meta-tpm | ||
33 | This layer provides the kernel configurations for TPM 1.x enablement. | ||
34 | |||
35 | - meta-tpm2 | ||
36 | This layer provides the kernel configurations for TPM 2.0 enablement. | ||
37 | |||
38 | ##### Use The External IMA Policy | ||
39 | initramfs is a good place to run some IMA initializations, such as loading | ||
40 | the IMA policy, as well as the public keys used to verify IMA signatures. | ||
41 | |||
42 | ###### The default external IMA policy | ||
43 | The default external IMA policy enforces appraising all the executable, shared | ||
44 | library, kernel modules and firmwares with the digital signature in the | ||
45 | effective root identity (euid=0). Hence, the opportunity of loading the default | ||
46 | external IMA policy occurs at the end of initramfs initializations, just before | ||
47 | switch_root. | ||
48 | |||
49 | Instead of running switch_root directly from initramfs, a statically linked | ||
50 | switch_root from the real rootfs is called and it must be already signed | ||
51 | properly. Otherwise, switch_root will fail to mount the real rootfs and kernel | ||
52 | panic will happen due to this failure. | ||
53 | |||
54 | The default external IMA policy is located at `/etc/ima_policy.default` in | ||
55 | initramfs. If a custom external IMA policy file exists, the default external | ||
56 | IMA policy file won't be used any more. | ||
57 | |||
58 | The default external IMA policy enables the following constraint conditions: | ||
59 | - Appraise the files for exec'd (the executables), files mmap'd for exec | ||
60 | (shared libraries), kernel modules and firmwares in effective root identity | ||
61 | (euid=0). | ||
62 | - Enforce verifying the IMA signature when running the executables, shared | ||
63 | libraries, kernel modules and firmwares. | ||
64 | - Deny to run the newly created executables, shared libraries, kernel modules | ||
65 | and firmwares. | ||
66 | - Deny to run the tampered executables, shared libraries, kernel modules and | ||
67 | firmwares. | ||
68 | - Deny to run any executables, shared libraries, kernel modules and firmwares | ||
69 | in the filesystems without file extended attribute supported. | ||
70 | - Allow to run the manually signed executables, shared libraries, kernel | ||
71 | modules and firmwares. | ||
72 | - Allow to run the updated executables, shared libraries, kernel modules and | ||
73 | firmwares during RPM installation. | ||
74 | - Note the different behaviors when executing a script. | ||
75 | e.g, launching a python script with "./test.py" is allowed only when test.py | ||
76 | is signed, and launching a python script with "python test.py" is always | ||
77 | allowed as long as the python interpreter is signed. | ||
78 | |||
79 | ###### The custom external IMA policy | ||
80 | If the default external IMA policy cannot meet the protection requirement, it | ||
81 | is allowed to define the custom external IMA policy. | ||
82 | |||
83 | - Deploy the custom policy file to installer image | ||
84 | |||
85 | - Create `/opt/installer/sbin/config-installer.sh` in installer image | ||
86 | Define the IMA_POLICY variable, pointing to the path of policy file. | ||
87 | |||
88 | The custom external IMA policy file is eventually installed to `/etc/ima_policy` | ||
89 | in initramfs. | ||
90 | |||
91 | ##### IMA certificate & private Key | ||
92 | The private key come in two flavors; one used by an installer to sign all | ||
93 | regular files in rootfs and one used by RPM to re-sign the executable, shared | ||
94 | library, kernel module and firmware during RPM installation. Correspondingly, | ||
95 | the IMA certificate is used to verify the IMA signature signed by the private | ||
96 | key. | ||
97 | |||
98 | In addition, initramfs is a good place to import the IMA certificate likewise. | ||
99 | |||
100 | ###### The default IMA certificate & private key | ||
101 | The default IMA certificate & private key are generated by the build system. By | ||
102 | default, the sample keys are used for the purpose of development and | ||
103 | demonstration. Please ensure you know what your risk is to use the sample keys | ||
104 | in your product, because they are completely public. | ||
105 | |||
106 | ### Best practice | ||
107 | The following best practices should be applied with using IMA. | ||
108 | |||
109 | - Enable UEFI/MOK secure boot | ||
110 | UEFI/MOK secure boot can verify the integrity of initramfs, providing the | ||
111 | protection against tampering of the external IMA policy files and IMA public | ||
112 | keys stored in initramfs. | ||
113 | |||
114 | - Moderate measuring | ||
115 | Measuring the files owned by non-root user may introduce malicious attack. | ||
116 | Malicious user may create lots of files with different names or trigger | ||
117 | violation conditions to generate a mass of event logs recorded in the runtime | ||
118 | measurement list, and thus exhaust the persistent kernel memory. | ||
119 | |||
120 | - Performance influence | ||
121 | Moderate policy can make a good balance between the performance and security. | ||
122 | Tune the default external policy (`/etc/ima_policy.default`) and modulate the | ||
123 | custom policy for the product requirement. | ||
124 | |||
125 | - Use IMA digital signature to protect the executable | ||
126 | Using the digital signature scheme DIGSIG is safer than digest-based scheme. | ||
127 | Meanwhile, use `appraise_type=imasig` in your IMA policy to enforce running | ||
128 | this. | ||
129 | |||
130 | - Use the measurement and audit rules together | ||
131 | The runtime measurement list is unable to track down the order of changes for | ||
132 | a file, e.g, a file content varies in order of X -> Y -> X. However, audit log | ||
133 | can record these changes in the right order. | ||
134 | |||
135 | ##### Known Issues | ||
136 | - The following operations may break the behavior of appraisal and cause the | ||
137 | failure of launching the executables, shared libraries, kernel modules and | ||
138 | firmwares: | ||
139 | - the syscalls used to set file last access and modification times. | ||
140 | - the syscalls used to set ownership of a file. | ||
141 | - the syscalls used to set permissions of a file. | ||
142 | |||
143 | To fix the failure, manually re-sign the affected file. | ||
144 | |||
145 | Note: RPM installation violates the IMA appraisal but its post_install | ||
146 | operation will always re-sign the affected files. | ||
147 | |||
148 | - Overwriting an existing file with the same content is deemed as tampering of | ||
149 | the file. | ||
150 | |||
151 | - The default IMA rules provides the ability of measuring the boot components | ||
152 | and calculating the aggregate integrity value for attesting. However, this | ||
153 | function conflicts with encrypted-storage feature which employs PCR policy | ||
154 | session to retrieve the passphrase in a safe way. If the installer enables | ||
155 | both of them, the default IMA rules will be not used. | ||
156 | |||
157 | ### Reference | ||
158 | [IMA wiki page](https://sourceforge.net/p/linux-ima/wiki/Home/) | ||
159 | |||
160 | [OpenEmbedded layer for EFI Secure Boot](https://github.com/jiazhang0/meta-efi-secure-boot) | ||
161 | |||
162 | [OpenEmbedded layer for signing key management](https://github.com/jiazhang0/meta-signing-key) | ||
163 | |||
164 | [OpenEmbedded layer for TPM 1.x](https://github.com/jiazhang0/meta-tpm) | ||
165 | |||
166 | [OpenEmbedded layer for TPM 2.0](https://github.com/jiazhang0/meta-tpm2) | ||
diff --git a/meta-integrity/classes/rpm5-ima.bbclass b/meta-integrity/classes/rpm5-ima.bbclass new file mode 100644 index 0000000..fbdefeb --- /dev/null +++ b/meta-integrity/classes/rpm5-ima.bbclass | |||
@@ -0,0 +1,156 @@ | |||
1 | inherit package | ||
2 | |||
3 | PACKAGEFUNCS =+ "package_ima_hook" | ||
4 | |||
5 | # security.ima is generated during the RPM build, and the base64-encoded | ||
6 | # value is written during RPM installation. In addition, if the private | ||
7 | # key is deployed on board, re-sign the updated files during RPM | ||
8 | # installation in higher priority. | ||
9 | python package_ima_hook() { | ||
10 | packages = d.getVar('PACKAGES', True) | ||
11 | pkgdest = d.getVar('PKGDEST', True) | ||
12 | ima_signing_blacklist = d.getVar('IMA_SIGNING_BLACKLIST', True) | ||
13 | ima_keys_dir = d.getVar('IMA_KEYS_DIR', True) | ||
14 | |||
15 | pkg_suffix_blacklist = ('dbg', 'dev', 'doc', 'locale', 'staticdev') | ||
16 | |||
17 | pkg_blacklist = () | ||
18 | with open(ima_signing_blacklist, 'r') as f: | ||
19 | pkg_blacklist = [ _.strip() for _ in f.readlines() ] | ||
20 | pkg_blacklist = tuple(pkg_blacklist) | ||
21 | |||
22 | import base64, pipes, stat | ||
23 | |||
24 | for pkg in packages.split(): | ||
25 | if (pkg.split('-')[-1] in pkg_suffix_blacklist) is True: | ||
26 | continue | ||
27 | |||
28 | if pkg.startswith(pkg_blacklist) is True: | ||
29 | continue | ||
30 | |||
31 | bb.note("Writing IMA %%post hook for %s ..." % pkg) | ||
32 | |||
33 | pkgdestpkg = os.path.join(pkgdest, pkg) | ||
34 | |||
35 | cmd = 'evmctl ima_sign --hashalgo sha256 -n --sigfile --key %s/x509_ima.key ' % (ima_keys_dir) | ||
36 | sig_list = [] | ||
37 | pkg_sig_list = [] | ||
38 | |||
39 | for _ in pkgfiles[pkg]: | ||
40 | # Ignore the symbol links. | ||
41 | if os.path.islink(_): | ||
42 | continue | ||
43 | |||
44 | # IMA appraisal is only applied to the regular file. | ||
45 | if not stat.S_ISREG(os.stat(_)[stat.ST_MODE]): | ||
46 | continue | ||
47 | |||
48 | bb.note("Preparing to sign %s ..." % _) | ||
49 | |||
50 | sh_name = pipes.quote(_) | ||
51 | print("Signing command: %s" % cmd + sh_name) | ||
52 | rc, res = oe.utils.getstatusoutput(cmd + sh_name + " >/dev/null") | ||
53 | if rc: | ||
54 | bb.fatal('Calculate IMA signature for %s failed with exit code %s:\n%s' % \ | ||
55 | (_, rc, res if res else "")) | ||
56 | |||
57 | with open(_ + '.sig', 'rb') as f: | ||
58 | s = str(base64.b64encode(f.read()).decode('ascii')) + '|' | ||
59 | sig_list.append(s + os.sep + os.path.relpath(_, pkgdestpkg)) | ||
60 | |||
61 | os.remove(_ + '.sig') | ||
62 | |||
63 | ima_sig_list = '&'.join(sig_list) | ||
64 | |||
65 | # When the statically linked binary is updated, use the | ||
66 | # dynamically linked one to resign or set. This situation | ||
67 | # occurs in runtime only. | ||
68 | setfattr_bin = 'setfattr.static' | ||
69 | evmctl_bin = 'evmctl.static' | ||
70 | # We don't want to create a statically linked echo program | ||
71 | # any more. | ||
72 | safe_echo = '1' | ||
73 | if pkg == 'attr-setfattr.static': | ||
74 | setfattr_bin = 'setfattr' | ||
75 | elif pkg == 'ima-evm-utils-evmctl.static': | ||
76 | evmctl_bin = 'evmctil' | ||
77 | elif pkg == 'coreutils': | ||
78 | safe_echo = '0' | ||
79 | |||
80 | # The %post is dynamically constructed according to the currently | ||
81 | # installed package and enviroment. | ||
82 | postinst = r'''#!/bin/sh | ||
83 | |||
84 | # %post hook for IMA appraisal | ||
85 | ima_resign=0 | ||
86 | sig_list="''' + ima_sig_list + r'''" | ||
87 | |||
88 | if [ -z "$D" ]; then | ||
89 | evmctl_bin="${sbindir}/''' + evmctl_bin + r'''" | ||
90 | setfattr_bin="${bindir}/''' + setfattr_bin + r'''" | ||
91 | |||
92 | [ -f "/etc/keys/privkey_evm.pem" -a -x "$evmctl_bin" ] && \ | ||
93 | ima_resign=1 | ||
94 | |||
95 | safe_echo="''' + safe_echo + r'''" | ||
96 | |||
97 | cond_print() | ||
98 | { | ||
99 | [ $safe_echo = "1" ] && echo $1 | ||
100 | } | ||
101 | |||
102 | saved_IFS="$IFS" | ||
103 | IFS="&" | ||
104 | for entry in $sig_list; do | ||
105 | IFS="|" | ||
106 | |||
107 | tokens="" | ||
108 | for token in $entry; do | ||
109 | tokens="$tokens$token|" | ||
110 | done | ||
111 | |||
112 | for sig in $tokens; do | ||
113 | break | ||
114 | done | ||
115 | |||
116 | IFS="$saved_IFS" | ||
117 | |||
118 | f="$token" | ||
119 | |||
120 | # If the filesystem doesn't support xattr, skip the following steps. | ||
121 | res=`"$setfattr_bin" -x security.ima "$f" 2>&1 | grep "Operation not supported$"` | ||
122 | [ x"$res" != x"" ] && { | ||
123 | cond_print "Current file system doesn't support to set xattr" | ||
124 | break | ||
125 | } | ||
126 | |||
127 | if [ $ima_resign -eq 0 ]; then | ||
128 | cond_print "Setting up security.ima for $f ..." | ||
129 | |||
130 | "$setfattr_bin" -n security.ima -v "0s$sig" "$f" || { | ||
131 | err=$? | ||
132 | cond_print "Unable to set up security.ima for $f (err: $err)" | ||
133 | exit 1 | ||
134 | } | ||
135 | else | ||
136 | cond_print "IMA signing for $f ..." | ||
137 | |||
138 | "$evmctl_bin" ima_sign --hashalgo sha256 "$f" || { | ||
139 | err=$? | ||
140 | cond_print "Unable to sign $f (err: $err)" | ||
141 | exit 1 | ||
142 | } | ||
143 | fi | ||
144 | |||
145 | IFS="&" | ||
146 | done | ||
147 | |||
148 | IFS="$saved_IFS" | ||
149 | fi | ||
150 | |||
151 | ''' | ||
152 | postinst = postinst + (d.getVar('pkg_postinst_%s' % pkg, True) or '') | ||
153 | d.setVar('pkg_postinst_%s' % pkg, postinst) | ||
154 | } | ||
155 | |||
156 | do_package[depends] += "ima-evm-utils-native:do_populate_sysroot" | ||
diff --git a/meta-integrity/conf/layer.conf b/meta-integrity/conf/layer.conf new file mode 100644 index 0000000..f3c00e0 --- /dev/null +++ b/meta-integrity/conf/layer.conf | |||
@@ -0,0 +1,19 @@ | |||
1 | # We have a conf and classes directory, add to BBPATH | ||
2 | BBPATH .= ":${LAYERDIR}" | ||
3 | |||
4 | # We have recipes-* directories, add to BBFILES | ||
5 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ | ||
6 | ${LAYERDIR}/recipes-*/*/*.bbappend" | ||
7 | |||
8 | BBFILE_COLLECTIONS += "integrity" | ||
9 | BBFILE_PATTERN_integrity = "^${LAYERDIR}/" | ||
10 | BBFILE_PRIORITY_integrity = "10" | ||
11 | |||
12 | IMA_SIGNING_BLACKLIST ??= "${LAYERDIR}/files/ima_signing_blacklist" | ||
13 | |||
14 | LAYERDEPENDS_integrity = "\ | ||
15 | core \ | ||
16 | signing-key \ | ||
17 | tpm2 \ | ||
18 | tpm \ | ||
19 | " | ||
diff --git a/meta-integrity/files/ima_signing_blacklist b/meta-integrity/files/ima_signing_blacklist new file mode 100644 index 0000000..276a7bc --- /dev/null +++ b/meta-integrity/files/ima_signing_blacklist | |||
@@ -0,0 +1 @@ | |||
kernel-devsrc | |||
diff --git a/meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb b/meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb new file mode 100644 index 0000000..89cb120 --- /dev/null +++ b/meta-integrity/recipes-base/packagegroups/packagegroup-ima-initramfs.bb | |||
@@ -0,0 +1,12 @@ | |||
1 | DESCRIPTION = "Linux Integrity Measurement Architecture (IMA) subsystem for initramfs" | ||
2 | |||
3 | include packagegroup-ima.inc | ||
4 | |||
5 | RDEPENDS_${PN} += " \ | ||
6 | util-linux-mount \ | ||
7 | util-linux-umount \ | ||
8 | gawk \ | ||
9 | ima-policy \ | ||
10 | key-store-ima-cert \ | ||
11 | initrdscripts-ima \ | ||
12 | " | ||
diff --git a/meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb new file mode 100644 index 0000000..e10300e --- /dev/null +++ b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.bb | |||
@@ -0,0 +1,21 @@ | |||
1 | DESCRIPTION = "Linux Integrity Measurement Architecture (IMA) subsystem" | ||
2 | |||
3 | include packagegroup-ima.inc | ||
4 | |||
5 | DEPENDS += " \ | ||
6 | ima-evm-utils-native \ | ||
7 | attr-native \ | ||
8 | " | ||
9 | |||
10 | RDEPENDS_${PN} += " \ | ||
11 | attr \ | ||
12 | util-linux-switch_root.static \ | ||
13 | attr-setfattr.static \ | ||
14 | ima-evm-utils-evmctl.static \ | ||
15 | " | ||
16 | |||
17 | # Note any private key is not available if user key signing model used. | ||
18 | RRECOMMENDS_${PN} += " \ | ||
19 | key-store-ima-privkey \ | ||
20 | key-store-system-trusted-privkey \ | ||
21 | " | ||
diff --git a/meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc new file mode 100644 index 0000000..64829dc --- /dev/null +++ b/meta-integrity/recipes-base/packagegroups/packagegroup-ima.inc | |||
@@ -0,0 +1,13 @@ | |||
1 | LICENSE = "MIT" | ||
2 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ | ||
3 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
4 | |||
5 | S = "${WORKDIR}" | ||
6 | |||
7 | ALLOW_EMPTY_${PN} = "1" | ||
8 | |||
9 | RDEPENDS_${PN} = " \ | ||
10 | ima-evm-utils \ | ||
11 | coreutils \ | ||
12 | grep \ | ||
13 | " | ||
diff --git a/meta-integrity/recipes-core/base-files/base-files_%.bbappend b/meta-integrity/recipes-core/base-files/base-files_%.bbappend new file mode 100644 index 0000000..2636dad --- /dev/null +++ b/meta-integrity/recipes-core/base-files/base-files_%.bbappend | |||
@@ -0,0 +1,4 @@ | |||
1 | # Append iversion option for auto types | ||
2 | do_install_append() { | ||
3 | sed -i 's/\s*auto\s*defaults/&,iversion/' ${D}${sysconfdir}/fstab | ||
4 | } | ||
diff --git a/meta-integrity/recipes-core/initrdscripts/files/init.ima b/meta-integrity/recipes-core/initrdscripts/files/init.ima new file mode 100755 index 0000000..1e92ba2 --- /dev/null +++ b/meta-integrity/recipes-core/initrdscripts/files/init.ima | |||
@@ -0,0 +1,129 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Initramfs script for IMA initialzation | ||
4 | # | ||
5 | # This script is a halper used to load the external | ||
6 | # IMA policy and public keys used to verify the IMA | ||
7 | # signature. | ||
8 | # | ||
9 | # Copyright (c) 2017, Jia Zhang <lans.zhang2008@gmail.com> | ||
10 | # All rights reserved. | ||
11 | # | ||
12 | # See "LICENSE" for license terms. | ||
13 | |||
14 | # Exit code: | ||
15 | # 0 - IMA initialiazation complete | ||
16 | # 1 - Kernel doesn't support securityfs | ||
17 | # 2 - Kernel doesn't support IMA | ||
18 | # 3 - There is no public key to load | ||
19 | # 4 - There is no IMA policy file defined | ||
20 | # 5 - Unable to load IMA policy file | ||
21 | |||
22 | # If root directory is not specified, the root of | ||
23 | # initramfs assumed. | ||
24 | ROOT_DIR="${1}" | ||
25 | |||
26 | SECURITYFS_DIR="${ROOT_DIR}/sys/kernel/security" | ||
27 | |||
28 | # The policy files are always placed in initramfs | ||
29 | IMA_POLICY=/etc/ima_policy | ||
30 | |||
31 | SECURITYFS_MOUNTED=0 | ||
32 | |||
33 | function print_critical | ||
34 | { | ||
35 | printf "\033[1;35m" | ||
36 | echo "$@" | ||
37 | printf "\033[0m" | ||
38 | } | ||
39 | |||
40 | function print_error | ||
41 | { | ||
42 | printf "\033[1;31m" | ||
43 | echo "$@" | ||
44 | printf "\033[0m" | ||
45 | } | ||
46 | |||
47 | function print_warning | ||
48 | { | ||
49 | printf "\033[1;33m" | ||
50 | echo "$@" | ||
51 | printf "\033[0m" | ||
52 | } | ||
53 | |||
54 | function print_info | ||
55 | { | ||
56 | printf "\033[1;32m" | ||
57 | echo "$@" | ||
58 | printf "\033[0m" | ||
59 | } | ||
60 | |||
61 | function print_verbose | ||
62 | { | ||
63 | printf "\033[1;36m" | ||
64 | echo "$@" | ||
65 | printf "\033[0m" | ||
66 | } | ||
67 | |||
68 | function trap_handler | ||
69 | { | ||
70 | local err=$? | ||
71 | |||
72 | print_verbose "Cleaning up with exit code $err ..." | ||
73 | |||
74 | [ $SECURITYFS_MOUNTED -eq 1 ] && | ||
75 | umount "$SECURITYFS_DIR" 2>"${ROOT_DIR}/dev/null" | ||
76 | } | ||
77 | |||
78 | trap "trap_handler $?" SIGINT EXIT | ||
79 | |||
80 | if grep -q "ima_appraise=off" "${ROOT_DIR}/proc/cmdline"; then | ||
81 | print_info "Skip to load the public key and IMA policy" | ||
82 | exit 0 | ||
83 | fi | ||
84 | |||
85 | if ! grep -q securityfs "${ROOT_DIR}/proc/mounts"; then | ||
86 | ! mount -t securityfs none "$SECURITYFS_DIR" 2>"${ROOT_DIR}/dev/null" && { | ||
87 | print_error "Unable to mount securityfs filesystem" | ||
88 | exit 1 | ||
89 | } | ||
90 | SECURITYFS_MOUNTED=1 | ||
91 | securityfs_dir="$SECURITYFS_DIR" | ||
92 | else | ||
93 | securityfs_dirs="$(grep securityfs ${ROOT_DIR}/proc/mounts | awk '{print $2}')" | ||
94 | |||
95 | # Use the first one. | ||
96 | for securityfs_dir in "$securityfs_dirs"; do | ||
97 | break | ||
98 | done | ||
99 | fi | ||
100 | |||
101 | [ ! -d "$securityfs_dir/ima" ] && | ||
102 | print_info "IMA is not enabled. Exiting ..." && exit 2 | ||
103 | |||
104 | keyring_id=0x`grep '\skeyring\s*\.ima: ' "${ROOT_DIR}/proc/keys" | awk '{ print $1 }'` | ||
105 | |||
106 | for key in ${ROOT_DIR}/etc/keys/x509_evm*.pem; do | ||
107 | [ ! -s "$key" ] && continue | ||
108 | |||
109 | if ! evmctl import "$key" "$keyring_id" >"${ROOT_DIR}/dev/null"; then | ||
110 | print_critical "Unable to load the public key $key for IMA appraisal" | ||
111 | else | ||
112 | print_verbose "The external public key $key loaded for IMA appraisal" | ||
113 | fi | ||
114 | done | ||
115 | |||
116 | # Attempt to load the default policy. | ||
117 | [ ! -f "${IMA_POLICY}" ] && IMA_POLICY="${IMA_POLICY}.default" | ||
118 | |||
119 | [ ! -f "${IMA_POLICY}" ] && { | ||
120 | print_warning "No IMA policy file defined" | ||
121 | exit 4 | ||
122 | } | ||
123 | |||
124 | cat "${IMA_POLICY}" > "$securityfs_dir/ima/policy" && { | ||
125 | exit 0 | ||
126 | } || { | ||
127 | print_critical "Unable to load the IMA policy ${IMA_POLICY}" | ||
128 | exit 5 | ||
129 | } | ||
diff --git a/meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb b/meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb new file mode 100644 index 0000000..3860be2 --- /dev/null +++ b/meta-integrity/recipes-core/initrdscripts/initrdscripts-ima.bb | |||
@@ -0,0 +1,47 @@ | |||
1 | DESCRIPTION = "The initrd script for Linux Integrity Measurement Architecture (IMA)" | ||
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ | ||
4 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
5 | |||
6 | S = "${WORKDIR}" | ||
7 | |||
8 | ALLOW_EMPTY_${PN} = "1" | ||
9 | |||
10 | SRC_URI = "\ | ||
11 | file://init.ima \ | ||
12 | " | ||
13 | |||
14 | do_install() { | ||
15 | if [ x"${@bb.utils.contains('DISTRO_FEATURES', 'ima', '1', '0', d)}" = x"1" ]; then | ||
16 | install -m 0500 ${WORKDIR}/init.ima ${D} | ||
17 | fi | ||
18 | } | ||
19 | |||
20 | FILES_${PN} += " \ | ||
21 | ${@bb.utils.contains('DISTRO_FEATURES', 'ima', '/init.ima', '', d)} \ | ||
22 | " | ||
23 | |||
24 | # Install the minimal stuffs only, and don't care how the external | ||
25 | # environment is configured. | ||
26 | # @bash: sh | ||
27 | # @coreutils: echo, mkdir, mknod, dirname, basename, cp, rm, sleep | ||
28 | # seq, printf, cut | ||
29 | # @grep: grep | ||
30 | # @gawk: awk | ||
31 | # @kmod: modprobe, depmod | ||
32 | # @net-tools: ifconfig | ||
33 | # @trousers: tcsd | ||
34 | # @procps: pkill | ||
35 | # @util-linux: blkid, mount, umount | ||
36 | RDEPENDS_${PN} += "\ | ||
37 | bash \ | ||
38 | coreutils \ | ||
39 | grep \ | ||
40 | gawk \ | ||
41 | kmod \ | ||
42 | net-tools \ | ||
43 | procps \ | ||
44 | util-linux-blkid \ | ||
45 | util-linux-mount \ | ||
46 | util-linux-umount \ | ||
47 | " | ||
diff --git a/meta-integrity/recipes-core/util-linux/util-linux_%.bbappend b/meta-integrity/recipes-core/util-linux/util-linux_%.bbappend new file mode 100644 index 0000000..1728f2e --- /dev/null +++ b/meta-integrity/recipes-core/util-linux/util-linux_%.bbappend | |||
@@ -0,0 +1,16 @@ | |||
1 | PACKAGES =+ "${PN}-switch_root.static" | ||
2 | |||
3 | CFLAGS_remove += "-pie -fpie" | ||
4 | |||
5 | do_compile_append_class-target() { | ||
6 | ${CC} ${CFLAGS} ${LDFLAGS} -static \ | ||
7 | sys-utils/switch_root.o \ | ||
8 | -o switch_root.static | ||
9 | } | ||
10 | |||
11 | do_install_append_class-target() { | ||
12 | install -d ${D}${sbindir} | ||
13 | install -m 0700 ${B}/switch_root.static ${D}${sbindir}/switch_root.static | ||
14 | } | ||
15 | |||
16 | FILES_${PN}-switch_root.static = "${sbindir}/switch_root.static" | ||
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc b/meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc new file mode 100644 index 0000000..8c08a45 --- /dev/null +++ b/meta-integrity/recipes-kernel/linux/linux-yocto-integrity.inc | |||
@@ -0,0 +1,18 @@ | |||
1 | FILESEXTRAPATHS_prepend := "${THISDIR}/linux-yocto:" | ||
2 | |||
3 | IMA_ENABLED = "${@bb.utils.contains('DISTRO_FEATURES', 'ima', '1', '0', d)}" | ||
4 | |||
5 | DEPENDS += "${@'key-store openssl-native' if d.getVar('IMA_ENABLED', True) == '1' else ''}" | ||
6 | # key-store-ima-cert is required in runtime but we hope it is available | ||
7 | # in initramfs only. So we don't add it to RDEPENDS_${PN} here. | ||
8 | |||
9 | SRC_URI += " \ | ||
10 | ${@'file://ima.scc file://ima.cfg' if d.getVar('IMA_ENABLED', True) == '1' else ''} \ | ||
11 | " | ||
12 | |||
13 | do_configure_append() { | ||
14 | [ -f "${STAGING_DIR_TARGET}${sysconfdir}/keys/system_trusted_key.pem" ] && | ||
15 | openssl x509 -in "${STAGING_DIR_TARGET}${sysconfdir}/keys/system_trusted_key.pem" \ | ||
16 | -outform DER -out "${B}/system_trusted_cert.x509" || | ||
17 | true | ||
18 | } | ||
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend b/meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend new file mode 100644 index 0000000..685d15c --- /dev/null +++ b/meta-integrity/recipes-kernel/linux/linux-yocto-rt_4.%.bbappend | |||
@@ -0,0 +1 @@ | |||
include linux-yocto-integrity.inc | |||
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg new file mode 100644 index 0000000..073197a --- /dev/null +++ b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.cfg | |||
@@ -0,0 +1,35 @@ | |||
1 | .......................................................................... | ||
2 | . WARNING | ||
3 | . | ||
4 | . This file is a kernel configuration fragment, and not a full kernel | ||
5 | . configuration file. The final kernel configuration is made up of | ||
6 | . an assembly of processed fragments, each of which is designed to | ||
7 | . capture a specific part of the final configuration (e.g. platform | ||
8 | . configuration, feature configuration, and board specific hardware | ||
9 | . configuration). For more information on kernel configuration, please | ||
10 | . consult the product documentation. | ||
11 | . | ||
12 | .......................................................................... | ||
13 | |||
14 | CONFIG_IMA=y | ||
15 | CONFIG_IMA_MEASURE_PCR_IDX=10 | ||
16 | # CONFIG_IMA_TEMPLATE is not set | ||
17 | # CONFIG_IMA_NG_TEMPLATE=y is not set | ||
18 | CONFIG_IMA_SIG_TEMPLATE=y | ||
19 | CONFIG_IMA_DEFAULT_TEMPLATE="ima-sig" | ||
20 | # CONFIG_IMA_DEFAULT_HASH_SHA1 is not set | ||
21 | CONFIG_IMA_DEFAULT_HASH_SHA256=y | ||
22 | # CONFIG_IMA_DEFAULT_HASH_SHA512 is not set | ||
23 | # CONFIG_IMA_DEFAULT_HASH_WP512 is not set | ||
24 | CONFIG_IMA_DEFAULT_HASH="sha256" | ||
25 | CONFIG_IMA_APPRAISE=y | ||
26 | CONFIG_INTEGRITY_SIGNATURE=y | ||
27 | CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y | ||
28 | CONFIG_INTEGRITY_TRUSTED_KEYRING=y | ||
29 | CONFIG_SYSTEM_TRUSTED_KEYRING=y | ||
30 | CONFIG_IMA_LOAD_X509=y | ||
31 | CONFIG_IMA_TRUSTED_KEYRING=y | ||
32 | CONFIG_IMA_X509_PATH="/etc/keys/x509_evm.der" | ||
33 | # CONFIG_IMA_APPRAISE_SIGNED_INIT is not set | ||
34 | CONFIG_AUDIT=y | ||
35 | CONFIG_INTEGRITY_AUDIT=y | ||
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc new file mode 100644 index 0000000..c43e1c4 --- /dev/null +++ b/meta-integrity/recipes-kernel/linux/linux-yocto/ima.scc | |||
@@ -0,0 +1,4 @@ | |||
1 | define KFEATURE_DESCRIPTION "Integrity Measurement Architecture (IMA) enablement" | ||
2 | define KFEATURE_COMPATIBILITY board | ||
3 | |||
4 | kconf non-hardware ima.cfg | ||
diff --git a/meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend b/meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend new file mode 100644 index 0000000..685d15c --- /dev/null +++ b/meta-integrity/recipes-kernel/linux/linux-yocto_4.%.bbappend | |||
@@ -0,0 +1 @@ | |||
include linux-yocto-integrity.inc | |||
diff --git a/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch new file mode 100644 index 0000000..db006c0 --- /dev/null +++ b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Don-t-build-man-pages.patch | |||
@@ -0,0 +1,27 @@ | |||
1 | From b5bc04d9062a69e116ed60ad540b56cd057d47d1 Mon Sep 17 00:00:00 2001 | ||
2 | From: Lans Zhang <jia.zhang@windriver.com> | ||
3 | Date: Tue, 27 Dec 2016 14:25:58 +0800 | ||
4 | Subject: [PATCH] Don't build man pages | ||
5 | |||
6 | Too many external tools are required to build the man pages. We don't | ||
7 | need them anyway. | ||
8 | |||
9 | Signed-off-by: George McCollister <george.mccollister@gmail.com> | ||
10 | Signed-off-by: Lans Zhang <jia.zhang@windriver.com> | ||
11 | --- | ||
12 | Makefile.am | 1 - | ||
13 | 1 file changed, 1 deletion(-) | ||
14 | |||
15 | diff --git a/Makefile.am b/Makefile.am | ||
16 | index 06ebf59..e527f34 100644 | ||
17 | --- a/Makefile.am | ||
18 | +++ b/Makefile.am | ||
19 | @@ -1,5 +1,4 @@ | ||
20 | SUBDIRS = src | ||
21 | -dist_man_MANS = evmctl.1 | ||
22 | |||
23 | doc_DATA = examples/ima-genkey-self.sh examples/ima-genkey.sh examples/ima-gen-local-ca.sh | ||
24 | EXTRA_DIST = autogen.sh $(doc_DATA) | ||
25 | -- | ||
26 | 2.7.4 | ||
27 | |||
diff --git a/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch new file mode 100644 index 0000000..545be42 --- /dev/null +++ b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils/0001-Install-evmctl-to-sbindir-rather-than-bindir.patch | |||
@@ -0,0 +1,28 @@ | |||
1 | From 412f60bbd5a7ed1eac7051bd2947d5fc0c95e86b Mon Sep 17 00:00:00 2001 | ||
2 | From: Lans Zhang <jia.zhang@windriver.com> | ||
3 | Date: Thu, 12 Jan 2017 16:55:03 +0800 | ||
4 | Subject: [PATCH] Install evmctl to $sbindir rather than $bindir | ||
5 | |||
6 | Setting security.ima requires sys_admin capability. | ||
7 | |||
8 | Signed-off-by: Lans Zhang <jia.zhang@windriver.com> | ||
9 | --- | ||
10 | src/Makefile.am | 2 +- | ||
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/src/Makefile.am b/src/Makefile.am | ||
14 | index deb18fb..aa8f666 100644 | ||
15 | --- a/src/Makefile.am | ||
16 | +++ b/src/Makefile.am | ||
17 | @@ -9,7 +9,7 @@ libimaevm_la_LIBADD = $(OPENSSL_LIBS) | ||
18 | |||
19 | include_HEADERS = imaevm.h | ||
20 | |||
21 | -bin_PROGRAMS = evmctl | ||
22 | +sbin_PROGRAMS = evmctl | ||
23 | |||
24 | evmctl_SOURCES = evmctl.c | ||
25 | evmctl_CPPFLAGS = $(OPENSSL_CFLAGS) | ||
26 | -- | ||
27 | 2.7.4 | ||
28 | |||
diff --git a/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb new file mode 100644 index 0000000..c1278a9 --- /dev/null +++ b/meta-integrity/recipes-support/ima-evm-utils/ima-evm-utils_git.bb | |||
@@ -0,0 +1,41 @@ | |||
1 | LICENSE = "GPLv2" | ||
2 | LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263" | ||
3 | |||
4 | SRC_URI = " \ | ||
5 | git://git.code.sf.net/p/linux-ima/ima-evm-utils \ | ||
6 | file://0001-Don-t-build-man-pages.patch \ | ||
7 | file://0001-Install-evmctl-to-sbindir-rather-than-bindir.patch \ | ||
8 | " | ||
9 | SRCREV = "3e2a67bdb0673581a97506262e62db098efef6d7" | ||
10 | PV = "1.0+git${SRCPV}" | ||
11 | |||
12 | S = "${WORKDIR}/git" | ||
13 | |||
14 | PACKAGES =+ "${PN}-evmctl.static" | ||
15 | |||
16 | DEPENDS += "openssl attr keyutils" | ||
17 | RDEPENDS_${PN}_class-target += "libcrypto libattr keyutils" | ||
18 | |||
19 | inherit pkgconfig autotools | ||
20 | |||
21 | # Specify any options you want to pass to the configure script using EXTRA_OECONF: | ||
22 | EXTRA_OECONF = "" | ||
23 | |||
24 | CFLAGS_remove += "-pie -fpie" | ||
25 | |||
26 | do_compile_append_class-target() { | ||
27 | ${CC} ${CFLAGS} ${LDFLAGS} -static \ | ||
28 | -include config.h -L=${libdir} \ | ||
29 | -Wl,--start-group -lcrypto -lkeyutils -ldl \ | ||
30 | ${S}/src/evmctl.c ${S}/src/libimaevm.c \ | ||
31 | -Wl,--end-group -o ${B}/src/evmctl.static | ||
32 | } | ||
33 | |||
34 | do_install_append_class-target() { | ||
35 | install -m 0700 ${B}/src/evmctl.static ${D}${sbindir}/evmctl.static | ||
36 | } | ||
37 | |||
38 | FILES_${PN}-dev += "${includedir}" | ||
39 | FILES_${PN}-evmctl.static = "${sbindir}/evmctl.static" | ||
40 | |||
41 | BBCLASSEXTEND = "native nativesdk" | ||
diff --git a/meta-integrity/recipes-support/ima-policy/files/ima_policy.default b/meta-integrity/recipes-support/ima-policy/files/ima_policy.default new file mode 100644 index 0000000..5d4ae47 --- /dev/null +++ b/meta-integrity/recipes-support/ima-policy/files/ima_policy.default | |||
@@ -0,0 +1,24 @@ | |||
1 | # The default external IMA policy | ||
2 | |||
3 | # Don't appraise any file opened. | ||
4 | # However, we cannot write down such a rule, | ||
5 | # dont_appraise func=FILE_CHECK | ||
6 | # | ||
7 | # because this rule will accidently cause the security.ima | ||
8 | # being deleted in post_setattr() path. In fact, this is a | ||
9 | # real bug in policy engine when handling post_setattr() | ||
10 | # hook. The failure can be triggered in such a way: | ||
11 | # touch /bin/ls | ||
12 | # /bin/ls <- permission denied | ||
13 | |||
14 | # Reduce performance loss | ||
15 | # audit func=FILE_CHECK fowner=0 mask=^MAY_READ | ||
16 | # measure func=FILE_CHECK fowner=0 mask=^MAY_READ | ||
17 | |||
18 | appraise func=MMAP_CHECK euid=0 appraise_type=imasig | ||
19 | |||
20 | appraise func=BPRM_CHECK euid=0 appraise_type=imasig | ||
21 | |||
22 | appraise func=MODULE_CHECK euid=0 appraise_type=imasig | ||
23 | |||
24 | appraise func=FIRMWARE_CHECK euid=0 appraise_type=imasig | ||
diff --git a/meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb b/meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb new file mode 100644 index 0000000..982717a --- /dev/null +++ b/meta-integrity/recipes-support/ima-policy/ima-policy_0.1.bb | |||
@@ -0,0 +1,18 @@ | |||
1 | DESCRIPTION = "The default external IMA policy" | ||
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ | ||
4 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
5 | |||
6 | SRC_URI = " \ | ||
7 | file://ima_policy.default \ | ||
8 | " | ||
9 | |||
10 | S = "${WORKDIR}" | ||
11 | |||
12 | do_install() { | ||
13 | install -d "${D}${sysconfdir}" | ||
14 | install -m 0400 "${WORKDIR}/ima_policy.default" \ | ||
15 | "${D}${sysconfdir}" | ||
16 | } | ||
17 | |||
18 | FILES_${PN} = "${sysconfdir}" | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch new file mode 100644 index 0000000..11be1e1 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-powerpc-cflags.patch | |||
@@ -0,0 +1,28 @@ | |||
1 | From 1cc17e3c8b1f73db43011775292396338f932a20 Mon Sep 17 00:00:00 2001 | ||
2 | From: Lei Maohui <leimaohui at cn.fujitsu.com> | ||
3 | Date: Mon, 17 Aug 2015 15:30:40 +0900 | ||
4 | Subject: [PATCH] keyutils fix powerpc cflags | ||
5 | |||
6 | --- | ||
7 | Makefile | 2 -- | ||
8 | 1 file changed, 2 deletions(-) | ||
9 | |||
10 | diff --git a/Makefile b/Makefile | ||
11 | index 82e1a0f..0746c82 100644 | ||
12 | --- a/Makefile | ||
13 | +++ b/Makefile | ||
14 | @@ -65,12 +65,10 @@ BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')- | ||
15 | LNS := ln -sf | ||
16 | |||
17 | ifeq ($(BUILDFOR),32-bit) | ||
18 | -CFLAGS += -m32 | ||
19 | LIBDIR := /usr/lib | ||
20 | USRLIBDIR := /usr/lib | ||
21 | else | ||
22 | ifeq ($(BUILDFOR),64-bit) | ||
23 | -CFLAGS += -m64 | ||
24 | LIBDIR := /usr/lib | ||
25 | USRLIBDIR := /usr/lib | ||
26 | endif | ||
27 | -- | ||
28 | 1.8.4.2 | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch new file mode 100644 index 0000000..77cf528 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-fix-the-cflags-for-all-of-targets.patch | |||
@@ -0,0 +1,32 @@ | |||
1 | From 8a1331d4abf9a96ee65e5fb31a00c7a2e0eed7c8 Mon Sep 17 00:00:00 2001 | ||
2 | From: Lei Maohui <leimaohui at cn.fujitsu.com> | ||
3 | Date: Mon, 17 Aug 2015 13:53:28 +0900 | ||
4 | Subject: [PATCH] fix the cflags for all of targets. | ||
5 | |||
6 | Signed-off-by: Lei Maohui <leimaohui at cn.fujitsu.com> | ||
7 | --- | ||
8 | Makefile | 2 -- | ||
9 | 1 file changed, 2 deletions(-) | ||
10 | |||
11 | diff --git a/Makefile b/Makefile | ||
12 | index e2d7e2d..82e1a0f 100644 | ||
13 | --- a/Makefile | ||
14 | +++ b/Makefile | ||
15 | @@ -64,7 +64,6 @@ BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')- | ||
16 | |||
17 | LNS := ln -sf | ||
18 | |||
19 | -ifeq ($(origin CFLAGS),undefined) | ||
20 | ifeq ($(BUILDFOR),32-bit) | ||
21 | CFLAGS += -m32 | ||
22 | LIBDIR := /usr/lib | ||
23 | @@ -76,7 +75,6 @@ LIBDIR := /usr/lib | ||
24 | USRLIBDIR := /usr/lib | ||
25 | endif | ||
26 | endif | ||
27 | -endif | ||
28 | |||
29 | ############################################################################### | ||
30 | # | ||
31 | -- | ||
32 | 1.8.4.2 | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch new file mode 100644 index 0000000..a049fd2 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils-remove-m32-m64.patch | |||
@@ -0,0 +1,19 @@ | |||
1 | Index: keyutils-1.5.5/Makefile | ||
2 | =================================================================== | ||
3 | --- keyutils-1.5.5.orig/Makefile 2011-12-20 11:05:10.000000000 +0200 | ||
4 | +++ keyutils-1.5.5/Makefile 2011-12-20 11:06:27.000000000 +0200 | ||
5 | @@ -58,12 +58,12 @@ | ||
6 | LNS := ln -sf | ||
7 | |||
8 | ifeq ($(BUILDFOR),32-bit) | ||
9 | -CFLAGS += -m32 | ||
10 | +#CFLAGS += -m32 | ||
11 | LIBDIR := /usr/lib | ||
12 | USRLIBDIR := /usr/lib | ||
13 | else | ||
14 | ifeq ($(BUILDFOR),64-bit) | ||
15 | -CFLAGS += -m64 | ||
16 | +#CFLAGS += -m64 | ||
17 | LIBDIR := /usr/lib | ||
18 | USRLIBDIR := /usr/lib | ||
19 | endif | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch new file mode 100644 index 0000000..adf0643 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_library_install.patch | |||
@@ -0,0 +1,30 @@ | |||
1 | Index: keyutils-1.5.5/Makefile | ||
2 | =================================================================== | ||
3 | --- keyutils-1.5.5.orig/Makefile 2011-11-30 17:27:43.000000000 +0200 | ||
4 | +++ keyutils-1.5.5/Makefile 2011-12-21 16:05:53.000000000 +0200 | ||
5 | @@ -59,13 +59,13 @@ | ||
6 | |||
7 | ifeq ($(BUILDFOR),32-bit) | ||
8 | CFLAGS += -m32 | ||
9 | -LIBDIR := /lib | ||
10 | +LIBDIR := /usr/lib | ||
11 | USRLIBDIR := /usr/lib | ||
12 | else | ||
13 | ifeq ($(BUILDFOR),64-bit) | ||
14 | CFLAGS += -m64 | ||
15 | -LIBDIR := /lib64 | ||
16 | -USRLIBDIR := /usr/lib64 | ||
17 | +LIBDIR := /usr/lib | ||
18 | +USRLIBDIR := /usr/lib | ||
19 | endif | ||
20 | endif | ||
21 | |||
22 | @@ -152,7 +152,7 @@ | ||
23 | $(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME) | ||
24 | $(LNS) $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME) | ||
25 | mkdir -p $(DESTDIR)$(USRLIBDIR) | ||
26 | - $(LNS) $(LIBDIR)/$(SONAME) $(DESTDIR)$(USRLIBDIR)/$(DEVELLIB) | ||
27 | + $(LNS) $(SONAME) $(DESTDIR)$(USRLIBDIR)/$(DEVELLIB) | ||
28 | $(INSTALL) -D keyctl $(DESTDIR)$(BINDIR)/keyctl | ||
29 | $(INSTALL) -D request-key $(DESTDIR)$(SBINDIR)/request-key | ||
30 | $(INSTALL) -D request-key-debug.sh $(DESTDIR)$(SHAREDIR)/request-key-debug.sh | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch new file mode 100644 index 0000000..b0c2d92 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86-64_cflags.patch | |||
@@ -0,0 +1,24 @@ | |||
1 | From d3b6b98984a28e782cb22dc6c7bd0ea9a0e74f15 Mon Sep 17 00:00:00 2001 | ||
2 | From: Lei Maohui <leimaohui at cn.fujitsu.com> | ||
3 | Date: Mon, 17 Aug 2015 15:53:02 +0900 | ||
4 | Subject: [PATCH] keyutils fix x86-64 cflags | ||
5 | |||
6 | --- | ||
7 | Makefile | 2 +- | ||
8 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
9 | |||
10 | diff --git a/Makefile b/Makefile | ||
11 | index 82e1a0f..23aa466 100644 | ||
12 | --- a/Makefile | ||
13 | +++ b/Makefile | ||
14 | @@ -60,7 +60,7 @@ endif | ||
15 | ifeq ($(origin USRLIBDIR),undefined) | ||
16 | USRLIBDIR := $(patsubst /lib/%,/usr/lib/%,$(LIBDIR)) | ||
17 | endif | ||
18 | -BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-bit | ||
19 | +BUILDFOR := 64-bit | ||
20 | |||
21 | LNS := ln -sf | ||
22 | |||
23 | -- | ||
24 | 1.8.4.2 | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch new file mode 100644 index 0000000..f5d5f70 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils/keyutils_fix_x86_cflags.patch | |||
@@ -0,0 +1,24 @@ | |||
1 | From 3263917382af02e61f12f3774c32d3324a57059f Mon Sep 17 00:00:00 2001 | ||
2 | From: Lei Maohui <leimaohui at cn.fujitsu.com> | ||
3 | Date: Mon, 17 Aug 2015 11:48:22 +0900 | ||
4 | Subject: [PATCH] keyutils fix x86 cflags | ||
5 | |||
6 | --- | ||
7 | Makefile | 2 +- | ||
8 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
9 | |||
10 | diff --git a/Makefile b/Makefile | ||
11 | index e2d7e2d..f05bada 100644 | ||
12 | --- a/Makefile | ||
13 | +++ b/Makefile | ||
14 | @@ -60,7 +60,7 @@ endif | ||
15 | ifeq ($(origin USRLIBDIR),undefined) | ||
16 | USRLIBDIR := $(patsubst /lib/%,/usr/lib/%,$(LIBDIR)) | ||
17 | endif | ||
18 | -BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-bit | ||
19 | +BUILDFOR := 32-bit | ||
20 | |||
21 | LNS := ln -sf | ||
22 | |||
23 | -- | ||
24 | 1.8.4.2 | ||
diff --git a/meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb b/meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb new file mode 100644 index 0000000..64e0365 --- /dev/null +++ b/meta-integrity/recipes-support/keyutils/keyutils_1.5.9.bb | |||
@@ -0,0 +1,48 @@ | |||
1 | SUMMARY = "Linux Key Management Utilities" | ||
2 | DESCRIPTION = "Keyutils is a set of utilities for managing the key retention \ | ||
3 | facility in the kernel, which can be used by filesystems, block devices and \ | ||
4 | more to gain and retain the authorization and encryption keys required to \ | ||
5 | perform secure operations." | ||
6 | SECTION = "base" | ||
7 | LICENSE = "GPLv2" | ||
8 | LIC_FILES_CHKSUM = "file://LICENCE.GPL;md5=5f6e72824f5da505c1f4a7197f004b45" | ||
9 | |||
10 | PR = "r1" | ||
11 | |||
12 | SRCREV = "9209a0c8fd63afc59f644e078b40cec531409c30" | ||
13 | |||
14 | SRC_URI = "git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/keyutils.git;protocol=git \ | ||
15 | file://keyutils_fix_library_install.patch \ | ||
16 | file://keyutils-fix-the-cflags-for-all-of-targets.patch \ | ||
17 | " | ||
18 | SRC_URI_append_arm = " file://keyutils-remove-m32-m64.patch" | ||
19 | SRC_URI_append_aarch64 = " file://keyutils-remove-m32-m64.patch" | ||
20 | SRC_URI_append_mips = " file://keyutils-remove-m32-m64.patch" | ||
21 | SRC_URI_append_mips64 = " file://keyutils-remove-m32-m64.patch" | ||
22 | SRC_URI_append_x86 = " file://keyutils_fix_x86_cflags.patch" | ||
23 | SRC_URI_append_x86-64 = " file://keyutils_fix_x86-64_cflags.patch" | ||
24 | SRC_URI_append_powerpc = "file://keyutils-fix-powerpc-cflags.patch" | ||
25 | |||
26 | S = "${WORKDIR}/git" | ||
27 | |||
28 | inherit autotools-brokensep | ||
29 | |||
30 | INSTALL_FLAGS = " \ | ||
31 | LIBDIR=${libdir} \ | ||
32 | USRLIBDIR=${libdir} \ | ||
33 | BINDIR=${bindir} \ | ||
34 | SBINDIR=${sbindir} \ | ||
35 | ETCDIR=${sysconfdir} \ | ||
36 | SHAREDIR=${datadir} \ | ||
37 | MANDIR=${mandir} \ | ||
38 | INCLUDEDIR=${includedir} \ | ||
39 | DESTDIR=${D} \ | ||
40 | " | ||
41 | |||
42 | do_install() { | ||
43 | cd ${S} && oe_runmake ${INSTALL_FLAGS} install | ||
44 | } | ||
45 | |||
46 | FILES_${PN} += "${datadir}/request-key-debug.sh" | ||
47 | |||
48 | BBCLASSEXTEND = "native nativesdk" | ||