<?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:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/">
  <channel>
    <title>kernel</title>
    <link>https://www.linuxjournal.com/</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Primer to Container Security</title>
  <link>https://www.linuxjournal.com/content/primer-container-security</link>
  <description>  &lt;div data-history-node-id="1340883" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-field-node-image field--type-image field--label-hidden field--item"&gt;  &lt;img loading="lazy" src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/primer-to-container-security.jpg" width="850" height="500" alt="Primer to Container Security" typeof="foaf:Image" class="img-responsive" /&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/ankur-kothiwall" lang="" about="https://www.linuxjournal.com/users/ankur-kothiwall" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Ankur Kothiwal&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p dir="ltr"&gt;Containers are considered to be a standard way of deploying these microservices to the cloud. Containers are better than virtual machines in almost all ways except security, which may be the main barrier to their widespread adoption.&lt;/p&gt;

&lt;p dir="ltr"&gt;This article will provide a better understanding of container security and available techniques to secure them.&lt;/p&gt;

&lt;p&gt;A Linux container can be defined as a process or a set of processes running in the userspace that is/are isolated from the rest of the system by different kernel tools.&lt;/p&gt;

&lt;p dir="ltr"&gt;Containers are great alternatives to virtual machines (VMs). Even though containers and virtual machines provide the same isolation benefits, they differ in the way that containers provide operating system virtualization instead of hardware. This makes them lightweight, faster to start, and consumes less memory.&lt;/p&gt;

&lt;p dir="ltr"&gt;As multiple containers share the same kernel, the solution is less secure than the VMs, where they have their copies of OS, libraries, dedicated resources, and applications. That makes VM excellently secure but because of their high storage size and reduced performance, it creates a limitation on the total number of VMs which can be run simultaneously on a server. Further VMs take a lot of time to boot.&lt;/p&gt;

&lt;p dir="ltr"&gt;The introduction of microservice architecture has changed the way of developing software. Microservices allow the development of software in small self-contained independent services. This makes the application easier to scale and provides agility.&lt;/p&gt;

&lt;p dir="ltr"&gt;If a part of the software needs to be rewritten it can easily be done by changing only that part of the code without interrupting any other service, which wasn't possible with the monolithic kernel.&lt;/p&gt;
&lt;figure role="group" class="image-max_1300x1300 align-center"&gt;&lt;img alt="Protection requirement use cases and solutions" data-entity-type="file" data-entity-uuid="eb7d3c7b-a755-4781-b600-3838da0064ce" height="321" src="https://www.linuxjournal.com/sites/default/files/inline-images/protection-requirement-use-cases-and-solutions.jpg" width="741" loading="lazy" /&gt;&lt;figcaption&gt;&lt;em&gt;Protection requirement use cases and solutions&lt;/em&gt;&lt;/figcaption&gt;&lt;/figure&gt;&lt;h2 dir="ltr"&gt;1) Linux Kernel Features&lt;/h2&gt;

&lt;h3 dir="ltr"&gt;a. Namespaces

&lt;/h3&gt;&lt;p dir="ltr"&gt;Namespaces ensure the isolation of resources for processes running in a container to that of others. They partition the kernel resources for different processes. One set of processes in a separate namespace will see one set of resources while another set of processes will see another. Processes in different see different process IDs, hostnames, user IDs, file names, names for network access, and some interprocess communication. Hence, each file system namespace has its private mount table and root directory.&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/primer-container-security" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Thu, 05 May 2022 16:00:00 +0000</pubDate>
    <dc:creator>Ankur Kothiwal</dc:creator>
    <guid isPermaLink="false">1340883 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Oops! Debugging Kernel Panics</title>
  <link>https://www.linuxjournal.com/content/oops-debugging-kernel-panics-0</link>
  <description>  &lt;div data-history-node-id="1340581" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/petros-koutoupis" lang="" about="https://www.linuxjournal.com/users/petros-koutoupis" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Petros Koutoupis&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;A look into what causes kernel panics and some utilities to help gain
