modsign: Use single PEM file for autogenerated key
[cascardo/linux.git] / kernel / Makefile
1 #
2 # Makefile for the linux kernel.
3 #
4
5 obj-y     = fork.o exec_domain.o panic.o \
6             cpu.o exit.o softirq.o resource.o \
7             sysctl.o sysctl_binary.o capability.o ptrace.o user.o \
8             signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
9             extable.o params.o \
10             kthread.o sys_ni.o nsproxy.o \
11             notifier.o ksysfs.o cred.o reboot.o \
12             async.o range.o smpboot.o
13
14 obj-$(CONFIG_MULTIUSER) += groups.o
15
16 ifdef CONFIG_FUNCTION_TRACER
17 # Do not trace debug files and internal ftrace files
18 CFLAGS_REMOVE_cgroup-debug.o = $(CC_FLAGS_FTRACE)
19 CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE)
20 endif
21
22 # cond_syscall is currently not LTO compatible
23 CFLAGS_sys_ni.o = $(DISABLE_LTO)
24
25 obj-y += sched/
26 obj-y += locking/
27 obj-y += power/
28 obj-y += printk/
29 obj-y += irq/
30 obj-y += rcu/
31 obj-y += livepatch/
32
33 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
34 obj-$(CONFIG_FREEZER) += freezer.o
35 obj-$(CONFIG_PROFILING) += profile.o
36 obj-$(CONFIG_STACKTRACE) += stacktrace.o
37 obj-y += time/
38 obj-$(CONFIG_FUTEX) += futex.o
39 ifeq ($(CONFIG_COMPAT),y)
40 obj-$(CONFIG_FUTEX) += futex_compat.o
41 endif
42 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
43 obj-$(CONFIG_SMP) += smp.o
44 ifneq ($(CONFIG_SMP),y)
45 obj-y += up.o
46 endif
47 obj-$(CONFIG_UID16) += uid16.o
48 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
49 obj-$(CONFIG_MODULES) += module.o
50 obj-$(CONFIG_MODULE_SIG) += module_signing.o
51 obj-$(CONFIG_KALLSYMS) += kallsyms.o
52 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
53 obj-$(CONFIG_KEXEC) += kexec.o
54 obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
55 obj-$(CONFIG_COMPAT) += compat.o
56 obj-$(CONFIG_CGROUPS) += cgroup.o
57 obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
58 obj-$(CONFIG_CPUSETS) += cpuset.o
59 obj-$(CONFIG_UTS_NS) += utsname.o
60 obj-$(CONFIG_USER_NS) += user_namespace.o
61 obj-$(CONFIG_PID_NS) += pid_namespace.o
62 obj-$(CONFIG_IKCONFIG) += configs.o
63 obj-$(CONFIG_SMP) += stop_machine.o
64 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
65 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
66 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
67 obj-$(CONFIG_AUDIT_WATCH) += audit_watch.o
68 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
69 obj-$(CONFIG_GCOV_KERNEL) += gcov/
70 obj-$(CONFIG_KPROBES) += kprobes.o
71 obj-$(CONFIG_KGDB) += debug/
72 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
73 obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
74 obj-$(CONFIG_SECCOMP) += seccomp.o
75 obj-$(CONFIG_RELAY) += relay.o
76 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
77 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
78 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
79 obj-$(CONFIG_TRACEPOINTS) += tracepoint.o
80 obj-$(CONFIG_LATENCYTOP) += latencytop.o
81 obj-$(CONFIG_BINFMT_ELF) += elfcore.o
82 obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o
83 obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o
84 obj-$(CONFIG_FUNCTION_TRACER) += trace/
85 obj-$(CONFIG_TRACING) += trace/
86 obj-$(CONFIG_TRACE_CLOCK) += trace/
87 obj-$(CONFIG_RING_BUFFER) += trace/
88 obj-$(CONFIG_TRACEPOINTS) += trace/
89 obj-$(CONFIG_IRQ_WORK) += irq_work.o
90 obj-$(CONFIG_CPU_PM) += cpu_pm.o
91 obj-$(CONFIG_BPF) += bpf/
92
93 obj-$(CONFIG_PERF_EVENTS) += events/
94
95 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
96 obj-$(CONFIG_PADATA) += padata.o
97 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
98 obj-$(CONFIG_JUMP_LABEL) += jump_label.o
99 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
100 obj-$(CONFIG_TORTURE_TEST) += torture.o
101
102 $(obj)/configs.o: $(obj)/config_data.h
103
104 # config_data.h contains the same information as ikconfig.h but gzipped.
105 # Info from config_data can be extracted from /proc/config*
106 targets += config_data.gz
107 $(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
108         $(call if_changed,gzip)
109
110       filechk_ikconfiggz = (echo "static const char kernel_config_data[] __used = MAGIC_START"; cat $< | scripts/basic/bin2c; echo "MAGIC_END;")
111 targets += config_data.h
112 $(obj)/config_data.h: $(obj)/config_data.gz FORCE
113         $(call filechk,ikconfiggz)
114
115 ###############################################################################
116 #
117 # Roll all the X.509 certificates that we can find together and pull them into
118 # the kernel so that they get loaded into the system trusted keyring during
119 # boot.
120 #
121 # We look in the source root and the build root for all files whose name ends
122 # in ".x509".  Unfortunately, this will generate duplicate filenames, so we
123 # have make canonicalise the pathnames and then sort them to discard the
124 # duplicates.
125 #
126 ###############################################################################
127 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
128 X509_CERTIFICATES-y := $(wildcard *.x509) $(wildcard $(srctree)/*.x509)
129 X509_CERTIFICATES-$(CONFIG_MODULE_SIG) += $(objtree)/signing_key.x509
130 X509_CERTIFICATES-raw := $(sort $(foreach CERT,$(X509_CERTIFICATES-y), \
131                                 $(or $(realpath $(CERT)),$(CERT))))
132 X509_CERTIFICATES := $(subst $(realpath $(objtree))/,,$(X509_CERTIFICATES-raw))
133
134 ifeq ($(X509_CERTIFICATES),)
135 $(warning *** No X.509 certificates found ***)
136 endif
137
138 ifneq ($(wildcard $(obj)/.x509.list),)
139 ifneq ($(shell cat $(obj)/.x509.list),$(X509_CERTIFICATES))
140 $(warning X.509 certificate list changed to "$(X509_CERTIFICATES)" from "$(shell cat $(obj)/.x509.list)")
141 $(shell rm $(obj)/.x509.list)
142 endif
143 endif
144
145 kernel/system_certificates.o: $(obj)/x509_certificate_list
146
147 quiet_cmd_x509certs  = CERTS   $@
148       cmd_x509certs  = cat $(X509_CERTIFICATES) /dev/null >$@ $(foreach X509,$(X509_CERTIFICATES),; $(kecho) "  - Including cert $(X509)")
149
150 targets += $(obj)/x509_certificate_list
151 $(obj)/x509_certificate_list: $(X509_CERTIFICATES) $(obj)/.x509.list
152         $(call if_changed,x509certs)
153
154 targets += $(obj)/.x509.list
155 $(obj)/.x509.list:
156         @echo $(X509_CERTIFICATES) >$@
157 endif
158
159 clean-files := x509_certificate_list .x509.list
160
161 ifeq ($(CONFIG_MODULE_SIG),y)
162 ###############################################################################
163 #
164 # If module signing is requested, say by allyesconfig, but a key has not been
165 # supplied, then one will need to be generated to make sure the build does not
166 # fail and that the kernel may be used afterwards.
167 #
168 ###############################################################################
169 ifndef CONFIG_MODULE_SIG_HASH
170 $(error Could not determine digest type to use from kernel config)
171 endif
172
173 # We do it this way rather than having a boolean option for enabling an
174 # external private key, because 'make randconfig' might enable such a
175 # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
176 ifeq ($(CONFIG_MODULE_SIG_KEY),"signing_key.pem")
177 signing_key.pem: x509.genkey
178         @echo "###"
179         @echo "### Now generating an X.509 key pair to be used for signing modules."
180         @echo "###"
181         @echo "### If this takes a long time, you might wish to run rngd in the"
182         @echo "### background to keep the supply of entropy topped up.  It"
183         @echo "### needs to be run as root, and uses a hardware random"
184         @echo "### number generator if one is available."
185         @echo "###"
186         openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
187                 -batch -x509 -config x509.genkey \
188                 -outform PEM -out signing_key.pem \
189                 -keyout signing_key.pem 2>&1
190         @echo "###"
191         @echo "### Key pair generated."
192         @echo "###"
193
194 x509.genkey:
195         @echo Generating X.509 key generation config
196         @echo  >x509.genkey "[ req ]"
197         @echo >>x509.genkey "default_bits = 4096"
198         @echo >>x509.genkey "distinguished_name = req_distinguished_name"
199         @echo >>x509.genkey "prompt = no"
200         @echo >>x509.genkey "string_mask = utf8only"
201         @echo >>x509.genkey "x509_extensions = myexts"
202         @echo >>x509.genkey
203         @echo >>x509.genkey "[ req_distinguished_name ]"
204         @echo >>x509.genkey "#O = Unspecified company"
205         @echo >>x509.genkey "CN = Build time autogenerated kernel key"
206         @echo >>x509.genkey "#emailAddress = unspecified.user@unspecified.company"
207         @echo >>x509.genkey
208         @echo >>x509.genkey "[ myexts ]"
209         @echo >>x509.genkey "basicConstraints=critical,CA:FALSE"
210         @echo >>x509.genkey "keyUsage=digitalSignature"
211         @echo >>x509.genkey "subjectKeyIdentifier=hash"
212         @echo >>x509.genkey "authorityKeyIdentifier=keyid"
213 endif
214
215 # We need to obtain the certificate from CONFIG_MODULE_SIG_KEY.
216 quiet_cmd_extract_der = CERT_DER $(2)
217       cmd_extract_der = scripts/extract-cert "$(2)" signing_key.x509
218
219 # CONFIG_MODULE_SIG_KEY is either a PKCS#11 URI or a filename. It is
220 # surrounded by quotes, and may contain spaces. To strip the quotes
221 # with $(patsubst) we need to turn the spaces into something else.
222 # And if it's a filename, those spaces need to be escaped as '\ ' in
223 # order to use it in dependencies or $(wildcard).
224 space :=
225 space +=
226 space_escape := %%%SPACE%%%
227 X509_SOURCE_temp := $(subst $(space),$(space_escape),$(CONFIG_MODULE_SIG_KEY))
228 # We need this to check for absolute paths or PKCS#11 URIs.
229 X509_SOURCE_ONEWORD := $(patsubst "%",%,$(X509_SOURCE_temp))
230 # This is the actual source filename/URI without the quotes
231 X509_SOURCE := $(subst $(space_escape),$(space),$(X509_SOURCE_ONEWORD))
232 # This\ version\ with\ spaces\ escaped\ for\ $(wildcard)\ and\ dependencies
233 X509_SOURCE_ESCAPED := $(subst $(space_escape),\$(space),$(X509_SOURCE_ONEWORD))
234
235 ifeq ($(patsubst pkcs11:%,%,$(X509_SOURCE_ONEWORD)),$(X509_SOURCE_ONEWORD))
236 # If it's a filename, depend on it.
237 X509_DEP := $(X509_SOURCE_ESCAPED)
238 ifeq ($(patsubst /%,%,$(X509_SOURCE_ONEWORD)),$(X509_SOURCE_ONEWORD))
239 ifeq ($(wildcard $(X509_SOURCE_ESCAPED)),)
240 ifneq ($(wildcard $(srctree)/$(X509_SOURCE_ESCAPED)),)
241 # Non-absolute filename, found in source tree and not build tree
242 X509_SOURCE := $(srctree)/$(X509_SOURCE)
243 X509_DEP := $(srctree)/$(X509_SOURCE_ESCAPED)
244 endif
245 endif
246 endif
247 endif
248
249 signing_key.x509: scripts/extract-cert include/config/module/sig/key.h $(X509_DEP)
250         $(call cmd,extract_der,$(X509_SOURCE))
251 endif