Network, userspace, and kernel boundaries

This page looks at the two upper (see Layered defense-in-depth architecture) boundaries in more detail: where network input enters userspace, and where userspace processes request services from the kernel. It shows how Ubuntu validates untrusted input and mediates privilege transitions at each boundary, in three steps: from the network to a service, from an unprivileged user to privileged actions, and from a process to the kernel.

The diagrams on this page follow the diagram conventions. To go to the explanation of a box, select the box in the diagram.

Network to userspace

Three main mechanisms - packet filtering, encrypted and authenticated access and service sandboxing - protect the path from the network to a service.

        ---
config:
  theme: base
  fontFamily: Ubuntu variable, Ubuntu, sans-serif
  themeCSS: 'svg, svg * { font-family: Ubuntu variable, Ubuntu, sans-serif !important; } .flowchart-link { stroke-width: 3px !important; } .edge-pattern-dotted { stroke-dasharray: 8 5 !important; }'
  flowchart:
    curve: linear
  themeVariables:
    fontFamily: Ubuntu variable, Ubuntu, sans-serif
    lineColor: "#E95420"
    primaryColor: "#F3F3F3"
    primaryBorderColor: "#000000"
    primaryTextColor: "#000000"
    clusterBkg: "#FFFFFF"
    clusterBorder: "#000000"
    edgeLabelBackground: "#FFFFFF"
---
flowchart TB
    subgraph MAIN[" "]
        direction LR
        subgraph NETZ["Outside — untrusted"]
            pkt["Remote clients and<br>untrusted peers"]
        end
        subgraph KZ["Linux kernel"]
            nf["Netfilter hooks,<br>TCP SYN cookies"]
        end
        subgraph US["Userspace"]
            rules["nftables or ufw rules<br>(opt-in)"]
            subgraph SANDBOX["systemd service sandbox"]
                svc["Network-facing service<br>(OpenSSH, TLS server, ...)"]
            end
        end
        pkt -.->|"Untrusted packets"| nf
        rules -.->|"Loaded rules"| nf
        nf -->|"Accepted connections"| svc
        pkt <-->|"Encrypted, authenticated<br>session"| svc
        style NETZ fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style KZ fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style US fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style SANDBOX fill:#FFFFFF,stroke:#000000,stroke-width:1px
    end

    subgraph LEG["Legend"]
        direction LR
        leg0["Trust zone"]
        leg1["Untrusted"]
        leg2["Component"]
        leg3["Opt-in"]
        leg4s[" "] --> leg4["Data flow"]
        leg5s[" "] -.-> leg5["Untrusted or<br>optional flow"]
        leg0 ~~~ leg1
        leg1 ~~~ leg2
        leg3 ~~~ leg4s
        leg4 ~~~ leg5s
    end
    MAIN ~~~ LEG

    classDef component fill:#F3F3F3,stroke:#000000,stroke-width:1px,color:#000000
    classDef hidden fill:none,stroke:none,color:#FFFFFF
    classDef note fill:#FFFFFF,stroke:none,color:#000000
    classDef optin fill:#F3F3F3,stroke:#000000,stroke-width:1px,stroke-dasharray:4 4,color:#000000
    classDef untrusted fill:#FFFFFF,stroke:#000000,stroke-width:1px,stroke-dasharray:4 4,color:#000000
    classDef zone fill:#FFFFFF,stroke:#000000,stroke-width:2px,color:#000000
    class pkt untrusted
    class nf,svc component
    class rules optin
    class leg0 zone
    class leg1 untrusted
    class leg2 component
    class leg3 optin
    class leg4 note
    class leg4s hidden
    class leg5 note
    class leg5s hidden
    click nf href "#security-architecture-packet-filtering"
    click rules href "#security-architecture-packet-filtering"
    click svc href "#security-architecture-encrypted-access"
    style LEG fill:#FFFFFF,stroke:#666666,stroke-width:1px
    style MAIN fill:none,stroke:none
    

From the network to a service

Other pages describe further elements of this diagram. See Untrusted network peers.

Packet filtering

Netfilter processes every packet in the kernel before a service receives it. Rules defined with nft(8) or ufw can drop or limit traffic. TCP SYN cookies keep services reachable during SYN flood attacks. See SYN cookies.

Encrypted and authenticated access

OpenSSH and Transport Layer Security (TLS) libraries protect remote sessions and service traffic. Ubuntu configures these libraries to reject legacy protocol versions and weak algorithms. See Cryptography.

Service sandboxing

Network-facing services usually run as systemd units. The unit file can declare the dropping privileges and thereby have systemd restrict the service, for example with a dedicated user, NoNewPrivileges=, ProtectSystem=, and system call filters. See systemd.exec(5).

Privilege elevation and authentication

