Bulk documentation updates for needlefish
[AGL/documentation.git] / docs / 2_Architecture_Guides / 2_Security_Blueprint / 5_Platform.md
1 ---
2 title: Platform
3 ---
4
5 ###### # #    # #    # ###### 
6 #      #  #  #  ##  ## #      
7 #####  #   ##   # ## # #####  
8 #      #   ##   #    # #      
9 #      #  #  #  #    # #      
10 #      # #    # #    # ###### 
11
12 This information is old and only kept for reference. The current implementation has evolved.
13
14
15 The Automotive Grade Linux platform is a Linux distribution with **AGL**
16 compliant applications and services. The platform includes the following
17 software:
18
19 - Linux **BSP** configured for reference boards.
20 - Proprietary device drivers for common peripherals on reference boards.
21 - Application framework.
22 - Windows/layer management (graphics).
23 - Sound resource management.
24 - An atomic software update system (chapter Update).
25 - Building and debug tools (based on Yocto project).
26
27
28
29 Domain              | Improvement
30 ------------------- | --------------------------------
31 Platform-Abstract-1 | Create a graphics and sound part.
32
33
34
35 This part focuses on the AGL platform including all tools and techniques used to
36 upgrade the security and downgrade the danger. It must be possible to apply the
37 two fundamental principles written at the very beginning of the document. First
38 of all, security management must remain simple. You must also prohibit
39 everything by default, and then define a set of authorization rules. As cases to
40 deal with, we must:
41
42 - Implement a **MAC** for processes and files.
43 - Limit communication between applications (_SystemBus_ and _SystemD_ part).
44 - Prohibit all tools used during development mode (_Utilities_ and _Services_
45   part).
46 - Manage user capabilities (_Users_ part).
47 - Manage application permissions and policies (_AGLFw_ part).
48
49
50
51 The tools and concepts used to meet these needs are only examples. Any other
52 tool that meets the need can be used.
53
54
55
56 In AGL, as in many other embedded systems, different security mechanisms settle
57 in the core layers to ensure isolation and data privacy. While the Mandatory
58 Access Control layer (**SMACK**) provides global security and isolation, other
59 mechanisms like **Cynara** are required to check application's permissions at
60 runtime. Applicative permissions (also called "_privileges_") may vary depending
61 on the user and the application being run: an application should have access to
62 a given service only if it is run by the proper user and if the appropriate
63 permissions are granted.
64
65 ## Discretionary Access Control
66
67 **D**iscretionary **A**ccess **C**ontrol (**DAC**) is the traditional Linux
68 method of separating users and groups from one another. In a shared environment
69 where multiple users have access to a computer or network, Unix IDs have offered
70 a way to contain access within privilege areas for individuals, or shared among
71 the group or system. The Android system took this one step further, assigning
72 new user IDs for each App. This was never the original intention of Linux UIDs,
73 but was able to provide Android’s initial security element: the ability to
74 sandbox applications.
75
76 Although AGL mentions use of **DAC** for security isolation, the weight of the
77 security responsibility lies in the **M**andatory **A**ccess **C**ontrol
78 (**MAC**) and **Cynara**. Furthermore, there are system services with unique
79 UIDs. however,the system does not go to the extreme of Android, where every
80 application has its own UID. All sandboxing (app isolation) in AGL is handled in
81 the **MAC** contexts.
82
83 ## Mandatory Access Control
84
85 **M**andatory **A**ccess **C**ontrol (**MAC**) is an extension to **DAC**,
86 whereby extended attributes (xattr) are associated with the filesystem. In the
87 case of AGL, the smackfs filesystem allows files and directories to be
88 associated with a SMACK label, providing the ability of further discrimination
89 on access control. A SMACK label is a simple null terminated character string
90 with a maximum of 255 bytes. While it doesn’t offer the richness of an SELinux
91 label, which provides a user, role,type, and level, the simplicity of a single
92 value makes the overall design far less complex. There is arguably less chance
93 of the security author making mistakes in the policies set forth.
94
95 --------------------------------------------------------------------------------
96
97
98
99 ## Acronyms and Abbreviations
100
101 The following table lists the terms utilized within this part of the document.
102
103 Acronyms or Abbreviations | Description
104 ------------------------- | --------------------------------------------------------------
105 _ACL_                     | **A**ccess **C**ontrol **L**ists
106 _alsa_                    | **A**dvanced **L**inux **S**ound **A**rchitecture
107 _API_                     | **A**pplication **P**rogramming **I**nterface
108 _AppFw_                   | **App**lication **F**rame**w**ork
109 _BSP_                     | **B**oard **S**upport **P**ackage
110 _Cap_                     | **Cap**abilities
111 _DAC_                     | **D**iscretionary **A**ccess **C**ontrol
112 _DDOS_                    | **D**istributed **D**enial **O**f **S**ervice
113 _DOS_                     | **D**enial **O**f **S**ervice
114 _IPC_                     | **I**nter-**P**rocess **C**ommunication
115 _MAC_                     | **M**andatory **A**ccess **C**ontrol
116 _PAM_                     | **P**luggable **A**uthentication **M**odules
117 _SMACK_                   | **S**implified **M**andatory **A**ccess **C**ontrol **K**ernel
118
119 # Mandatory Access Control
120
121
122
123 We decided to put the **MAC** protection on the platform part despite the fact
124 that it applies to the kernel too, since its use will be mainly at the platform
125 level (except floor part).
126
127
128
129 **M**andatory **A**ccess **C**ontrol (**MAC**) is a protection provided by the
130 Linux kernel that requires a **L**inux **S**ecurity **M**odule (**LSM**). AGL
131 uses an **LSM** called **S**implified **M**andatory **A**ccess **C**ontrol
132 **K**ernel (**SMACK**). This protection involves the creation of **SMACK**
133 labels as part of the extended attributes **SMACK** labels to the file extended
134 attributes. And a policy is also created to define the behaviour of each label.
135
136 The kernel access controls is based on these labels and this policy. If there is
137 no rule, no access will be granted and as a consequence, what is not explicitly
138 authorized is forbidden.
139
140 There are two types of **SMACK** labels:
141
142 - **Execution SMACK** (Attached to the process): Defines how files are
143   _accessed_ and _created_ by that process.
144 - **File Access SMACK** (Written to the extended attribute of the file): Defines
145   _which_ process can access the file.
146
147 By default a process executes with its File Access **SMACK** label unless an
148 Execution **SMACK** label is defined.
149
150 AGL's **SMACK** scheme is based on the _Tizen 3 Q2/2015_. It divides the System
151 into the following domains:
152
153 - Floor.
154 - System.
155 - Applications, Services and User.
156
157 See [AGL security framework
158 review](http://iot.bzh/download/public/2017/AMMQ1Tokyo/AGL-security-framework-review.pdf)
159 and [Smack White
160 Paper](http://schaufler-ca.com/yahoo_site_admin/assets/docs/SmackWhitePaper.257153003.pdf)
161 for more information.
162
163 --------------------------------------------------------------------------------
164
165
166
167 ## Floor
168
169 The _floor_ domain includes the base system services and any associated data and
170 libraries. This data remains unchanged at runtime. Writing to floor files or
171 directories is allowed only in development mode or during software installation
172 or upgrade.
173
174 The following table details the _floor_ domain:
175
176 Label | Name  | Execution **SMACK** | File Access **SMACK**
177 ----- | ----- | ------------------- | ---------------------------------------
178 `-`   | Floor | `r-x` for all       | Only kernel and internal kernel thread.
179 `^`   | Hat   | `---` for all       | `rx` on all domains.
180 `*`   | Star  | `rwx` for all       | None
181
182
183
184 - The Hat label is Only for privileged system services (currently only
185   systemd-journal). Useful for backup or virus scans. No file with this label
186   should exist except in the debug log.
187
188 - The Star label is used for device files or `/tmp` Access restriction managed
189   via **DAC**. Individual files remain protected by their **SMACK** label.
190
191
192
193 Domain             | `Label` name | Recommendations
194 ------------------ | ------------ | -----------------------------------------------------------
195 Kernel-MAC-Floor-1 | `^`          | Only for privileged system services.
196 Kernel-MAC-Floor-2 | `*`          | Used for device files or `/tmp` Access restriction via DAC.
197
198
199
200 --------------------------------------------------------------------------------
201
202
203
204 ## System
205
206 The _system_ domain includes a reduced set of core system services of the OS and
207 any associated data. This data may change at runtime.
208
209 The following table details the _system_ domain:
210
211 Label            | Name      | Execution **SMACK**                             | File Access **SMACK**
212 ---------------- | --------- | ----------------------------------------------- | ---------------------
213 `System`         | System    | None                                            | Privileged processes
214 `System::Run`    | Run       | `rwxatl` for User and System label              | None
215 `System::Shared` | Shared    | `rwxatl` for system domain `r-x` for User label | None
216 `System::Log`    | Log       | `rwa` for System label `xa` for user label      | None
217 `System::Sub`    | SubSystem | Subsystem Config files                          | SubSystem only
218
219
220
221 Domain              | `Label` name     | Recommendations
222 ------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------
223 Kernel-MAC-System-1 | `System`         | Process should write only to file with transmute attribute.
224 Kernel-MAC-System-2 | `System::run`    | Files are created with the directory label from user and system domain (transmute) Lock is implicit with `w`.
225 Kernel-MAC-System-3 | `System::Shared` | Files are created with the directory label from system domain (transmute) User domain has locked privilege.
226 Kernel-MAC-System-4 | `System::Log`    | Some limitation may impose to add `w` to enable append.
227 Kernel-MAC-System-5 | `System::Sub`    | Isolation of risky Subsystem.
228
229
230
231 --------------------------------------------------------------------------------
232
233
234
235 ## Applications, Services and User
236
237 The _application_, _services_ and _user_ domain includes code that provides
238 services to the system and user, as well as any associated data. All code
239 running on this domain is under _Cynara_ control.
240
241 The following table details the _application_, _services_ and _user_ domain:
242
243 Label               | Name   | Execution **SMACK**                                                         | File Access **SMACK**
244 ------------------- | ------ | --------------------------------------------------------------------------- | ---------------------------
245 `User::Pkg::$AppID` | AppID  | `rwx` (for files created by the App). `rx` for files installed by **AppFw** | $App runtime executing $App
246 `User::Home`        | Home   | `rwx-t` from System label `r-x-l` from App                                  | None
247 `User::App-Shared`  | Shared | `rwxat` from System and User domains label of $User                         | None
248
249
250
251 Domain              | `Label` name        | Recommendations
252 ------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------
253 Kernel-MAC-System-1 | `User::Pkg::$AppID` | Only one Label is allowed per App. A data directory is created by the AppFw in `rwx` mode.
254 Kernel-MAC-System-2 | `User::Home`        | AppFw needs to create a directory in `/home/$USER/App-Shared` at first launch if not present with label app-data access is `User::App-Shared` without transmute.
255 Kernel-MAC-System-3 | `User::App-Shared`  | Shared space between all App running for a given user.
256
257
258
259 ## Attack Vectors
260
261 There are 4 major components to the system:
262
263 - The LSM kernel module.
264 - The `smackfs` filesystem.
265 - Basic utilities for policy management and checking.
266 - The policy/configuration data.
267
268 As with any mandatory access system, the policy management needs to be carefully
269 separated from the checking, as the management utilities can become a convenient
270 point of attack. Dynamic additions to the policy system need to be carefully
271 verified, as the ability to update the policies is often needed, but introduces
272 a possible threat. Finally, even if the policy management is well secured, the
273 policy checking and failure response to that checking is also of vital
274 importance to the smooth operation of the system.
275
276 While **MAC** is a certainly a step up in security when compared to DAC, there
277 are still many ways to compromise a SMACK-enabled Linux system. Some of these
278 ways are as follows:
279
280 - Disabling SMACK at invocation of the kernel (with command-line:
281   security=none).
282 - Disabling SMACK in the kernel build and redeploying the kernel.
283 - Changing a SMACK attribute of a file or directory at install time.
284 - Tampering with a process with the CAP_MAC_ADMIN privilege.
285 - Setting/Re-setting the SMACK label of a file.
286 - Tampering with the default domains (i.e.
287   /etc/smack/accesses.d/default-access-domains).
288 - Disabling or tampering with the SMACK filesystem (i.e. /smackfs).
289 - Adding policies with `smackload` (adding the utility if not present).
290 - Changing labels with `chsmack` (adding the utility if not present).
291
292 # SystemD
293
294 `afm-system-daemon` is used to:
295
296 - Manage users and user sessions.
297 - Setup applications and services (_CGroups_, _namespaces_, autostart,
298   permissions).
299 - Use of `libsystemd` for its programs (event management, **D-Bus** interface).
300
301
302
303 Domain             | Object         | Recommendations
304 ------------------ | -------------- | ------------------------------------
305 Platform-SystemD-1 | Security model | Use Namespaces for containerization.
306 Platform-SystemD-2 | Security model | Use CGroups to organise processes.
307
308
309
310 See [systemd integration and user
311 management](http://iot.bzh/download/public/2017/AMM-Dresden/AGL-systemd.pdf) for
312 more information.
313
314 ## Benefits
315
316 - Removal of one privileged process: **afm-user-daemon**
317 - Access and use of high level features:
318
319   - Socket activation.
320   - Management of users and integration of **PAM**.
321   - Dependency resolution to services.
322   - `Cgroups` and resource control.
323   - `Namespaces` containerization.
324   - Autostart of required API.
325   - Permissions and security settings.
326   - Network management.
327
328
329
330 ## CGroups
331
332 Control Groups offer a lot of features, with the most useful ones you can
333 control: Memory usage, how much CPU time is allocated, how much device I/O is
334 allowed or which devices can be accessed. **SystemD** uses _CGroups_ to organise
335 processes (each service is a _CGroups_, and all processes started by that
336 service use that _CGroups_). By default, **SystemD** automatically creates a
337 hierarchy of slice, scope and service units to provide a unified structure for
338 the _CGroups_ tree. With the `systemctl` command, you can further modify this
339 structure by creating custom slices. Currently, in AGL, there are 2 slices
340 (**user.slice** and **system.slice**).
341
342 ## Namespaces
343
344 ### User side
345
346 There are several ways of authenticating users (Key Radio Frequency, Phone,
347 Gesture, ...). Each authentication provides dynamic allocation of **uids** to
348 authenticated users. **Uids** is used to ensure privacy of users and **SMACK**
349 for applications privacy.
350
351 First, the user initiates authentication with **PAM** activation. **PAM**
352 Standard offers highly configurable authentication with modular design like face
353 recognition, Voice identification or with a password. Then users should access
354 identity services with services and applications.
355
356 # D-Bus
357
358 D-Bus is a well-known **IPC** (Inter-Process Communication) protocol (and
359 daemon) that helps applications to talk to each other. The use of D-Bus is great
360 because it allows to implement discovery and signaling.
361
362 The D-Bus session is by default addressed by environment variable
363 `DBUS_SESSION_BUS_ADDRESS`. Using **systemd** variable
364 `DBUS_SESSION_BUS_ADDRESS` is automatically set for user sessions. D-Bus usage
365 is linked to permissions.
366
367 D-Bus has already had several [security
368 issues](https://www.cvedetails.com/vulnerability-list/vendor_id-13442/D-bus-Project.html)
369 (mostly **DoS** issues), to allow applications to keep talking to each other. It
370 is important to protect against this type of attack to keep the system more
371 stable.
372
373
374
375
376 Domain          | Object         | Recommendations
377 --------------- | -------------- | ------------------------------------
378 Platform-DBus-1 | Security model | Use D-Bus as IPC.
379 Platform-DBus-2 | Security model | Apply D-BUS security patches: [D-Bus CVE](https://www.cvedetails.com/vulnerability-list/vendor_id-13442/D-bus-Project.html)
380
381
382
383 # System services and daemons
384
385
386
387 Domain              | Improvement
388 ------------------- | -----------
389 Platform-Services-1 | SystemD ?
390 Platform-Services-2 | Secure daemon ?
391
392
393
394 ## Tools
395
396 - **connman**: An internet connection manager designed to be slim and to use as
397   few resources as possible. It is a fully modular system that can be extended,
398   through plug-ins, to support all kinds of wired or wireless technologies.
399 - **bluez** is a Bluetooth stack. Its goal is to program an implementation of
400   the Bluetooth wireless standards specifications. In addition to the basic
401   stack, the `bluez-utils` and `bluez-firmware` packages contain low level
402   utilities such as `dfutool` which can interrogate the Bluetooth adapter
403   chipset in order to determine whether its firmware can be upgraded.
404 - **gstreamer** is a pipeline-based multimedia framework. It can be used to
405   build a system that reads files in one format, processes them, and exports
406   them in another format.
407 - **alsa** is a software framework and part of the Linux kernel that provides an
408   **API** for sound card device drivers.
409
410
411
412 Domain               | `Tool` name | _State_
413 -------------------- | ----------- | -------
414 Platform-Utilities-1 | `connman`   | _Used_ as a connection manager.
415 Platform-Utilities-2 | `bluez`     | _Used_ as a Bluetooth manager.
416 Platform-Utilities-3 | `gstreamer` | _Used_ to manage multimedia file format.
417 Platform-Utilities-4 | `alsa`      | _Used_ to provides an API for sound card device drivers.
418
419
420
421 # Application framework/model (**AppFw**)
422
423 The AGL application framework consists of several inter-working parts:
424
425 - **SMACK**: The kernel level **LSM** (**L**inux **S**ecurity **M**odule) that
426   performs extended access control of the system.
427 - **Cynara**: the native gatekeeper daemon used for policy handling, updating to
428   the database and policy checking.
429 - Security Manager: a master service, through which all security events are
430   intended to take place.
431 - Several native application framework utilities: `afm-main-binding`,
432   `afm-user-daemon`, `afm-system-daemon`.
433
434 The application framework manages:
435
436 - The applications and services management: Installing, Uninstalling, Listing,
437   ...
438 - The life cycle of applications: Start -> (Pause, Resume) -> Stop.
439 - Events and signals propagation.
440 - Privileges granting and checking.
441 - API for interaction with applications.
442
443
444
445 - The **security model** refers to the security model used to ensure security
446   and to the tools that are provided for implementing that model. It's an
447   implementation detail that should not impact the layers above the application
448   framework.
449
450 - The **security model** refers to how **DAC** (**D**iscretionary **A**ccess
451   **C**ontrol), **MAC** (Mandatory Access Control) and `Capabilities` are used
452   by the system to ensure security and privacy. It also includes features of
453   reporting using audit features and by managing logs and alerts.
454
455
456
457 The **AppFw** uses the security model to ensure the security and the privacy of
458 the applications that it manages. It must be compliant with the underlying
459 security model. But it should hide it to the applications.
460
461
462
463 Domain                 | Object         | Recommendations
464 ---------------------- | -------------- | --------------------------------
465 Platform-AGLFw-AppFw-1 | Security model | Use the AppFw as Security model.
466
467
468
469 See [AGL AppFw Privileges
470 Management](http://docs.automotivelinux.org/docs/devguides/en/dev/reference/iotbzh2016/appfw/03-AGL-AppFW-Privileges-Management.pdf)
471 and [AGL - Application Framework
472 Documentation](http://iot.bzh/download/public/2017/SDK/AppFw-Documentation-v3.1.pdf)
473 for more information.
474
475
476
477 The Security Manager communicates policy information to **Cynara**, which
478 retains information in its own database in the format of a text file with
479 comma-separated values (CSV). There are provisions to retain a copy of the CSV
480 text file when the file is being updated.
481
482 Runtime checking occurs through **Cynara**. Each application that is added to
483 the framework has its own instantiation of a SMACK context and D-bus bindings.
484 The afb_daemon and Binder form a web-service that is communicated to through
485 http or a websocket from the application-proper. This http or websocket
486 interface uses a standard unique web token for API communication.
487
488 ![Application Framework Flow](images/App-flow.png)
489
490 ## Cynara
491
492 There's a need for another mechanism responsible for checking applicative
493 permissions: Currently in AGL, this task depends on a policy-checker service
494 (**Cynara**).
495
496 - Stores complex policies in databases.
497 - "Soft" security (access is checked by the framework).
498
499 Cynara interact with **D-Bus** in order to deliver this information.
500
501 Cynara consists of several parts:
502
503 - Cynara: a daemon for controlling policies and responding to access control
504   requests.
505 - Database: a spot to hold policies.
506 - Libraries: several static and dynamic libraries for communicating with Cynara.
507
508 The daemon communicates to the libraries over Unix domain sockets. The database
509 storage format is a series of CSV-like files with an index file.
510
511 There are several ways that an attacker can manipulate policies of the Cynara
512 system:
513
514 - Disable Cynara by killing the process.
515 - Tamper with the Cynara binary on-disk or in-memory.
516 - Corrupt the database controlled by Cynara.
517 - Tamper with the database controlled by Cynara.
518 - Highjack the communication between Cynara and the database.
519
520 The text-based database is the weakest part of the system and although there are
521 some consistency mechanisms in place (i.e. the backup guard), these mechanisms
522 are weak at best and can be countered by an attacker very easily.
523
524
525
526 Domain                  | Object      | Recommendations
527 ----------------------- | ----------- | -------------------------------------
528 Platform-AGLFw-Cynara-1 | Permissions | Use Cynara as policy-checker service.
529
530
531
532 ### Policies
533
534 - Policy rules:
535
536   - Are simple - for pair [application context, privilege] there is straight
537     answer (single Policy Type): [ALLOW / DENY / ...].
538   - No code is executed (no script).
539   - Can be easily cached and managed.
540
541 - Application context (describes id of the user and the application credentials)
542   It is build of:
543
544   - UID of the user that runs the application.
545   - **SMACK** label of application.
546
547 ## Holding policies
548
549 Policies are kept in buckets. Buckets are set of policies which have additional
550 a property of default answer, the default answer is yielded if no policy matches
551 searched key. Buckets have names which might be used in policies (for
552 directions).
553
554 ## Attack Vectors
555
556 The following attack vectors are not completely independent. While attackers may
557 have varying levels of access to an AGL system, experience has shown that a
558 typical attack can start with direct access to a system, find the
559 vulnerabilities, then proceed to automate the attack such that it can be invoked
560 from less accessible standpoint (e.g. remotely). Therefore, it is important to
561 assess all threat levels, and protect the system appropriately understanding
562 that direct access attacks are the door-way into remote attacks.
563
564 ### Remote Attacks
565
566 The local web server interface used for applications is the first point of
567 attack, as web service APIs are well understood and easily intercepted. The
568 local web server could potentially be exploited by redirecting web requests
569 through the local service and exploiting the APIs. While there is the use of a
570 security token on the web service API, this is weak textual matching at best.
571 This will not be difficult to spoof. It is well known that [API Keys do not
572 provide any real security](http://nordicapis.com/why-api-keys-are-not-enough/).
573
574 It is likely that the architectural inclusion of an http / web-service interface
575 provided the most flexibility for applications to be written natively or in
576 HTML5. However, this flexibility may trade-off with security concerns. For
577 example, if a native application were linked directly to the underlying
578 framework services, there would be fewer concerns over remote attacks coming
579 through the web-service interface.
580
581 Leaving the interface as designed, mitigations to attacks could include further
582 securing the interface layer with cryptographic protocols: e.g. encrypted
583 information passing, key exchange (e.g. Elliptic-Curve Diffie-Hellman).
584
585 ### User-level Native Attacks
586
587 - Modifying the CSV data-base
588 - Modifying the SQLite DB
589 - Tampering with the user-level binaries
590 - Tampering with the user daemons
591 - Spoofing the D-bus Interface
592 - Adding executables/libraries
593
594 With direct access to the device, there are many security concerns on the native
595 level. For example, as **Cynara** uses a text file data-base with
596 comma-separated values (CSV), an attacker could simply modify the data-base to
597 escalate privileges of an application. Once a single application has all the
598 privileges possible on the system, exploits can come through in this manner.
599 Similarly the SQLite database used by the Security Manager is not much different
600 than a simple text file. There are many tools available to add, remove, modify
601 entries in an SQLite data-base.
602
603 On the next level, a common point of attack is to modify binaries or daemons for
604 exploiting functionality. There are many Linux tools available to aid in this
605 regard, including: [IDA Pro](https://www.hex-rays.com/products/ida/index.shtml),
606 and [radare2](https://rada.re/r/). With the ability to modify binaries, an
607 attacker can do any number of activities including: removing calls to security
608 checks, redirecting control to bypass verification functionality, ignoring
609 security policy handling, escalating privileges, etc.
610
611 Additionally, another attack vector would be to spoof the D-bus interface. D-bus
612 is a message passing system built upon Inter-Process Communication (IPC), where
613 structured messages are passed based upon a protocol. The interface is generic
614 and well documented. Therefore, modifying or adding binaries/libraries to spoof
615 this interface is a relatively straight-forward process. Once the interface has
616 been spoofed, the attacker can issue any number of commands that lead into
617 control of low-level functionality.
618
619 Protecting a system from native attacks requires a methodical approach. First,
620 the system should reject processes that are not sanctioned to run.
621 Signature-level verification at installation time will help in this regard, but
622 run-time integrity verification is much better. Signatures need to originate
623 from authorized parties, which is discussed further in a later section on the
624 Application Store.
625
626 On the next level, executables should not be allowed to do things where they
627 have not been granted permission. DAC and SMACK policies can help in this
628 regard. On the other hand, there remain concerns with memory accesses, system
629 calls, and other process activity that may go undetected. For this reason, a
630 secure environment which monitors all activity can give indication of all
631 unauthorized activity on the system.
632
633 Finally, it is very difficult to catch attacks of direct tampering in a system.
634 These types of attacks require a defense-in-depth approach, where complementary
635 software protection and hardening techniques are needed. Tamper-resistance and
636 anti-reverse-engineering technologies include program
637 transformations/obfuscation, integrity verification, and white-box cryptography.
638 If applied in a mutually-dependent fashion and considering performance/security
639 tradeoffs, the approach can provide an effective barrier to direct attacks to
640 the system. Furthermore, the use of threat monitoring provides a valuable
641 telemetry/analytics capability and the ability to react and renew a system under
642 attack.
643
644 ### Root-level Native Attacks
645
646 - Tampering the system daemon
647 - Tampering Cynara
648 - Tampering the security manager
649 - Disabling SMACK
650 - Tampering the kernel
651
652 Once root-level access (i.e. su) has been achieved on the device, there are many
653 ways to compromise the system. The system daemon, **Cynara**, and the security
654 manager are vulnerable to tampering attacks. For example, an executable can be
655 modified in memory to jam a branch, jump to an address, or disregard a check.
656 This can be as simple as replacing a branch instruction with a NOP, changing a
657 memory value, or using a debugger (e.g. gdb, IDA) to change an instruction.
658 Tampering these executables would mean that policies can be ignored and
659 verification checks can be bypassed.
660
661 Without going so far as to tamper an executable, the **SMACK** system is also
662 vulnerable to attack. For example, if the kernel is stopped and restarted with
663 the *security=none* flag, then SMACK is not enabled. Furthermore, `systemd`
664 starts the loading of **SMACK** rules during start-up. If this start-up process
665 is interfered with, then **SMACK** will not run. Alternatively, new policies can
666 be added with `smackload` allowing unforeseen privileges to alternative
667 applications/executables.
668
669 Another intrusion on the kernel level is to rebuild the kernel (as it is
670 open-source) and replace it with a copy that has **SMACK** disabled, or even
671 just the **SMACK** filesystem (`smackfs`) disabled. Without the extended label
672 attributes, the **SMACK** system is disabled.
673
674 Root-level access to the device has ultimate power, where the entire system can
675 be compromised. More so, a system with this level access allows an attacker to
676 craft a simpler *point-attack* which can operate on a level requiring fewer
677 privileges (e.g. remote access, user-level access).
678
679 ## Vulnerable Resources
680
681 ### Resource: `afm-user-daemon`
682
683 The `afm-user-daemon` is in charge of handling applications on behalf of a user.
684 Its main tasks are:
685
686 - Enumerate applications that the end user can run and keep this list available
687   on demand.
688 - Start applications on behalf of the end user, set user running environment,
689   set user security context.
690 - List current runnable or running applications.
691 - Stop (aka pause), continue (aka resume), terminate a running instance of a
692   given application.
693 - Transfer requests for installation/uninstallation of applications to the
694   corresponding system daemon afm-system-daemon.
695
696 The `afm-user-daemon` launches applications. It builds a secure environment for
697 the application before starting it within that environment. Different kinds of
698 applications can be launched, based on a configuration file that describes how
699 to launch an application of a given kind within a given launching mode: local or
700 remote. Launching an application locally means that the application and its
701 binder are launched together. Launching an application remotely translates in
702 only launching the application binder.
703
704 The UI by itself has to be activated remotely by a request (i.e. HTML5
705 homescreen in a browser). Once launched, running instances of the application
706 receive a `runid` that identifies them. `afm-user-daemon` manages the list of
707 applications that it has launched. When owning the right permissions, a client
708 can get the list of running instances and details about a specific running
709 instance. It can also terminate, stop or continue a given application. If the
710 client owns the right permissions, `afm-user-daemon` delegates the task of
711 installing and uninstalling applications to `afm-system-daemon`.
712
713 `afm-user-daemon` is launched as a `systemd` service attached to a user session.
714 Normally, the service file is located at
715 /usr/lib/systemd/user/afm-user-daemon.service.
716
717 Attacker goals:
718
719 - Disable `afm-user-daemon`.
720 - Tamper with the `afm-user-daemon` configuration.
721   - /usr/lib/systemd/user/afm-user-daemon.service.
722   - Application(widget) config.xml file.
723   - /etc/afm/afm-launch.conf (launcher configuration).
724
725 - Escalate user privileges to gain more access with `afm-user-daemon`.
726 - Install malicious application (widget).
727 - Tamper with `afm-user-daemon` on disk or in memory.
728
729 ### Resource: `afm-system-daemon`
730
731 The `afm-system-daemon` is in charge of installing applications on the AGL
732 system. Its main tasks are:
733
734 - Install applications and setup security framework for newly installed
735   applications.
736 - Uninstall applications.
737
738 `afm-system-daemon` is launched as a `systemd` service attached to system.
739 Normally, the service file is located at
740 /lib/systemd/system/afm-systemdaemon.service.
741
742 Attacker goals:
743
744 - Disable `afm-system-daemon`.
745 - Tamper with the `afm-system-daemon` configuration.
746 - Tamper `afm-system-daemon` on disk or in memory.
747
748 ### Resource `afb-daemon`
749
750 `afb-binder` is in charge of serving resources and features through an HTTP
751 interface. `afb-daemon` is in charge of binding one instance of an application
752 to the AGL framework and AGL system. The application and its companion binder
753 run in a secured and isolated environment set for them. Applications are
754 intended to access to AGL system through the binder. `afb-daemon` binders serve
755 files through HTTP protocol and offers developers the capability to expose
756 application API methods through HTTP or WebSocket protocol.
757
758 Binder bindings are used to add APIs to `afb-daemon`. The user can write a
759 binding for `afb-daemon`. The binder `afb-daemon` serves multiple purposes:
760
761 1. It acts as a gateway for the application to access the system.
762 2. It acts as an HTTP server for serving files to HTML5 applications.
763 3. It allows HTML5 applications to have native extensions subject to security
764    enforcement for accessing hardware resources or for speeding up parts of
765    algorithm.
766
767 Attacker goals:
768
769 - Break from isolation.
770 - Disable `afb-daemon`.
771 - Tamper `afb-demon` on disk or in memory.
772 - Tamper **capabilities** by creating/installing custom bindings for
773   `afb-daemon`.
774
775 # Utilities
776
777 - **busybox**: Software that provides several stripped-down Unix tools in a
778   single executable file. Of course, it will be necessary to use a "production"
779   version of **busybox** in order to avoid all the tools useful only in
780   development mode.
781
782
783
784 Domain               | `Tool` name | _State_
785 -------------------- | ----------- | ----------------------------------------------------------------------
786 Platform-Utilities-1 | `busybox`   | _Used_ to provide a number of tools. Do not compile development tools.
787
788
789
790 ## Functionalities to exclude in production mode
791
792 In production mode, a number of tools must be disabled to prevent an attacker
793 from finding logs for example. This is useful to limit the visible surface and
794 thus complicate the fault finding process. The tools used only in development
795 mode are marked by an '**agl-devel**' feature. When building in production mode,
796 these tools will not be compiled.
797
798
799
800 Domain                | `Utility` name and normal `path`                     | _State_
801 --------------------- | ---------------------------------------------------- | ----------
802 Platform-Utilities-1  | `chgrp` in `/bin/chgrp`                              | _Disabled_
803 Platform-Utilities-2  | `chmod` in `/bin/chmod`                              | _Disabled_
804 Platform-Utilities-3  | `chown` in `/bin/chown`                              | _Disabled_
805 Platform-Utilities-4  | `dmesg` in `/bin/dmesg`                              | _Disabled_
806 Platform-Utilities-5  | `Dnsdomainname` in `/bin/dnsdomainname`              | _Disabled_
807 Platform-Utilities-6  | `dropbear`, Remove "dropbear" from `/etc/init.d/rcs` | _Disabled_
808 Platform-Utilities-7  | `Editors` in (vi) `/bin/vi`                          | _Disabled_
809 Platform-Utilities-8  | `find` in `/bin/find`                                | _Disabled_
810 Platform-Utilities-9  | `gdbserver` in `/bin/gdbserver`                      | _Disabled_
811 Platform-Utilities-10 | `hexdump` in `/bin/hexdump`                          | _Disabled_
812 Platform-Utilities-11 | `hostname` in `/bin/hostname`                        | _Disabled_
813 Platform-Utilities-12 | `install` in `/bin/install`                          | _Disabled_
814 Platform-Utilities-13 | `iostat` in `/bin/iostat`                            | _Disabled_
815 Platform-Utilities-14 | `killall` in `/bin/killall`                          | _Disabled_
816 Platform-Utilities-15 | `klogd` in `/sbin/klogd`                             | _Disabled_
817 Platform-Utilities-16 | `logger` in `/bin/logger`                            | _Disabled_
818 Platform-Utilities-17 | `lsmod` in `/sbin/lsmod`                             | _Disabled_
819 Platform-Utilities-18 | `pmap` in `/bin/pmap`                                | _Disabled_
820 Platform-Utilities-19 | `ps` in `/bin/ps`                                    | _Disabled_
821 Platform-Utilities-20 | `ps` in `/bin/ps`                                    | _Disabled_
822 Platform-Utilities-21 | `rpm` in `/bin/rpm`                                  | _Disabled_
823 Platform-Utilities-22 | `SSH`                                                | _Disabled_
824 Platform-Utilities-23 | `stbhotplug` in `/sbin/stbhotplug`                   | _Disabled_
825 Platform-Utilities-24 | `strace` in `/bin/trace`                             | _Disabled_
826 Platform-Utilities-25 | `su` in `/bin/su`                                    | _Disabled_
827 Platform-Utilities-26 | `syslogd` in (logger) `/bin/logger`                  | _Disabled_
828 Platform-Utilities-27 | `top` in `/bin/top`                                  | _Disabled_
829 Platform-Utilities-28 | `UART` in `/proc/tty/driver/`                        | _Disabled_
830 Platform-Utilities-29 | `which` in `/bin/which`                              | _Disabled_
831 Platform-Utilities-30 | `who` and `whoami` in `/bin/whoami`                  | _Disabled_
832 Platform-Utilities-31 | `awk` (busybox)                                      | _Enabled_
833 Platform-Utilities-32 | `cut` (busybox)                                      | _Enabled_
834 Platform-Utilities-33 | `df` (busybox)                                       | _Enabled_
835 Platform-Utilities-34 | `echo` (busybox)                                     | _Enabled_
836 Platform-Utilities-35 | `fdisk` (busybox)                                    | _Enabled_
837 Platform-Utilities-36 | `grep` (busybox)                                     | _Enabled_
838 Platform-Utilities-37 | `mkdir` (busybox)                                    | _Enabled_
839 Platform-Utilities-38 | `mount` (vfat) (busybox)                             | _Enabled_
840 Platform-Utilities-39 | `printf` (busybox)                                   | _Enabled_
841 Platform-Utilities-40 | `sed` in `/bin/sed` (busybox)                        | _Enabled_
842 Platform-Utilities-41 | `tail` (busybox)                                     | _Enabled_
843 Platform-Utilities-42 | `tee` (busybox)                                      | _Enabled_
844 Platform-Utilities-43 | `test` (busybox)                                     | _Enabled_
845
846
847
848 The _Enabled_ Unix/Linux utilities above shall be permitted as they are often
849 used in the start-up scripts and for USB logging. If any of these utilities are
850 not required by the device then those should be removed.
851
852
853
854 # Users
855
856 The user policy can group users by function within the car. For example, we can
857 consider a driver and his passengers. Each user is assigned to a single group to
858 simplify the management of space security.
859
860 ## Root Access
861
862 The main applications, those that provide the principal functionality of the
863 embedded device, should not execute with root identity or any capability.
864
865 If the main application is allowed to execute at any capability, then the entire
866 system is at the mercy of the said application's good behaviour. Problems arise
867 when an application is compromised and able to execute commands which could
868 consistently and persistently compromise the system by implanting rogue
869 applications.
870
871 It is suggested that the middleware and the UI should run in a context on a user
872 with no capability and all persistent resources should be maintained without any
873 capability.
874
875 One way to ensure this is by implementing a server-client paradigm. Services
876 provided by the system's drivers can be shared this way. The other advantage of
877 this approach is that multiple applications can share the same resources at the
878 same time.
879
880
881
882 Domain                | Object           | Recommendations
883 --------------------- | ---------------- | -----------------------------------------------------
884 Platform-Users-root-1 | Main application | Should not execute as root.
885 Platform-Users-root-2 | UI               | Should run in a context on a user with no capability.
886
887
888
889 Root access should not be allowed for the following utilities:
890
891
892
893 Domain                | `Utility` name | _State_
894 --------------------- | -------------- | -------------
895 Platform-Users-root-3 | `login`        | _Not allowed_
896 Platform-Users-root-4 | `su`           | _Not allowed_
897 Platform-Users-root-5 | `ssh`          | _Not allowed_
898 Platform-Users-root-6 | `scp`          | _Not allowed_
899 Platform-Users-root-7 | `sftp`         | _Not allowed_
900
901
902
903 Root access should not be allowed for the console device. The development
904 environment should allow users to login with pre-created user accounts.
905
906 Switching to elevated privileges shall be allowed in the development environment
907 via `sudo`.
908
909 --------------------------------------------------------------------------------
910
911
912
913 ## Capabilities
914
915
916
917 Domain                        | Improvement
918 ----------------------------- | ------------------------
919 Platform-Users-Capabilities-1 | Kernel or Platform-user?
920 Platform-Users-Capabilities-2 | Add config note.
921
922
923
924 The goal is to restrict functionality that will not be useful in **AGL**. They
925 are integrated into the **LSM**. Each privileged transaction is associated with
926 a capability. These capabilities are divided into three groups:
927
928 - e: Effective: This means the capability is “activated”.
929 - p: Permitted: This means the capability can be used/is allowed.
930 - i: Inherited: The capability is kept by child/subprocesses upon execve() for
931   example.