more information.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
Working in a Linux environment, how often have you seen a kernel panic?
When it happens, your system is left in a crippled state until
you reboot it completely. And, even after you get your system back into a
functional state, you're still left with the question: why? You may have no
idea what happened or why it happened. Those questions can be answered
though,
and the following guide will help you root out the cause of some of the conditions
that led to the original crash.
&lt;/p&gt;

&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/panic.png" width="650" height="358" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 1. A Typical Kernel Panic&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
Let's start by looking at a set of utilities known as
&lt;code&gt;kexec&lt;/code&gt; and &lt;code&gt;kdump&lt;/code&gt;. &lt;code&gt;kexec&lt;/code&gt; allows you to boot into
another kernel from an existing (and running) kernel, and
&lt;code&gt;kdump&lt;/code&gt; is a
&lt;code&gt;kexec&lt;/code&gt;-based crash-dumping mechanism for Linux.
&lt;/p&gt;


&lt;span class="h3-replacement"&gt;
Installing the Required Packages&lt;/span&gt;

&lt;p&gt;
First and foremost, your kernel should have the following components statically built in to its image:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
CONFIG_RELOCATABLE=y
CONFIG_KEXEC=y
CONFIG_CRASH_DUMP=y
CONFIG_DEBUG_INFO=y
CONFIG_MAGIC_SYSRQ=y
CONFIG_PROC_VMCORE=y
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
You can find this in &lt;code&gt;/boot/config-`uname -r`&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Make sure that your operating system is up to date with the latest-and-greatest package versions:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
$ sudo apt update &amp;&amp; sudo apt upgrade
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
Install the following packages
(I'm currently using Debian, but the
same should and will apply to Ubuntu):

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
$ sudo apt install gcc make binutils linux-headers-`uname -r`
 ↪kdump-tools crash `uname -r`-dbg
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;&lt;em&gt;Note: Package names may vary
across distributions.&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
During the installation, you will be prompted with questions to enable
&lt;code&gt;kexec&lt;/code&gt; to handle reboots (answer whatever you'd like, but I answered
"no"; see Figure 2).
&lt;/p&gt;

&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/kexec.png" width="650" height="362" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 2.
kexec Configuration Menu&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
And to enable &lt;code&gt;kdump&lt;/code&gt; to run and load at system boot, answer
"yes" (Figure 3).
&lt;/p&gt;

&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/kdump.png" width="650" height="361" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 3.
kdump Configuration Menu&lt;/em&gt;&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Configuring kdump&lt;/span&gt;

&lt;p&gt;
Open the /etc/default/kdump-tools file, and at the very top,
you should see the following:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/oops-debugging-kernel-panics-0" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 07 Aug 2019 23:30:00 +0000</pubDate>
    <dc:creator>Petros Koutoupis</dc:creator>
    <guid isPermaLink="false">1340581 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Documenting Proper Git Usage</title>
  <link>https://www.linuxjournal.com/content/documenting-proper-git-usage</link>
  <description>  &lt;div data-history-node-id="1340753" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/zack-brown" lang="" about="https://www.linuxjournal.com/users/zack-brown" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Zack Brown&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
&lt;strong&gt;Jonathan Corbet&lt;/strong&gt; wrote a document for inclusion in the kernel tree, describing
best practices for merging and rebasing &lt;strong&gt;git&lt;/strong&gt;-based kernel repositories. As he put
it, it represented workflows that were actually in current use, and it was a living
document that hopefully would be added to and corrected over time.
&lt;/p&gt;

&lt;p&gt;
The inspiration for the document came from noticing how frequently &lt;strong&gt;Linus
Torvalds&lt;/strong&gt;
was unhappy with how other people—typically subsystem maintainers—handled
their git trees.
&lt;/p&gt;

&lt;p&gt;
It's interesting to note that before Linus wrote the git tool, branching and
merging was virtually unheard of in the Open Source world. In &lt;strong&gt;CVS&lt;/strong&gt;, it was a
nightmare horror of leechcraft and broken magic. Other tools were not much better.
One of the primary motivations behind git—aside from blazing speed—was, in
fact, to make branching and merging trivial operations—and so they have become.
&lt;/p&gt;