Three components mediate the transition from an unprivileged user or service to privileged actions.

        ---
config:
  theme: base
  fontFamily: Ubuntu variable, Ubuntu, sans-serif
  themeCSS: 'svg, svg * { font-family: Ubuntu variable, Ubuntu, sans-serif !important; } .flowchart-link { stroke-width: 3px !important; } .edge-pattern-dotted { stroke-dasharray: 8 5 !important; }'
  flowchart:
    curve: linear
  themeVariables:
    fontFamily: Ubuntu variable, Ubuntu, sans-serif
    lineColor: "#E95420"
    primaryColor: "#F3F3F3"
    primaryBorderColor: "#000000"
    primaryTextColor: "#000000"
    clusterBkg: "#FFFFFF"
    clusterBorder: "#000000"
    edgeLabelBackground: "#FFFFFF"
---
flowchart TB
    subgraph MAIN[" "]
        direction TB
        subgraph OUT["Outside — untrusted"]
            users["Remote and local users"]
        end
        subgraph UNPRIV["Unprivileged"]
            user["User session or application<br>(started by login services)"]
        end
        subgraph PRIV["Privileged (root)"]
            login["Login services<br>(console, SSH, display manager)"]
            sudo["sudo-rs"]
            daemon["Privileged daemon"]
            polkit["polkit"]
            pam["PAM"]
            mfa["Multi-factor, smart card,<br>network identity (opt-in)"]
        end
        users -->|"Credentials"| login
        login -->|"Authentication"| pam
        user -->|"Elevation request"| sudo
        sudo -->|"Authentication"| pam
        user -->|"D-Bus call"| daemon
        daemon -->|"Authorization check"| polkit
        pam -.->|"Additional factors"| mfa
        style OUT fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style UNPRIV fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style PRIV fill:#FFFFFF,stroke:#000000,stroke-width:2px
    end

    subgraph LEG["Legend"]
        direction LR
        leg0["Trust zone"]
        leg1["Untrusted"]
        leg2["Component"]
        leg4["Opt-in"]
        leg5s[" "] --> leg5["Data flow"]
        leg6s[" "] -.-> leg6["Untrusted or<br>optional flow"]
        leg0 ~~~ leg1
        leg1 ~~~ leg2
        leg2 ~~~ leg4
        leg4 ~~~ leg5s
        leg5 ~~~ leg6s
    end
    MAIN ~~~ LEG

    classDef component fill:#F3F3F3,stroke:#000000,stroke-width:1px,color:#000000
    classDef hidden fill:none,stroke:none,color:#FFFFFF
    classDef note fill:#FFFFFF,stroke:none,color:#000000
    classDef optin fill:#F3F3F3,stroke:#000000,stroke-width:1px,stroke-dasharray:4 4,color:#000000
    classDef untrusted fill:#FFFFFF,stroke:#000000,stroke-width:1px,stroke-dasharray:4 4,color:#000000
    classDef zone fill:#FFFFFF,stroke:#000000,stroke-width:2px,color:#000000
    class users untrusted
    class user,login,daemon,polkit,pam,sudo component
    class mfa optin
    class leg0 zone
    class leg1 untrusted
    class leg2 component
    class leg4 optin
    class leg5 note
    class leg5s hidden
    class leg6 note
    class leg6s hidden
    click login href "#security-architecture-pam"
    click user href "#security-architecture-privilege-boundary"
    click sudo href "#security-architecture-sudo-rs"
    click daemon href "#security-architecture-polkit"
    click polkit href "#security-architecture-polkit"
    click pam href "#security-architecture-pam"
    click mfa href "#security-architecture-pam"
    style LEG fill:#FFFFFF,stroke:#666666,stroke-width:1px
    style MAIN fill:none,stroke:none
    

From an unprivileged user to privileged actions

Other pages describe further elements of this diagram. See Users and administrators.

PAM

Login services, such as the console login, SSH, and the display manager, use pam(7) to authenticate users, check account restrictions, and set up sessions. PAM modules add multi-factor authentication, smart cards, or network identity providers if you configure them. See Two factor authentication with TOTP/HOTP, Smart card authentication, and the authd documentation.

sudo-rs

sudo-rs lets authorized users run commands as root with their own credentials. The root account has no usable password by default. See User management and sudo-rs.

Note

Ubuntu 24.04 LTS uses sudo instead of sudo-rs by default.

polkit

polkit lets privileged daemons decide whether an unprivileged caller may perform an action, such as mounting a disk or changing network settings. See polkit(8).

Userspace to kernel

Every request from a userspace process to the kernel passes through the system call interface. The kernel validates the arguments of each system call, and copies data from and to process memory only through dedicated functions, such as copy_from_user(), which check that the memory belongs to the calling process. The kernel then applies the following checks.

        ---
