<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Djalal Harouni on Medium]]></title>
        <description><![CDATA[Stories by Djalal Harouni on Medium]]></description>
        <link>https://medium.com/@tixxdz?source=rss-bf8e76cbd364------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nDo3zsOg6dBiZZT4aK02Zg.png</url>
            <title>Stories by Djalal Harouni on Medium</title>
            <link>https://medium.com/@tixxdz?source=rss-bf8e76cbd364------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:07:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tixxdz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hardening Linux-based IoT systems]]></title>
            <link>https://medium.com/@tixxdz/hardening-linux-based-iot-systems-bd7dc31b38fa?source=rss-bf8e76cbd364------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd7dc31b38fa</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Djalal Harouni]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 09:37:44 GMT</pubDate>
            <atom:updated>2017-10-16T09:37:44.097Z</atom:updated>
            <content:encoded><![CDATA[<p><em>TL;DR: In Linux kernel and as part of the Kernel Self Protection Project we are pushing for new lightweight security mechanisms. On top of that, in systemd we are implementing new lightweight container mechanisms that target Embedded Linux and IoT. Our goal is to make it easy to deploy Secure Embedded Linux and IoT systems.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/135/1*v4YSm3fzTDgdt9SumBrzsw.png" /><figcaption>Linux Kernel Self Protection logo</figcaption></figure><p>Working with Embedded Linux systems, device drivers, system and kernel security, allows me to inspect what will be deployed in production. I noticed a common pattern for some devices, either they contain simple kernel vulnerabilities within third party drivers, or deployed applications run with higher privileges, they lack common sandbox and security features. In this blog post, I will present a brief introduction on some mechanisms that allow you to improve your Linux-based IoT security, before discussing new plans that are in development from systemd to Linux kernel hardening.</p><h3>Linux Kernel Hardening and security</h3><p>Linux is one of the most popular operating systems for Embedded and IoT systems. Linux is a beast, it solves most embedded world use cases, however, supporting lot of technologies has its own code complexity cost. Security hardening measures allow to hide this complexity, to reduce the attack surface, to contain apps, and to defeat some kernel or user space exploitation techniques. <a href="https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project">The Linux kernel Self Protection project</a> [1] tries to take this further by offering Kernel Self Protection features, the aim to protect against known and unknown Linux kernel bugs and vulnerabilities.</p><p><strong>Some Embedded Kernel Hardening features:</strong></p><blockquote><strong>CONFIG_DEFAULT_MMAP_MIN_ADDR=32768</strong> Disallow allocating the first 32k of memory to protect against kernel null pointer dereference and related exploits.</blockquote><blockquote><strong>CONFIG_STRICT_KERNEL_RWX=y</strong> Make kernel text and rodata read-only. Kernel version of W^X.</blockquote><blockquote><strong>CONFIG_STRICT_DEVMEM=y </strong>and<strong> CONFIG_IO_STRICT_DEVMEM=y </strong>restrict physical memory access.</blockquote><blockquote><strong>CONFIG_SECCOMP=y</strong> and <strong>CONFIG_SECCOMP_FILTER=y</strong> allows userspace to reduce the attack surface.</blockquote><blockquote><strong>STATIC_USERMODEHELPER=y</strong> Force all usermode helper calls through a single binary</blockquote><blockquote><strong>CONFIG_HARDENED_USERCOPY=y</strong> performs extra usercopy checks.</blockquote><p>For more security features, please check the following <a href="https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project/Recommended_Settings">Kernel Self Protection Project guide</a> [2]. There are lot of features that needs to be disabled on production systems. You should also consider <strong><em>trusted boot</em></strong> and <strong><em>TPM</em></strong> support from the beginning, they are not perfect but it is an extra layer to measure the boot process and allow <strong>TPM</strong> to act on that.</p><p><strong>Current/Future plans:</strong></p><p><strong><em>Modernization of proc file system</em>: </strong>I have been working on modernizing Linux <a href="https://lkml.org/lkml/2017/4/25/282">proc API [3].</a> The <strong>procfs</strong> file system is an old virtual file system that exposes lot of kernel information, some of these files can be used as a source for information leaks to get kernel addresses and construct complex attacks. We have came to the conclusion that <strong>procfs</strong> needs to be updated and it is blocking lot of other Linux features. Together with <strong><em>Alexey Gladkov </em></strong>and based on <strong><em>Andy Lutomirski</em></strong> feedback, we have a branch here: <a href="https://github.com/legionus/linux/commits/pidfs-v4">https://github.com/legionus/linux/commits/pidfs-v4</a> [4] that allows to improve Linux <strong>procfs</strong> and protect exposed kernel files, only <strong>/proc/&lt;pids&gt;/</strong> files will be available.</p><p>It also allows to have separate procfs instances per App, this means you are not forced anymore to use PID namespaces to hide some processes, simply mounting a new separate procfs instance with “hidepid=” will allow to hide at some degree other processes that belong to other users, and without using PID namespaces. This is useful for Linux-based IoT, as we may not need to have multiple PID namespace managers. Another introduction RFC is planed soon to try to make the transition as smooth as possible.</p><p><strong><em>Automatic module loading protection</em>: </strong>historically, Linux was always able to transparently load kernel modules to satisfy user functionality when needed, this is a crucial point for a better user experience. However, this feature can be abused to load vulnerable modules and exploit some kernel bugs. Several examples come to mind:</p><p><a href="http://seclists.org/oss-sec/2017/q1/471">The 11 year old DCCP double free vulnerability CVE-2017–6074</a> [5]</p><p><a href="https://a13xp0p0v.github.io/2017/03/24/CVE-2017-2636.html">CVE-2017–2636: exploit the race condition in the n_hdlc Linux kernel driver bypassing SMEP</a> [6]</p><p><a href="http://www.openwall.com/lists/oss-security/2017/03/29/2">kernel: Local privilege escalation in XFRM framework CVE-2017–7184</a> [7] it was advertised that maybe this vulnerability was used to break Ubuntu systems on security contests.</p><p>Most Embedded Linux systems should not allow module loading at all, or only a subset of signed modules, however there are products that need unrestricted module support. Inspired by <a href="https://grsecurity.net/">Grsecurity MODHARDEN</a> [8] feature, we have tried to implement a new generic module autoloading restriction that can be used by sandbox tools. The result is here: <a href="https://lkml.org/lkml/2017/5/22/312">https://lkml.org/lkml/2017/5/22/312</a> [9]. Thanks to <strong><em>Kees Cook</em></strong>, <strong><em>Solar Designer</em></strong> and <strong><em>Andy Lutomirski</em></strong> for the feedback, I am planning v5.</p><p><strong><em>Generalizing YAMA LSM</em>: </strong><a href="https://www.kernel.org/doc/Documentation/security/Yama.txt"><strong>Yama LSM</strong></a><strong> </strong>[10] is a Linux security module with a clear purpose of protecting processes from being controlled by other processes using <a href="http://man7.org/linux/man-pages/man2/ptrace.2.html">ptrace</a> functionality. Recently, I have been experimenting on how to generalize this behaviour to other kernel interfaces and system calls. The aim is to have a simple interface to restrict some operations from operating on arbitrary processes, or processes that run under a different User ID. This should be a default kernel hardening measure on Embedded Linux.</p><h3>systemd Sandbox or systemd Lightweight Containers</h3><p>Sandboxing IoT Apps is another important step, it allows to reduce the exposure from mis-configuration, bugs, or vulnerability exploitation. As a simple example the BrickerBot and similar worms did not use complex 0day exploits. They used simple attack vectors like unprotected remote shells accounts and according to internet resources, lot of IoT devices were affected. The straightforward solution in this case should be a firewall solution plus a powerful sandbox mechanism for apps.</p><p>While with every new <a href="https://lists.freedesktop.org/archives/systemd-devel/2017-October/039589.html">systemd release</a> we continue to introduce new sandbox mechanisms, by default all these mechanisms are an opt-in operation, in the future we are planning to maybe add another run-time mode to make the sandbox an opt-out operation. Meanwhile, systemd manager now allows you to run your apps from an image like most other container runtimes. However, systemd does not use any standard format, since most of the container run-times that are using this schema are usually over-engineered, and some of them are abusing some Linux kernel features to hide some other misbehavior, etc. In systemd, right now we support Lightweight Containers, by using only file system Mount Namespaces to isolate and ship Apps with their dependencies, we avoid for now the container managers complexity. Network namespaces are used rarely to only block internet access for Apps by disconnecting network interfaces. We may improve network namespace usage, but only to make it easy to integrate within the <strong>“ip”</strong> tool, that should handle all possible network cases for Embedded Linux setups.</p><p>The following lists some new systemd sandbox options:</p><ol><li><strong><em>New File system sandbox option:</em></strong></li></ol><blockquote><strong><em>RootImage=</em></strong> Takes a path to a block device, loopback file, etc that can be mounted as the new root filesystem for your App.</blockquote><p><strong><em>2. Some User privileges sandbox options:</em></strong></p><blockquote><strong><em>DynamicUser=</em></strong> If set to yes, allows to run your App under different User (Unix UID/GID). The UID is allocated dynamically and released when the App stops, allowing IoT devices to follow Android model where each App is executed under a different user, separating Apps and their file access permissions.</blockquote><blockquote><strong><em>NoNewPrivileges=</em></strong> If set, ensures that the App and all its children can never gain new privileges through execve().</blockquote><p><strong><em>3. Some Network sandbox options:</em></strong></p><blockquote><strong><em>PrivateNetwork=</em></strong> If set to yes, will set up a new private network namespace with only loopback interface inside, disconnecting internet access.</blockquote><blockquote><strong><em>IPAddressDeny=</em></strong> Takes an IP address prefix, all traffic from and to this address will be blocked for the App.</blockquote><blockquote><strong><em>IPAddressAllow=</em></strong> The whitelist or permitted IP address/network mask list.</blockquote><blockquote>To block raw packets <strong><em>AF_PACKET</em></strong> you should also use:</blockquote><blockquote><strong><em>RestrictAddressFamilies=~AF_PACKET</em></strong> (blacklisting mode).</blockquote><blockquote>We are working to make this more user friendly, maybe in the near feature we will add: <strong><em>“ACCESS_INTERNET=yes|no”</em></strong> alias for those options to effectively block all inet or internet operations, including constructing raw packets and binding privileged ports.</blockquote><p><strong><em>4. Kernel attack surface reduction:</em></strong></p><blockquote><strong><em>RestrictNamespaces= </em></strong>Restrict Access to Linux namespaces. Most IoT devices should reduce access to Linux User Namespaces since some vulnerabilities and exploits are still targeting this feature. <strong><em>“RestrictNamespaces=yes” or “RestrictNamespaces=~user”</em></strong></blockquote><blockquote><strong><em>ProtectKernelTunables=</em></strong> Blocks tuning Kernel parameters by making <strong>/proc</strong> and related <strong>/sys</strong> files read-only.</blockquote><blockquote><strong><em>ProtectKernelModules=</em></strong> If set, removes the <strong>CAP_SYS_MODULE</strong> capability and blocks your App from explicitly loading or unloading modules.</blockquote><blockquote><strong><em>SystemCallFilter=</em></strong> Seccomp system call filtering feature. In systemd we have organized Linux system calls in groups inspired from Google Chromium browser. You can restrict your App by functionality by blacklisting the system calls using the <strong>“~”</strong> before each group. As an example:</blockquote><blockquote><strong><em>“@reboot”</em></strong> will block all related reboot system calls.</blockquote><blockquote><strong><em>“@module”</em></strong> will block all kernel module system calls.</blockquote><blockquote><strong><em>“@mount”</em></strong> will block all file system mount and umount system calls.</blockquote><p>For more system call filtering please refer to official systemd documentation <a href="https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=">systemd.exec</a> [11]. We have a pretty usable system call filtering feature, and we are actively working on improving it. In the near feature we are planning to add more usable groups and improve our sandbox model: <a href="https://github.com/systemd/systemd/pull/6963">https://github.com/systemd/systemd/pull/6963</a> [12].</p><p><strong>Future plans for systemd: </strong>as the systemd project continue to evolve to handle new use cases, we have to face reality: we need 1) reduce our functionality to better handle some IoT requirements, 2) integrate with software update mechanisms. On a more generic approach we have to support more user friendly features. In the past, systemd was intended to be used by experienced service developers and SysVinit experts, today the user base is more of Container and Android Apps model users. <strong><em>This does not mean that we have to copy those models, but we should start with a new smooth run-time model.</em></strong></p><h3>Other Important Security Mechanisms</h3><p>Now days, robust IoT products need to support a software update mechanism, bugs or vulnerabilities may have a long lifetime. A recent research by <strong><em>Kees Cook</em></strong> suggests that between the introduction of a vulnerability and its final fix it is <strong><em>“roughly 5 years”</em></strong>, if you are interested you can read about at his blog <a href="https://outflux.net/blog/archives/2016/10/18/security-bug-lifetime/">Security bug lifetime</a> [13].</p><p>IoT system updates are a hot topic and the sessions at next week “<a href="http://all-systems-go.io/">All systems go 2017”</a> [14] conference confirm this, make sure to check:</p><p><a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/122">“Software updates for connected Linux devices: key requirements”</a> by <strong><em>Drew Moseley</em></strong> from <a href="https://mender.io/">Mender.io</a> [15] [16]</p><p><a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/129">“The IoT botnet wars, Linux devices, and the absence of basic security hardening”</a> by <strong><em>Drew Moseley</em></strong> from <a href="https://mender.io/">Mender.io</a> [16] [17]</p><p><a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/133">“Updating Embedded Systems — Putting it all Together”</a> by <strong><em>Michael Olbrich </em></strong>from <a href="http://pengutronix.de/">pengutronix.de</a> [18]</p><p><a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/112">“Modern deployment for Embedded Linux and IoT”</a> mine [19]</p><p>Updating full system images, operating on the block layer and chunk based updates are all neat features, several new technologies are emerging, <a href="https://github.com/systemd/casync">casync “Content Addressable Data Synchronizer”</a> [20] is one example. Others like <a href="https://mender.io/">Mender.io</a> are already offering an Over-the-air software update solution for Embedded Linux.</p><p>There are also other specialized solutions using the container based approach, the just released <a href="https://www.balena.io/">balena</a> [21], a Moby-based container engine for IoT [ref] that should replace default docker <a href="https://www.resinos.io/">in Resin OS</a> [22] seems promising. There are use cases where full containers are the solution, with the new balena, resinOS can be adapted to easily integrate with more resource constrained embedded systems.</p><p>Finally and to conclude the next <a href="https://all-systems-go.io/"><strong>All systems go 2017 conf</strong></a> has some other interesting tracks related to Embedded Linux and Security:</p><p><a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/140">“Building a secure boot chain to userland”</a> by <strong><em>Matthew Garrett [23]</em></strong></p><p><a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/119">“Securing Home Automation with Tor”</a> by <strong><em>Kalyan Dikshit [24]</em></strong></p><p>Thanks!</p><p><strong>References:</strong></p><p>[1] <a href="https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project">https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project</a></p><p>[2] <a href="https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project/Recommended_Settings">https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project/Recommended_Settings</a></p><p>[3] <a href="https://lkml.org/lkml/2017/4/25/282">https://lkml.org/lkml/2017/4/25/282</a></p><p>[4] <a href="https://github.com/legionus/linux/commits/pidfs-v4">https://github.com/legionus/linux/commits/pidfs-v4</a></p><p>[5] <a href="http://seclists.org/oss-sec/2017/q1/471">http://seclists.org/oss-sec/2017/q1/471</a></p><p>[6] <a href="https://a13xp0p0v.github.io/2017/03/24/CVE-2017-2636.html">https://a13xp0p0v.github.io/2017/03/24/CVE-2017-2636.html</a></p><p>[7] <a href="http://www.openwall.com/lists/oss-security/2017/03/29/2">http://www.openwall.com/lists/oss-security/2017/03/29/2</a></p><p>[8] <a href="https://grsecurity.net/">https//:grsecurity.net/</a></p><p>[9] <a href="https://lkml.org/lkml/2017/5/22/312">https://lkml.org/lkml/2017/5/22/312</a></p><p>[10] <a href="https://www.kernel.org/doc/Documentation/security/Yama.txt">https://www.kernel.org/doc/Documentation/security/Yama.txt</a></p><p>[11] <a href="https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=">https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=</a></p><p>[12] <a href="https://github.com/systemd/systemd/pull/6963">https://github.com/systemd/systemd/pull/6963</a></p><p>[13] <a href="https://outflux.net/blog/archives/2016/10/18/security-bug-lifetime/">https://outflux.net/blog/archives/2016/10/18/security-bug-lifetime/</a></p><p>[14] <a href="https://all-systems-go.io/">https://all-systems-go.io/</a></p><p>[15] <a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/122">https://cfp.all-systems-go.io/en/ASG2017/public/events/122</a></p><p>[16] <a href="https://mender.io/">https://mender.io/</a></p><p>[17] <a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/129">https://cfp.all-systems-go.io/en/ASG2017/public/events/129</a></p><p>[18] <a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/133">https://cfp.all-systems-go.io/en/ASG2017/public/events/133</a></p><p>[19] <a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/112">https://cfp.all-systems-go.io/en/ASG2017/public/events/112</a></p><p>[20] <a href="https://github.com/systemd/casync">https://github.com/systemd/casync</a></p><p>[21] <a href="https://www.balena.io/">https://www.balena.io/</a></p><p>[22] <a href="https://resinos.io/">https://resinos.io/</a></p><p>[23] <a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/140">https://cfp.all-systems-go.io/en/ASG2017/public/events/140</a></p><p>[24] <a href="https://cfp.all-systems-go.io/en/ASG2017/public/events/119">https://cfp.all-systems-go.io/en/ASG2017/public/events/119</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd7dc31b38fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IoT Lightweight Linux Containers]]></title>
            <link>https://medium.com/@tixxdz/iot-lightweight-linux-containers-d3aa6d792f86?source=rss-bf8e76cbd364------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3aa6d792f86</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Djalal Harouni]]></dc:creator>
            <pubDate>Fri, 05 May 2017 18:23:08 GMT</pubDate>
            <atom:updated>2017-05-05T18:23:08.073Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>As Linux containers continue to evolve rapidly, their adoption in the Embedded and IoT industry is subject sometimes to adaptation to mainly fit the final run-time environment. In this article we will see how we can use some Linux features to have some sort of Container privacy.</p><p>Everyone has his own definition of “Containers” but maybe some will agree that they should offer: 1) A quick develop and ship workflow by isolating the program and its resources from the rest of the system, and 2) A sandbox mechanism. There are already tools to solve these needs, however from an Embedded and IoT context maybe some of these tools need to be adapted to be more friendly to their environment and to the final devices where apps are shipped.</p><h3><strong>IoT Containers and Sandboxes</strong></h3><p><a href="https://resin.io/how-it-works/">Resin.io [1]</a> is one notable example, they did manage to offer a platform running the <strong>resinOS </strong>that is generated with a Yocto layer named “meta-resin”, this whole infrastructure allows them to support multiple devices and bring Linux Containers and <strong>docker</strong> support transparently. There are also other examples, and other IoT vendors that seem to use lightweight sandbox tools to mimic at some degree containers functionality. Maybe we will see more flavors.</p><p>Using one specific<strong> </strong>resource bundling format in an IoT<strong> </strong>world can be a bit restrictive, one has to ensure that apps can be ported from one container engine or version to another easily, not to mention the security aspect if this fails. Therefore, I think it would be better maybe to have a generic setup where the container resources are in a form of a simple directory tree, a tarball, subvolume, raw image, etc. Linux kernel asserts backward compatibility, mount namespaces can be used to solve resource bundling and isolation, and finally the tools to encode and decode such generic formats are already there. All this brings us to the next point <strong>Lightweight Containers and Sandboxes</strong>.</p><h3><strong>Lightweight Containers and Sandboxes</strong></h3><p>First, probably it just makes sense to cite the building blocks that allow to make Linux containers which are: <em>namespaces</em> and <em>cgroups</em>, and point to the following LWN article <a href="https://lwn.net/Articles/531114/">“Namespaces in operation” [2]</a> that explains Linux namepsaces. As said in the beginning, everyone has his own view on what “Containers” mean, so I will spare you the pain and say that “Lightweight Containers” are Containers without all the Linux namespace features.</p><p>Lennart Poettering already presented the <em>“portable system services” </em>idea which is basically integrate services or apps with the system, have some kind of resource bundling, and let the sandbox mechanism handle host and services security. You can read more about it in this LWN <a href="https://lwn.net/Articles/706025/">“Portable system services” [3]</a> article.</p><p>Some of these ideas make lot of sense in IoT world, we may need some Linux namespaces but not all of them. The mount namespace is the most important one as we need it to ship apps and related resources, at the same time they need to be isolated from each other.</p><p>In the other hand the PID (Process ID) namespace [4] and depending on the use-cases can be omitted. Creating PID namespaces consumes resources, in each PID namespace we need a reaper, Linux kernel implementation assumes that there is always a reaper per PID namespace. Container folks are aware of this, hence they introduce workarounds to have a stub process to collect signals, reap processes, etc.</p><p>I have been using <strong>ResinOS</strong>, but at same time I also built my own setup, and came to the conclusion that: in some cases I really should omit using PID namespaces. I need one supervisor plus a monitoring feature, why should I duplicate some functionality on each PID namespace ? then why I am using PID namespaces at all ? and most of the time the response is: “<strong>privacy”.</strong></p><p>If I have some apps shipped with all their resources on my IoT, I do not want them to peek on each other. Currently in Linux you can access other processes memory by using the <strong><em>ptrace syscall</em></strong> [6] or some other direct system calls to check or compare processes related resources, all these can be restricted by a sandbox mechanism using <strong><em>seccomp filters</em></strong> [7] or by running apps under different UIDs. In the other hand<strong><em>, procfs /proc/&lt;pids&gt;/ </em></strong>[8] can still be used to peek on processes by using filesystem system calls. A process can peek on <strong><em>/proc/&lt;pids&gt;/</em></strong> and seccomp filters will not help in this case.</p><p>There is a <strong><em>procfs</em></strong> protection <strong><em>“hidepid” </em></strong>that allows to hide processes inside procfs that we can not <strong><em>ptrace</em></strong>. It is really effective and it comes from <strong><em>Openwall</em></strong> and <strong><em>grsecurity</em></strong> patches. It was designed back in the times for shared hosting to prevent users and scripts to reveal website access activities, it was upstreamed by Vasiliy Kulikov<strong> </strong>heya :)! thanks to him!</p><p>However, with today’s use-cases the protection needs to be modernized, it comes in a way <em>“all or nothing”</em>, if you have one app that needs to read <strong><em>/proc/&lt;pids&gt;/</em> </strong>then applying “hidepid” protection will affect all apps including the app that needs to read <strong><em>/proc/&lt;pids&gt;/</em></strong> which is too restrictive. The only way to go around it is to create a new PID namespace which brings us back to the first issue.</p><p>The real issue is: internally <strong><em>procfs</em></strong> mounts are shared inside the same PID namespace, updating one <strong><em>procfs</em></strong> mount will propagate to all other mounts.</p><p>Different Linux subsystems have been modernized to work better under containers or sandboxes. The <strong><em>devpts</em></strong> filesystem [9] is one real example where different mounts used to be shared, now by default each new <strong><em>devpts</em></strong> mount is a distinct mount totally separated from others. It seems that <strong><em>procfs</em></strong> needs also to go under the same modernization which will allow to have separate <strong><em>procfs </em></strong>mounts per app under the same PID namespace, allowing to block processes from peeking on each other by default, without creating new PID namespaces for each app.</p><p>I had some private patches that allowed to block processes from reading other processes through <strong><em>/proc/&lt;pids&gt;/</em></strong> without affecting other <strong><em>procfs</em></strong> mounts or apps, I was successfully using them but I did never submit them to upstream. After a discussion with Andy Lutomirski<em> </em>it turned out that this will not really fit upstream,<em> </em>therefor and as suggested by Andy another approach was proposed to upstream. We allow <strong><em>procfs</em></strong> to have new separated instances, each app can have its own private instance where mount or remount operations will not propagate to other <strong><em>procfs</em></strong> mounts that are inside the same PID namespace. This is better for Linux and it allows to modernize and fix some leftover things.</p><p>The actual patches: <a href="https://lkml.org/lkml/2017/4/25/282"><strong>Patches: RFC v2 proc: support private proc instances per pidnamespace</strong></a> [10].</p><p>With these patches, apps will not be able to notice other processes through <strong><em>/proc/&lt;pids&gt;/</em></strong> , this means running <strong><em>“ps”</em></strong> or <strong><em>“top”</em></strong> won’t show other processes. Of course there are other ways to know if a <strong><em>pid</em></strong> is active or not, these can be solved on their own later.</p><h3><strong>Conclusion</strong></h3><p>The referenced proc patches allow to modernize <strong><em>procfs, </em></strong>they are still an RFC that will hopefully be cleaned and submitted again.</p><p>The other improvement of these patches is that it will give Linux Security Modules a security path inside <strong><em>procfs </em></strong>for pids. LSMs can use it to tighten access, as an example Yama LSM can be updated to only allow access to inferior processes through <strong><em>/proc/&lt;pids&gt;/ , </em></strong>allowing maybe later to have some privacy for processes that run under same user…</p><p>Without getting out of the context and to conclude, this article focused mainly on Embedded and IoT Linux, of course everyone has its own use-cases, some will use all the features, others will only use a subset, that is totally fine!</p><p>Maybe in next article we will see how to improve and optimize apps monitoring or lightweight monitoring witch such setups.</p><h3><strong>References:</strong></h3><p>[1] <a href="https://resin.io/how-it-works/">https://resin.io/how-it-works/</a></p><p>[2] <a href="https://lwn.net/Articles/531114/">https://lwn.net/Articles/531114/</a></p><p>[3] <a href="https://lwn.net/Articles/706025/">https://lwn.net/Articles/706025/</a></p><p>[4] <a href="http://man7.org/linux/man-pages/man7/pid_namespaces.7.html">http://man7.org/linux/man-pages/man7/pid_namespaces.7.html</a></p><p>[5] <a href="https://docs.resin.io/runtime/runtime/">https://docs.resin.io/runtime/runtime/</a></p><p>[6] <a href="http://man7.org/linux/man-pages/man2/ptrace.2.html">http://man7.org/linux/man-pages/man2/ptrace.2.html</a></p><p>[7] <a href="http://man7.org/linux/man-pages/man2/seccomp.2.html">http://man7.org/linux/man-pages/man2/seccomp.2.html</a></p><p>[8] <a href="https://www.kernel.org/doc/Documentation/filesystems/proc.txt">https://www.kernel.org/doc/Documentation/filesystems/proc.txt</a></p><p>[9] <a href="http://elixir.free-electrons.com/linux/v4.11/source/Documentation/filesystems/devpts.txt">http://elixir.free-electrons.com/linux/v4.11/source/Documentation/filesystems/devpts.txt</a></p><p>[10] <a href="https://lkml.org/lkml/2017/4/25/282">https://lkml.org/lkml/2017/4/25/282</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3aa6d792f86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>