&lt;p&gt;
One of the offshoots of branching and merging, Jonathan wrote, was rebasing—altering the patch history of a local repository. The benefits of rebasing are
fantastic. They can make a repository history cleaner and clearer, which in turn
can make it easier to track down the patches that introduced a given bug. So
rebasing has a direct value to the development process.
&lt;/p&gt;

&lt;p&gt;
On the other hand, used poorly, rebasing can make a big mess. For example, suppose
you rebase a repository that has already been merged with another, and then merge
them again—insane soul death.
&lt;/p&gt;

&lt;p&gt;
So Jonathan explained some good rules of thumb. Never rebase a repository that's
already been shared. Never rebase patches that come from someone else's repository.
And in general, simply never rebase—unless there's a genuine reason.
&lt;/p&gt;

&lt;p&gt;
Since rebasing changes the history of patches, it relies on a new "base" version,
from which the later patches diverge. Jonathan recommended choosing a base version
that was generally thought to be more stable rather than less—a new version or a
release candidate, for example, rather than just an arbitrary patch during regular
development.
&lt;/p&gt;

&lt;p&gt;
Jonathan also recommended, for any rebase, treating all the rebased patches as new
code, and testing them thoroughly, even if they had been tested already prior to
the rebase.
&lt;/p&gt;

&lt;p&gt;
"If", he said, "rebasing is limited to private trees, commits are based on a
well-known starting point, and they are well tested, the potential for trouble is
low."
&lt;/p&gt;

&lt;p&gt;
Moving on to merging, Jonathan pointed out that nearly 9% of all kernel commits
were merges. There were more than 1,000 merge requests in the 5.1 development cycle
alone.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/documenting-proper-git-usage" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 07 Aug 2019 22:30:00 +0000</pubDate>
    <dc:creator>Zack Brown</dc:creator>
    <guid isPermaLink="false">1340753 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Another Episode of "Seems Perfectly Feasible and Then Dies"--Script to Simplify the Process of Changing System Call Tables</title>
  <link>https://www.linuxjournal.com/content/another-episode-seems-perfectly-feasible-and-then-dies-script-simplify-process-changing</link>
  <description>  &lt;div data-history-node-id="1340754" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/zack-brown" lang="" about="https://www.linuxjournal.com/users/zack-brown" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Zack Brown&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
&lt;strong&gt;David Howells&lt;/strong&gt; put in quite a bit of work on a script,
./scripts/syscall-manage.pl, to simplify the entire process of changing the
system call tables. With this script, it was a simple matter to add, remove,
rename or renumber any system call you liked. The script also would resolve
&lt;strong&gt;git&lt;/strong&gt;
conflicts, in the event that two repositories renumbered the system calls in
conflicting ways.
&lt;/p&gt;

&lt;p&gt;
Why did David need to write this patch? Why weren't system calls already fairly
easy to manage? When you make a system call, you add it to a master list, and then
you add it to the system call "tables", which is where the running kernel looks up
which kernel function corresponds to which system call number. Kernel developers
need to make sure system calls are represented in all relevant spots in the source
tree. Renaming, renumbering and making other changes to system calls involves a
lot of fiddly little details. David's script simply would do everything
right—end
of story no problemo hasta la vista.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Arnd Bergmann&lt;/strong&gt; remarked, "Ah, fun. You had already threatened to add that script in
the past. The implementation of course looks fine, I was just hoping we could
instead eliminate the need for it first." But, bowing to necessity, Arnd offered
some technical suggestions for improvements to the patch.
&lt;/p&gt;

&lt;p&gt;
However, &lt;strong&gt;Linus Torvalds&lt;/strong&gt; swooped in at this particular moment, saying:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;
Ugh, I hate it.
&lt;/p&gt;

&lt;p&gt;
I'm sure the script is all kinds of clever and useful, but I really think the
solution is not this kind of helper script, but simply that we should work at not
having each architecture add new system calls individually in the first place.
&lt;/p&gt;

&lt;p&gt;
IOW, we should look at having just one unified table for new system call numbers,
and aim for the per-architecture ones to be for "legacy numbering".
&lt;/p&gt;

&lt;p&gt;
Maybe that won't happen, but in the _hope_ that it happens, I really would prefer
that people not work at making scripts for the current nasty situation.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
And the portcullis came crashing down.
&lt;/p&gt;