config:
  theme: base
  fontFamily: Ubuntu variable, Ubuntu, sans-serif
  themeCSS: 'svg, svg * { font-family: Ubuntu variable, Ubuntu, sans-serif !important; } .flowchart-link { stroke-width: 3px !important; } .edge-pattern-dotted { stroke-dasharray: 8 5 !important; }'
  flowchart:
    curve: linear
  themeVariables:
    fontFamily: Ubuntu variable, Ubuntu, sans-serif
    lineColor: "#E95420"
    primaryColor: "#F3F3F3"
    primaryBorderColor: "#000000"
    primaryTextColor: "#000000"
    clusterBkg: "#FFFFFF"
    clusterBorder: "#000000"
    edgeLabelBackground: "#FFFFFF"
---
flowchart TB
    subgraph MAIN[" "]
        direction TB
        subgraph KZ["Linux kernel"]
            sys["System call entry<br>(argument and user<br>memory checks)"]
            seccomp["seccomp-bpf filter"]
            dac["DAC (UID, GID, POSIX ACLs)<br>and capabilities"]
            subgraph LSM["LSM hooks"]
                aa["AppArmor MAC<br>(files, sockets,<br>capabilities)"]
                yama["Yama ptrace scope"]
            end
            nscg["Namespaces and cgroups"]
            obj["Kernel objects<br>(files, sockets,<br>processes, devices)"]
        end
        subgraph US["Userspace"]
            proc["Userspace process"]
            policy["Security policy<br>(AppArmor profiles,<br>seccomp filters)"]
        end
        sys --> seccomp
        seccomp -->|"Allowed calls"| dac
        dac -->|"Permitted access"| LSM
        LSM -->|"Mediated access"| obj
        nscg -->|"Scope and limit"| obj
        proc <-->|"System call<br>and result"| sys
        policy -->|"Define filters"| seccomp
        policy -->|"Control hooks"| LSM
        policy -->|"Control"| nscg
        style US fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style KZ fill:#FFFFFF,stroke:#000000,stroke-width:2px
        style LSM fill:#FFFFFF,stroke:#000000,stroke-width:1px
    end

    subgraph LEG["Legend"]
        direction LR
        leg0["Trust zone"]
        leg1["Component"]
        leg2["Ubuntu default"]
        leg3s[" "] --> leg3["Data flow"]
        leg0 ~~~ leg1
        leg1 ~~~ leg2
        leg2 ~~~ leg3s
    end
    MAIN ~~~ LEG

    classDef component fill:#F3F3F3,stroke:#000000,stroke-width:1px,color:#000000
    classDef hidden fill:none,stroke:none,color:#FFFFFF
    classDef note fill:#FFFFFF,stroke:none,color:#000000
    classDef ubuntu fill:#737373,stroke:#000000,stroke-width:1px,color:#FFFFFF
    classDef zone fill:#FFFFFF,stroke:#000000,stroke-width:2px,color:#000000
    class proc,policy,sys,seccomp,dac,nscg,obj component
    class aa,yama ubuntu
    class leg0 zone
    class leg1 component
    class leg2 ubuntu
    class leg3 note
    class leg3s hidden
    click policy href "#security-architecture-policy"
    click sys href "#security-architecture-syscall-boundary"
    click seccomp href "#security-architecture-seccomp"
    click dac href "#security-architecture-dac"
    click aa href "#security-architecture-apparmor"
    click yama href "#security-architecture-yama"
    click nscg href "#security-architecture-namespaces"
    style LEG fill:#FFFFFF,stroke:#666666,stroke-width:1px
    style MAIN fill:none,stroke:none
    

From a process to the kernel

Other pages describe further elements of this diagram. See Userspace.

seccomp-bpf

seccomp-bpf rejects system calls that the process’s filter does not allow. snapd, systemd, and many applications install filters. See seccomp filtering and seccomp(2).

Discretionary access control and capabilities

The kernel checks the process’s user and group IDs against file permissions and acl(5) entries, and checks capabilities(7) for privileged operations.

AppArmor

AppArmor restricts each confined program to the files, network access, and capabilities listed in its profile, even if the program runs as root. AppArmor also restricts the use of unprivileged user namespaces. See AppArmor and AppArmor.

Yama

Yama allows a process to attach to another process with ptrace only if it is an ancestor of that process, or has the required capability. See ptrace scope.

Namespaces and cgroups

Namespaces and cgroups limit which resources a process can see, and how much of them it can use. Containers and snaps build on them. See namespaces(7) and cgroups.

Security policy

Policies for these mechanisms, such as AppArmor profiles, seccomp filters, and nftables rules, are written and managed in userspace. Once loaded, the kernel enforces them, and a process cannot bypass them without the privileges to replace the policy.