1517393d9SAndrew Geissler.. SPDX-License-Identifier: CC-BY-SA-2.0-UK
2517393d9SAndrew Geissler
3517393d9SAndrew GeisslerMaking Images More Secure
4517393d9SAndrew Geissler*************************
5517393d9SAndrew Geissler
6517393d9SAndrew GeisslerSecurity is of increasing concern for embedded devices. Consider the
7517393d9SAndrew Geisslerissues and problems discussed in just this sampling of work found across
8517393d9SAndrew Geisslerthe Internet:
9517393d9SAndrew Geissler
10517393d9SAndrew Geissler-  *"*\ `Security Risks of Embedded
11517393d9SAndrew Geissler   Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"*
12517393d9SAndrew Geissler   by Bruce Schneier
13517393d9SAndrew Geissler
14517393d9SAndrew Geissler-  *"*\ `Internet Census
15517393d9SAndrew Geissler   2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna
16517393d9SAndrew Geissler   Botnet
17517393d9SAndrew Geissler
18517393d9SAndrew Geissler-  *"*\ `Security Issues for Embedded
19517393d9SAndrew Geissler   Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"*
20517393d9SAndrew Geissler   by Jake Edge
21517393d9SAndrew Geissler
22517393d9SAndrew GeisslerWhen securing your image is of concern, there are steps, tools, and
23517393d9SAndrew Geisslervariables that you can consider to help you reach the security goals you
24517393d9SAndrew Geisslerneed for your particular device. Not all situations are identical when
25517393d9SAndrew Geisslerit comes to making an image secure. Consequently, this section provides
26517393d9SAndrew Geisslersome guidance and suggestions for consideration when you want to make
27517393d9SAndrew Geissleryour image more secure.
28517393d9SAndrew Geissler
29517393d9SAndrew Geissler.. note::
30517393d9SAndrew Geissler
31517393d9SAndrew Geissler   Because the security requirements and risks are different for every
32517393d9SAndrew Geissler   type of device, this section cannot provide a complete reference on
33517393d9SAndrew Geissler   securing your custom OS. It is strongly recommended that you also
34517393d9SAndrew Geissler   consult other sources of information on embedded Linux system
35517393d9SAndrew Geissler   hardening and on security.
36517393d9SAndrew Geissler
37517393d9SAndrew GeisslerGeneral Considerations
38517393d9SAndrew Geissler======================
39517393d9SAndrew Geissler
40517393d9SAndrew GeisslerThere are general considerations that help you create more secure images.
41517393d9SAndrew GeisslerYou should consider the following suggestions to make your device
42517393d9SAndrew Geisslermore secure:
43517393d9SAndrew Geissler
44517393d9SAndrew Geissler-  Scan additional code you are adding to the system (e.g. application
45517393d9SAndrew Geissler   code) by using static analysis tools. Look for buffer overflows and
46517393d9SAndrew Geissler   other potential security problems.
47517393d9SAndrew Geissler
48517393d9SAndrew Geissler-  Pay particular attention to the security for any web-based
49517393d9SAndrew Geissler   administration interface.
50517393d9SAndrew Geissler
51517393d9SAndrew Geissler   Web interfaces typically need to perform administrative functions and
52517393d9SAndrew Geissler   tend to need to run with elevated privileges. Thus, the consequences
53517393d9SAndrew Geissler   resulting from the interface's security becoming compromised can be
54517393d9SAndrew Geissler   serious. Look for common web vulnerabilities such as
55517393d9SAndrew Geissler   cross-site-scripting (XSS), unvalidated inputs, and so forth.
56517393d9SAndrew Geissler
57517393d9SAndrew Geissler   As with system passwords, the default credentials for accessing a
58517393d9SAndrew Geissler   web-based interface should not be the same across all devices. This
59517393d9SAndrew Geissler   is particularly true if the interface is enabled by default as it can
60517393d9SAndrew Geissler   be assumed that many end-users will not change the credentials.
61517393d9SAndrew Geissler
62517393d9SAndrew Geissler-  Ensure you can update the software on the device to mitigate
63517393d9SAndrew Geissler   vulnerabilities discovered in the future. This consideration
64517393d9SAndrew Geissler   especially applies when your device is network-enabled.
65517393d9SAndrew Geissler
66517393d9SAndrew Geissler-  Regularly scan and apply fixes for CVE security issues affecting
67517393d9SAndrew Geissler   all software components in the product, see ":ref:`dev-manual/vulnerabilities:checking for vulnerabilities`".
68517393d9SAndrew Geissler
69517393d9SAndrew Geissler-  Regularly update your version of Poky and OE-Core from their upstream
70517393d9SAndrew Geissler   developers, e.g. to apply updates and security fixes from stable
71*8e7b46e2SPatrick Williams   and :term:`LTS` branches.
72517393d9SAndrew Geissler
73517393d9SAndrew Geissler-  Ensure you remove or disable debugging functionality before producing
74517393d9SAndrew Geissler   the final image. For information on how to do this, see the
75517393d9SAndrew Geissler   ":ref:`dev-manual/securing-images:considerations specific to the openembedded build system`"
76517393d9SAndrew Geissler   section.
77517393d9SAndrew Geissler
78517393d9SAndrew Geissler-  Ensure you have no network services listening that are not needed.
79517393d9SAndrew Geissler
80517393d9SAndrew Geissler-  Remove any software from the image that is not needed.
81517393d9SAndrew Geissler
82517393d9SAndrew Geissler-  Enable hardware support for secure boot functionality when your
83517393d9SAndrew Geissler   device supports this functionality.
84517393d9SAndrew Geissler
85517393d9SAndrew GeisslerSecurity Flags
86517393d9SAndrew Geissler==============
87517393d9SAndrew Geissler
88517393d9SAndrew GeisslerThe Yocto Project has security flags that you can enable that help make
89517393d9SAndrew Geissleryour build output more secure. The security flags are in the
90517393d9SAndrew Geissler``meta/conf/distro/include/security_flags.inc`` file in your
91517393d9SAndrew Geissler:term:`Source Directory` (e.g. ``poky``).
92517393d9SAndrew Geissler
93517393d9SAndrew Geissler.. note::
94517393d9SAndrew Geissler
95517393d9SAndrew Geissler   Depending on the recipe, certain security flags are enabled and
96517393d9SAndrew Geissler   disabled by default.
97517393d9SAndrew Geissler
98517393d9SAndrew GeisslerUse the following line in your ``local.conf`` file or in your custom
99517393d9SAndrew Geisslerdistribution configuration file to enable the security compiler and
100517393d9SAndrew Geisslerlinker flags for your build::
101517393d9SAndrew Geissler
102517393d9SAndrew Geissler   require conf/distro/include/security_flags.inc
103517393d9SAndrew Geissler
104517393d9SAndrew GeisslerConsiderations Specific to the OpenEmbedded Build System
105517393d9SAndrew Geissler========================================================
106517393d9SAndrew Geissler
107517393d9SAndrew GeisslerYou can take some steps that are specific to the OpenEmbedded build
108517393d9SAndrew Geisslersystem to make your images more secure:
109517393d9SAndrew Geissler
110517393d9SAndrew Geissler-  Ensure "debug-tweaks" is not one of your selected
111517393d9SAndrew Geissler   :term:`IMAGE_FEATURES`.
112517393d9SAndrew Geissler   When creating a new project, the default is to provide you with an
113517393d9SAndrew Geissler   initial ``local.conf`` file that enables this feature using the
114517393d9SAndrew Geissler   :term:`EXTRA_IMAGE_FEATURES`
115517393d9SAndrew Geissler   variable with the line::
116517393d9SAndrew Geissler
117517393d9SAndrew Geissler      EXTRA_IMAGE_FEATURES = "debug-tweaks"
118517393d9SAndrew Geissler
119517393d9SAndrew Geissler   To disable that feature, simply comment out that line in your
120517393d9SAndrew Geissler   ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain
121517393d9SAndrew Geissler   "debug-tweaks" before producing your final image. Among other things,
122517393d9SAndrew Geissler   leaving this in place sets the root password as blank, which makes
123517393d9SAndrew Geissler   logging in for debugging or inspection easy during development but
124517393d9SAndrew Geissler   also means anyone can easily log in during production.
125517393d9SAndrew Geissler
126517393d9SAndrew Geissler-  It is possible to set a root password for the image and also to set
127517393d9SAndrew Geissler   passwords for any extra users you might add (e.g. administrative or
128517393d9SAndrew Geissler   service type users). When you set up passwords for multiple images or
129517393d9SAndrew Geissler   users, you should not duplicate passwords.
130517393d9SAndrew Geissler
131517393d9SAndrew Geissler   To set up passwords, use the :ref:`ref-classes-extrausers` class, which
132517393d9SAndrew Geissler   is the preferred method. For an example on how to set up both root and
133517393d9SAndrew Geissler   user passwords, see the ":ref:`ref-classes-extrausers`" section.
134517393d9SAndrew Geissler
135517393d9SAndrew Geissler   .. note::
136517393d9SAndrew Geissler
137517393d9SAndrew Geissler      When adding extra user accounts or setting a root password, be
138517393d9SAndrew Geissler      cautious about setting the same password on every device. If you
139517393d9SAndrew Geissler      do this, and the password you have set is exposed, then every
140517393d9SAndrew Geissler      device is now potentially compromised. If you need this access but
141517393d9SAndrew Geissler      want to ensure security, consider setting a different, random
142517393d9SAndrew Geissler      password for each device. Typically, you do this as a separate
143517393d9SAndrew Geissler      step after you deploy the image onto the device.
144517393d9SAndrew Geissler
145517393d9SAndrew Geissler-  Consider enabling a Mandatory Access Control (MAC) framework such as
146517393d9SAndrew Geissler   SMACK or SELinux and tuning it appropriately for your device's usage.
147517393d9SAndrew Geissler   You can find more information in the
148517393d9SAndrew Geissler   :yocto_git:`meta-selinux </meta-selinux/>` layer.
149517393d9SAndrew Geissler
150517393d9SAndrew GeisslerTools for Hardening Your Image
151517393d9SAndrew Geissler==============================
152517393d9SAndrew Geissler
153517393d9SAndrew GeisslerThe Yocto Project provides tools for making your image more secure. You
154517393d9SAndrew Geisslercan find these tools in the ``meta-security`` layer of the
155517393d9SAndrew Geissler:yocto_git:`Yocto Project Source Repositories <>`.
156517393d9SAndrew Geissler
157