&lt;p&gt;
It's interesting that, instead of accepting this relatively obvious improvement to
the existing situation, Linus would rather leave it broken and ugly, so that
someone someday somewhere might be motivated to do the harder-yet-better fix. And,
it's all the more interesting given how extreme the current problem is. Without
actually being broken, the situation requires developers to put in a tremendous
amount of care and effort into something that David's script could make trivial and
easy. Even for such an obviously "good" patch, Linus gives thought to the policy
and cultural implications, and the future motivations of other people working in
that region of code.
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: if you're mentioned above and want to post a response above the comment section, send a message with your response text to ljeditor@linuxjournal.com.&lt;/em&gt;&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/another-episode-seems-perfectly-feasible-and-then-dies-script-simplify-process-changing" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 07 Aug 2019 20:45:00 +0000</pubDate>
    <dc:creator>Zack Brown</dc:creator>
    <guid isPermaLink="false">1340754 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Simplifying Function Tracing for the Modern GCC</title>
  <link>https://www.linuxjournal.com/content/simplifying-function-tracing-modern-gcc</link>
  <description>  &lt;div data-history-node-id="1340683" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/zack-brown" lang="" about="https://www.linuxjournal.com/users/zack-brown" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Zack Brown&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
&lt;strong&gt;Steven Rostedt&lt;/strong&gt; wanted to do a little housekeeping, specifically with the function
tracing code used in debugging the kernel. Up until then, the kernel could enable
function tracing using either &lt;strong&gt;GCC&lt;/strong&gt;'s &lt;code&gt;-pg&lt;/code&gt; flag or a
combination of &lt;code&gt;-pg&lt;/code&gt; and
&lt;code&gt;-mfentry&lt;/code&gt;. In each case, GCC would create a special routine that would execute at the
start of each function, so the kernel could track calls to all functions. With just
&lt;code&gt;-pg&lt;/code&gt;, GCC would create a call to &lt;code&gt;mcount()&lt;/code&gt; in all C functions,
although with &lt;code&gt;-pg&lt;/code&gt; coupled
with &lt;code&gt;-mfentry&lt;/code&gt;, it would create a call to &lt;code&gt;fentry()&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Steven pointed out that using &lt;code&gt;-mfentry&lt;/code&gt; was generally regarded as superior, so much so
that the kernel build system always would choose it over the &lt;code&gt;mcount()&lt;/code&gt; alternative by
testing GCC at compile time to see if it actually supported that command-line argument.
&lt;/p&gt;

&lt;p&gt;
This is all very normal. Since any user might have any version of a given piece of
software in the toolchain, or a variety of different CPUs and so on, each with different
capabilities, the kernel build system runs many tests to identify the best available
features that the kernel will be able to rely on.
&lt;/p&gt;

&lt;p&gt;
But in this case, Steven noticed that for &lt;strong&gt;Linux version 4.19&lt;/strong&gt;,
&lt;strong&gt;Linus Torvalds&lt;/strong&gt; had agreed to bump
the minimum supported GCC version to 4.6. Coincidentally, as Steven now pointed out,
GCC version 4.6 was the first to support the &lt;code&gt;-mfentry&lt;/code&gt; argument. And, this was his
point—all supported versions of GCC now supported the better function tracing
option, and so there was no need for the kernel build system to cling to the
&lt;code&gt;mcount()&lt;/code&gt;
implementation at all.
&lt;/p&gt;

&lt;p&gt;
Steven posted a patch to rip it out by the roots.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Peter Zijlstra&lt;/strong&gt; gave his support for this plan, as did &lt;strong&gt;Jiri
Kosina&lt;/strong&gt;. And, Jiri in
particular spat upon the face of the &lt;code&gt;mcount()&lt;/code&gt; solution.
&lt;/p&gt;

