Giter Club home page Giter Club logo

linux-netns-sysctl-verify's Introduction

linux-netns-sysctl-verify

Linux network namespace sysctl safety verifier.

Ensure that net sysctls are network-namespace-safe.

Usage

usage: verify.py [-h] [-v]

optional arguments:
  -h, --help     show this help message and exit
  -v, --verbose  Verbose output

Currently, this must be run as root, in order to use CLONE_NEWNET.

$ sudo ./verify.py -v

Theory of Operation

The premise behind this tool is simple:

  • Take a snapshot of all values in /proc/sys/net.
  • Create a child process with a new netns (using CLONE_NEWNET).
  • In the child netns, modify every writable value in /proc/sys/net.
  • Exit the child netns.
  • Take a second snapshot of /proc/sys/net.
  • Compare the snapshots and report any differences.

Anything in the parent which changed as a result of manipulations in the child is considered a "leak".

Background

The Linux kernel provides runtime-configurable kernel parameters known as "sysctls", which are accessed via /proc/sys/.

Linux also supports supports network namespaces (netns) which enable isolated virtual network stacks and are used heavily by containerization platforms like LXC or Docker. See network_namespaces(7).

It's generally understood that the "net" sysctls (under /proc/sys/net) are supposed to be "netns safe", meaning that manipulating sysctls from one network namespace cannot affect any other network namespace. This isn't exactly guaranteed, though.

It may be desirable to allow a container to write to net sysctls, specifically parameters of devices which exist only within the container's netns. However, the latest version of Docker (20.10.6 as of this writing) mounts all of /proc/sys read-only, to prevent changes made in a container from "leaking" out of the container. This protection mechanism makes it more difficult (and less secure) to run a libvirt QEMU VM inside of a Docker container.

This tool was inspired by conversation on this runc issue.

Results

Use of this tool helped to uncover several bugs in the Linux kernel's implementation of several sysctls, which have been subsequently fixed by this tool's author:

Bug 1: Several nf_conntrack sysctls are global and writable by any netns

  • Affected sysctls:
    • net.nf_conntrack_max
    • net.netfilter.nf_conntrack_max
    • net.netfilter.nf_conntrack_expect_max
  • First broken: (long ago; since introduction of net namespaces)
  • Fix: netfilter: conntrack: Make global sysctls readonly in non-init netns
  • Fixed in Kernels:

Bug 2: tcp_allowed_congestion_control is global and writable by any netns

  • Affected sysctls:
    • net.ipv4.tcp_allowed_congestion_control
  • First broken: v5.7
  • Fix: net: Make tcp_allowed_congestion_control readonly in non-init netns
  • Fixed in Kernels:

Bug 3: Setting tcp_congestion_control can globally affect tcp_allowed_congestion_control

  • Related sysctls:
    • net.ipv4.tcp_congestion_control (affects)
    • net.ipv4.tcp_allowed_congestion_control (affected)
  • First broken: v4.15
  • Fix: net: Only allow init netns to set default tcp cong to a restricted algo
  • Fixed in Kernels:

Additionally, a safety check was added to the kernel to prevent certain classes of bugs from going unnoticed:

  • 31c4d2f160eb: net: Ensure net namespace isolation of sysctls

linux-netns-sysctl-verify's People

Contributors

jonathonreinhart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

linux-netns-sysctl-verify's Issues

Invalid argument: ipfrag_high_thresh

Kernel: Linux ubuntu 4.15.0-143-generic #147-Ubuntu SMP

Frob errors:

Error writing '262145' > /proc/sys/net/ipv4/ipfrag_high_thresh: [Errno 22] Invalid argument
Error writing '262145' > /proc/sys/net/ipv6/ip6frag_high_thresh: [Errno 22] Invalid argument

Default values:

root@ubuntu:~# cat /proc/sys/net/ipv4/ipfrag_high_thresh
262144
root@ubuntu:~# cat /proc/sys/net/ipv6/ip6frag_high_thresh
262144

Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/0: [Errno 2] No such file or directory

Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/0: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/1: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/10: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/11: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/12: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/2: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/3: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/4: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/5: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/6: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/7: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/8: [Errno 2] No such file or directory
Error writing 'nfnetlink_log' > /proc/sys/net/netfilter/nf_log/9: [Errno 2] No such file or directory```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.