&lt;p&gt;
Linus also liked Steven's patch, and he pointed out that with &lt;strong&gt;mcount()&lt;/strong&gt; out of the
picture, there were several more areas in the kernel that had existed simply to help
choose between &lt;code&gt;mcount()&lt;/code&gt; and &lt;code&gt;fentry()&lt;/code&gt;, and that those now also could be removed. But Steven
replied that, although yes this should be done, he still wanted to do split it up into
a separate patch, for cleanliness' sake.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/simplifying-function-tracing-modern-gcc" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Fri, 26 Jul 2019 11:30:00 +0000</pubDate>
    <dc:creator>Zack Brown</dc:creator>
    <guid isPermaLink="false">1340683 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Extending the Kernel with Built-in Kernel Headers</title>
  <link>https://www.linuxjournal.com/content/extending-kernel-built-kernel-headers</link>
  <description>  &lt;div data-history-node-id="1340763" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/joel-fernandes" lang="" about="https://www.linuxjournal.com/users/joel-fernandes" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Joel Fernandes&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;Note: this article is a followup to Zack Brown's &lt;a href="https://www.linuxjournal.com/content/android-low-memory-killer-or-out"&gt;"Android
Low Memory Killer—In or Out?"&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
Linux kernel headers are the unstable, constantly-changing, internal API of
the kernel. This includes internal kernel structures (for example,
&lt;code&gt;task_struct&lt;/code&gt;) as well as helper macros and functions. Unlike the UAPI headers
used to build userspace programs that are stable and backward-compatible,
the internal kernel headers can change at any time and any release. While
this allows the kernel unlimited flexibility to evolve and change, it
presents some difficulties for code that needs to be loaded into the kernel
at runtime and executed in kernel context.
&lt;/p&gt;

&lt;p&gt;
Kernel modules are a prime example of such code code. They execute in kernel
context and depend on this same unstable API that can change at any time. A
module has to be built for the kernel it is running on and may not load on
another because of an internal API change could break it. Another example is
eBPF tracing programs. These programs are dynamically compiled from C to
eBPF, loaded into the kernel and execute in kernel space in an in-kernel BPF
virtual machine. Since these programs trace the kernel, they need to use the
in kernel API at times, and they have the same challenges as kernel modules as
far as internal API changes go. They may need to understand what data
structures in the kernel look like or call kernel helper functions.
&lt;/p&gt;

&lt;p&gt;
Kernel headers are usually unavailable on the target where these BPF tracing
programs need to be dynamically compiled and run. That is certainly the case
with Android, which runs on billions of devices. It is not practical to ship
custom kernel headers for every device. My solution to the problem is to embed the
kernel headers within the kernel image itself and make it available through
the sysfs virtual filesystem (usually mounted at /sys) as a compressed
archive file (/sys/kernel/kheaders.tar.xz). This archive can be uncompressed
as needed to a temporary directory. This simple change guarantees that the
headers are always shipped with the running kernel.
&lt;/p&gt;

&lt;p&gt;
Several kernel developers disagreed with the solution; however, kernel
maintainer Greg Kroah-Hartman was supportive of the solution as were many
others. Greg argued that the solution is simple and just works as did other
kernel developers. Linus pulled the patches in v5.2 of the kernel release.
&lt;/p&gt;

&lt;p&gt;
To enable the embedded kernel headers, build your kernel with
&lt;code&gt;CONFIG_KHEADERS=y&lt;/code&gt; kernel option, or &lt;code&gt;=m&lt;/code&gt; if you want to save some memory.
&lt;/p&gt;

&lt;p&gt;
The
rest of this article looks at challenges with kernel headers, solutions
and the limitations.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Challenges with Kernel Headers&lt;/span&gt;

&lt;p&gt;
&lt;em&gt;Filesystem or Archive?&lt;/em&gt;
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/extending-kernel-built-kernel-headers" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 24 Jul 2019 11:30:00 +0000</pubDate>
    <dc:creator>Joel Fernandes</dc:creator>
    <guid isPermaLink="false">1340763 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>What Does It Take to Make a Kernel?</title>
  <link>https://www.linuxjournal.com/content/what-does-it-take-make-kernel-0</link>
  <description>  &lt;div data-history-node-id="1340576" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/petros-koutoupis" lang="" about="https://www.linuxjournal.com/users/petros-koutoupis" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Petros Koutoupis&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;The kernel &lt;em&gt;this&lt;/em&gt;. The kernel &lt;em&gt;that&lt;/em&gt;. People
often refer to one operating system's kernel or another without
truly knowing what it does or how it works or what it takes to make
one. What does it take to write a custom (and non-Linux) kernel?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
So, what am I going to do here? In June 2018, I wrote a &lt;a href="https://www.linuxjournal.com/content/diy-build-custom-minimal-linux-distribution-source"&gt;guide
to build a complete Linux distribution from source packages&lt;/a&gt;, and in
January 2019, I &lt;a href="https://www.linuxjournal.com/content/build-custom-minimal-linux-distribution-source-part-ii"&gt;expanded
on that guide&lt;/a&gt; by adding more packages to
the original guide. Now it's time to dive deeper into the custom
operating system topic. This article describes how to write your very own kernel from scratch
and then boot up into it. Sounds pretty straightforward, right? Now,
don't get &lt;em&gt;too&lt;/em&gt; excited here. This kernel won't do much of anything.
It'll
print a few messages onto the screen and then halt the CPU. Sure,
you can build on top of it and create something more, but that is not
the purpose of this article. My main goal is to provide you, the reader,
with a deep understanding of how a kernel is written.
&lt;/p&gt;

&lt;p&gt;
Once upon a time, in an era long ago, embedded Linux was not really a
&lt;em&gt;thing&lt;/em&gt;. I know that sounds a bit crazy, but it's true! If you worked with
a microcontroller, you were given (from the vendor) a specification, a
design sheet, a manual of all its registers and nothing more. Translation:
&lt;em&gt;you had to write your own operating system (kernel included)
from scratch.&lt;/em&gt; Although this guide assumes the standard generic
32-bit x86 architecture, a lot of it reflects what had to be done
back in the day.
&lt;/p&gt;

&lt;p&gt;
The exercises below require that you install a few packages in
your preferred Linux distribution. For instance, on an Ubuntu machine,
you will need the following:
&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;binutils&lt;/li&gt;

&lt;li&gt;
gcc&lt;/li&gt;

&lt;li&gt;
grub-common&lt;/li&gt;

&lt;li&gt;
make&lt;/li&gt;

&lt;li&gt;
nasm&lt;/li&gt;

&lt;li&gt;
xorriso&lt;/li&gt;
&lt;/ul&gt;&lt;span class="h3-replacement"&gt;
An Extreme Crash Course into the Assembly Language&lt;/span&gt;

&lt;p&gt;
&lt;em&gt;Note: I'm going to simplify things by pretending to work with
a not-so-complex 8-bit microprocessor. This doesn't
reflect the modern (and possibly past) designs of any commercial
processor.&lt;/em&gt;
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/what-does-it-take-make-kernel-0" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 23 Jul 2019 12:00:00 +0000</pubDate>
    <dc:creator>Petros Koutoupis</dc:creator>
    <guid isPermaLink="false">1340576 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Shrinking Linux Attack Surfaces</title>
  <link>https://www.linuxjournal.com/content/shrinking-linux-attack-surfaces</link>
  <description>  &lt;div data-history-node-id="1340684" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/zack-brown" lang="" about="https://www.linuxjournal.com/users/zack-brown" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Zack Brown&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
Often, a kernel developer will try to reduce the size of an attack surface against
Linux, even if it can't be closed entirely. It's generally a toss-up whether such a
patch makes it into the kernel. &lt;strong&gt;Linus Torvalds&lt;/strong&gt; always prefers security patches that
really close a hole, rather than just give attackers a slightly harder time of it.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Matthew Garrett&lt;/strong&gt; recognized that userspace applications might have secret data that
might be sitting in RAM at any given time, and that those applications might want to
wipe that data clean so no one could look at it.
&lt;/p&gt;

&lt;p&gt;
There were various ways to do this already in the kernel, as Matthew pointed out. An
application could use &lt;code&gt;mlock()&lt;/code&gt; to prevent its memory contents from being pushed into
swap, where it might be read more easily by attackers. An application also could use
&lt;code&gt;atexit()&lt;/code&gt; to cause its memory to be thoroughly overwritten when the application exited,
thus leaving no secret data in the general pool of available RAM.
&lt;/p&gt;

&lt;p&gt;
The problem, Matthew pointed out, came if an attacker was able to reboot the system at
a critical moment—say, before the user's data could be safely overwritten. If
attackers then booted into a different OS, they might be able to examine the data still
stored in RAM, left over from the previously running Linux system.
&lt;/p&gt;

&lt;p&gt;
As Matthew also noted, the existing way to prevent even that was to tell the
&lt;strong&gt;UEFI&lt;/strong&gt; firmware to wipe system memory before booting to another OS, but this would
dramatically increase the amount of time it took to reboot. And if the good guys had
won out over the attackers, forcing them to wait a long time for a reboot could be
considered a denial of service attack—or at least downright annoying.
&lt;/p&gt;

&lt;p&gt;
Ideally, Matthew said, if the attackers were only able to induce a clean
shutdown—not
simply a cold boot—then there needed to be a way to tell Linux to scrub all data out
of RAM, so there would be no further need for UEFI to handle it, and thus no need for a
very long delay during reboot.
&lt;/p&gt;

&lt;p&gt;
Matthew explained the reasoning behind his patch. He said:
&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;
Unfortunately, if an
application exits uncleanly, its secrets may still be present in RAM. This can't be
easily fixed in userland (eg, if the OOM killer decides to kill a process holding
secrets, we're not going to be able to avoid that), so this patch adds a new flag to
madvise() to allow userland to request that the kernel clear the covered pages whenever
the page reference count hits zero. Since vm_flags is already full on 32-bit, it will
only work on 64-bit systems.
&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;
&lt;strong&gt;Matthew Wilcox&lt;/strong&gt; liked this plan and offered some technical suggestions for Matthew G's
patch, and Matthew G posted an updated version in response.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/shrinking-linux-attack-surfaces" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Thu, 18 Jul 2019 11:00:00 +0000</pubDate>
    <dc:creator>Zack Brown</dc:creator>
    <guid isPermaLink="false">1340684 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Address Space Isolation and the Linux Kernel</title>
  <link>https://www.linuxjournal.com/content/address-space-isolation-and-linux-kernel</link>
  <description>  &lt;div data-history-node-id="1340685" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/zack-brown" lang="" about="https://www.linuxjournal.com/users/zack-brown" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Zack Brown&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
&lt;strong&gt;Mike Rapoport&lt;/strong&gt; from &lt;strong&gt;IBM&lt;/strong&gt; launched a bid to implement address space isolation in the Linux
kernel. Address space isolation emanates from the idea of virtual memory—where the
system maps all its hardware devices' memory addresses into a clean virtual space so
that they all appear to be one smooth range of available RAM. A system that implements
virtual memory also can create isolated address spaces that are available only to part
of the system or to certain processes.
&lt;/p&gt;

&lt;p&gt;
The idea, as Mike expressed it, is that if hostile users find themselves in an
isolated address space, even if they find bugs in the kernel that might be exploited to
gain control of the system, the system they would gain control over would be just that
tiny area of RAM to which they had access. So they might be able to mess up their own local
user, but not any other users on the system, nor would they be able to gain access to root level
infrastructure.
&lt;/p&gt;

&lt;p&gt;
In fact, Mike posted patches to implement an element of this idea, called &lt;strong&gt;System Call
Isolation&lt;/strong&gt; (SCI). This would cause system calls to each run in their own isolated
address space. So if, somehow, an attacker were able to modify the return values stored
in the stack, there would be no useful location to which to return.
&lt;/p&gt;

&lt;p&gt;
His approach was relatively straightforward. The kernel already maintains a "symbol
table" with the addresses of all its functions. Mike's patches would make sure that any
return addresses that popped off the stack corresponded to entries in the symbol table. And
since "attacks are all about jumping to gadget code which is effectively in the middle
of real functions, the jumps they induce are to code that doesn't have an external
symbol, so it should mostly detect when they happen."
&lt;/p&gt;

&lt;p&gt;
The problem, he acknowledged, was that implementing this would have a speed hit. He saw
no way to perform and enforce these checks without slowing down the kernel. For that
reason, Mike said, "it should only be activated for processes or containers we know
should be untrusted."
&lt;/p&gt;

&lt;p&gt;
There was not much enthusiasm for this patch. As &lt;strong&gt;Jiri Kosina&lt;/strong&gt; pointed out, Mike's code
was incompatible with other security projects like retpolines, which tries to prevent
certain types of data leaks falling into an attacker's hands.
&lt;/p&gt;

&lt;p&gt;
There was no real discussion and no interest was expressed in the patch. The
combination of the speed hit, the conflict with existing security projects, and the
fact that it tried to secure against only hypothetical security holes and not actual
flaws in the system, probably combined to make this patch set less interesting to
kernel developers.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/address-space-isolation-and-linux-kernel" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 10 Jul 2019 11:30:00 +0000</pubDate>
    <dc:creator>Zack Brown</dc:creator>
    <guid isPermaLink="false">1340685 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Deprecating a.out Binaries</title>
  <link>https://www.linuxjournal.com/content/deprecating-aout-binaries</link>
  <description>  &lt;div data-history-node-id="1340618" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/zack-brown" lang="" about="https://www.linuxjournal.com/users/zack-brown" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Zack Brown&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
Remember &lt;strong&gt;a.out binaries&lt;/strong&gt;? They were the file format of the Linux kernel till
around 1995 when &lt;strong&gt;ELF&lt;/strong&gt; took over. ELF is better. It allows you to load shared
libraries anywhere in memory, while a.out binaries need you to register
shared library locations. That's fine at small scales, but it gets to be
more and more of a headache as you have more and more shared libraries to
deal with. But a.out is still supported in the Linux source tree, 25 years
after ELF became the standard default format.
&lt;/p&gt;

&lt;p&gt;
Recently, &lt;strong&gt;Borislav Petkov&lt;/strong&gt; recommended deprecating it in the source tree,
with the idea of removing it if it turned out there were no remaining
users. He posted a patch to implement the deprecation. &lt;strong&gt;Alan
Cox&lt;/strong&gt; also
remarked that "in the unlikely event that someone actually has an a.out
binary they can't live with, they can also just write an a.out loader as an
ELF program entirely in userspace."
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Richard Weinberger&lt;/strong&gt; had no problem deprecating a.out and gave his official
approval of Borislav's patch.
&lt;/p&gt;

&lt;p&gt;
In fact, there's a reason the issue happens to be coming up now, 25 years
after the fact. &lt;strong&gt;Linus Torvalds&lt;/strong&gt; pointed out:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;
I'd prefer to try to deprecate a.out core dumping first....That's the part
that is actually broken, no?
&lt;/p&gt;

&lt;p&gt;
In fact, I'd be happy to deprecate a.out entirely, but if somebody _does_
complain, I'd like to be able to bring it back without the core dumping.
&lt;/p&gt;

&lt;p&gt;
Because I think the likelihood that anybody cares about a.out core dumps is
basically zero. While the likelihood that we have some odd old binary that
is still a.out is slightly above zero.
&lt;/p&gt;

&lt;p&gt;
So I'd be much happier with this if it was a two-stage thing where we just
delete a.out core dumping entirely first, and then deprecate even running
a.out binaries separately.
&lt;/p&gt;

&lt;p&gt;
Because I think all the known *bugs* we had were with the core dumping
code, weren't they?
&lt;/p&gt;

&lt;p&gt;
Removing it looks trivial. Untested patch attached.
&lt;/p&gt;

&lt;p&gt;
Then I'd be much happier with your "let's deprecate a.out entirely" as a
second patch, because I think it's an unrelated issue and much more likely
to have somebody pipe up and say "hey, I have this sequence that generates
executables dynamically, and I use a.out because it's much simpler than
ELF, and now it's broken". Or something.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
&lt;strong&gt;Jann Horn&lt;/strong&gt; looked over Linus' patch and suggested additional elements of
a.out that would no longer be used by anything, if core dumping was coming
out. He suggested those things also could be removed with the same git
commit, without risking anyone complaining.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/deprecating-aout-binaries" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Tue, 25 Jun 2019 12:00:00 +0000</pubDate>
    <dc:creator>Zack Brown</dc:creator>
    <guid isPermaLink="false">1340618 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
