
<rss version="2.0" 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" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title><![CDATA[ The Cloudflare Blog ]]></title>
        <description><![CDATA[ Get the latest news on how products at Cloudflare are built, technologies used, and join the teams helping to build a better Internet. ]]></description>
        <link>https://blog.cloudflare.com</link>
        <atom:link href="https://blog.cloudflare.com/" rel="self" type="application/rss+xml"/>
        <language>en-us</language>
        <image>
            <url>https://blog.cloudflare.com/favicon.png</url>
            <title>The Cloudflare Blog</title>
            <link>https://blog.cloudflare.com</link>
        </image>
        <lastBuildDate>Sun, 10 May 2026 19:12:40 GMT</lastBuildDate>
        <item>
            <title><![CDATA[How Cloudflare responded to the “Copy Fail” Linux vulnerability]]></title>
            <link>https://blog.cloudflare.com/copy-fail-linux-vulnerability-mitigation/</link>
            <pubDate>Thu, 07 May 2026 13:00:00 GMT</pubDate>
            <description><![CDATA[ When a critical Linux kernel privilege escalation was publicly disclosed, Cloudflare's security and engineering teams detected, investigated, and mitigated the threat across our global fleet, confirming zero customer impact and no malicious exploitation. ]]></description>
            <content:encoded><![CDATA[ <p>On April 29, 2026, a Linux kernel local privilege escalation vulnerability was publicly disclosed under the name "Copy Fail" (<a href="https://security-tracker.debian.org/tracker/CVE-2026-31431"><u>CVE-2026-31431</u></a>). Cloudflare’s Security and Engineering teams began assessing the vulnerability as soon as it was disclosed. We reviewed the exploit technique, evaluated exposure across our infrastructure, and validated that our existing behavioral detections could identify the exploit pattern within minutes. </p><p><b>There was no impact to the Cloudflare environment, no customer data was at risk, and no services were disrupted at any point.</b> Read on to learn how our preparedness paid off. </p>
    <div>
      <h2>Background</h2>
      <a href="#background">
        
      </a>
    </div>
    
    <div>
      <h4>Our Linux kernel release process</h4>
      <a href="#our-linux-kernel-release-process">
        
      </a>
    </div>
    <p>Cloudflare operates a global Linux server infrastructure at an immense scale, with datacenters located <a href="https://www.cloudflare.com/network/"><u>across 330 cities</u></a>. We maintain a custom Linux kernel build based on the community's Long-Term Support (LTS) versions to manage updates effectively at this volume. At any given time, we may utilize multiple LTS versions from various series, such as 6.12 or 6.18, which benefit from extended update periods.</p><p>The community regularly merges and releases security and stability updates which trigger an automated job to generate a new internal kernel build approximately every week. These builds undergo testing in our staging data centers to ensure stability before a global rollout. Following a successful release, the Edge Reboot Release (ERR) pipeline manages a systematic update and reboot of the edge infrastructure on a four-week cycle. Our control plane infrastructure typically adopts the most recent kernel, with reboots scheduled according to specific workload requirements.</p><p>By the time a CVE becomes public knowledge, the necessary fix has typically been integrated into stable Linux LTS releases for several weeks. Our established procedures ensure that we have already deployed these patches.</p><p>At the time of the "Copy Fail" disclosure, the majority of our infrastructure was running the 6.12 LTS version, while a subset of machines had begun transitioning to the newer 6.18 LTS release.</p>
    <div>
      <h3>About the Copy Fail vulnerability</h3>
      <a href="#about-the-copy-fail-vulnerability">
        
      </a>
    </div>
    <p>It helps to understand the vulnerability before getting to the response story. A comprehensive write-up can be found in the original <a href="https://xint.io/blog/copy-fail-linux-distributions"><u>Xint Code disclosure</u></a> post.</p>
    <div>
      <h4>AF_ALG and the kernel crypto API</h4>
      <a href="#af_alg-and-the-kernel-crypto-api">
        
      </a>
    </div>
    <p>The Linux kernel's internal crypto API manages functions like kTLS and IPsec. Userspace programs access this via the <code>AF_ALG</code> socket family, allowing unprivileged processes to request encryption or decryption. The <code>algif_aead</code> module facilitates this for Authenticated Encryption with Associated Data (AEAD) ciphers.</p><p>An unprivileged program follows these steps:</p><ol><li><p>Opens an <code>AF_ALG</code> socket and binds to an AEAD template.</p></li><li><p>Sets a key and accepts a request socket.</p></li><li><p>Submits input via <code>sendmsg()</code> or <code>splice()</code>.</p></li><li><p>Executes the operation using <code>recvmsg()</code>.</p></li></ol><p>The <code>splice()</code> system call is critical here, as it moves data by passing page cache references.</p>
    <div>
      <h4>Memory mechanics: page cache and in-place crypto</h4>
      <a href="#memory-mechanics-page-cache-and-in-place-crypto">
        
      </a>
    </div>
    <p>The <b>page cache</b> is a shared system cache for file contents. Modifying a page belonging to a setuid binary effectively edits that program for all users until the page is evicted.</p><p>The crypto API utilizes <b>scatterlists</b>, which are structures linking various memory pages. In 2017, <code>algif_aead</code> was optimized for <i>in-place</i> operations, chaining destination and reference pages together. This design lacked enforcement to prevent algorithms from writing past intended boundaries.</p>
    <div>
      <h4>The vulnerability: out-of-bounds write</h4>
      <a href="#the-vulnerability-out-of-bounds-write">
        
      </a>
    </div>
    <p>When the user executes <code>recvmsg()</code>, the <code>authencesn</code> wrapper in the kernel performs a 4-byte write past the legitimate output region:</p>
            <pre><code>scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1);
</code></pre>
            <p>By using <code>splice()</code>, an attacker can chain a target file's page cache pages to the scatterlist. The out-of-bounds write then taints the cached file, allowing an attacker to control which file is modified, the offset, and the specific 4 bytes written. This means the attacker can manipulate the following with this exploit:</p><ul><li><p>File: Any readable file.</p></li><li><p>Offset: Tunable via <code>assoclen</code> and splice parameters.</p></li><li><p>Value: Controlled via AAD bytes 4-7 in <code>sendmsg()</code></p></li></ul>
    <div>
      <h4>The exploit, step by step</h4>
      <a href="#the-exploit-step-by-step">
        
      </a>
    </div>
    
          <figure>
          <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5uqfOddH7biQaTjtgQOist/5c16c08bf3e5ce2f9030d6f98d2403cb/BLOG-3308_2.png" />
          </figure><p>The default exploit targets <code>/usr/bin/su</code>, a setuid-root binary present on essentially every distribution.</p><ol><li><p><b>Cache Reference:</b> Open <code>/usr/bin/su</code> as <code>O_RDONLY</code> and <code>read()</code> to populate the page cache. Use splice() on the file descriptor to pass these page cache references into the crypto scatterlist.</p></li><li><p><b>Setup:</b> Create an <code>AF_ALG</code> socket, <code>bind()</code> to <code>authencesn(hmac(sha256),cbc(aes))</code>, set a key, and accept a request socket without needing privileges.</p></li><li><p><b>Write Construction:</b> For each 4-byte shellcode chunk:</p><ul><li><p><code>sendmsg()</code> with AAD bytes 4–7 containing the shellcode.</p></li><li><p><code>splice()</code> the binary into a pipe then the <code>AF_ALG</code> socket so <code>assoclen + cryptlen</code> targets the desired <code>.text</code> offset.</p></li></ul></li><li><p><b>Trigger:</b> <code>recvmsg()</code> initiates decryption. <code>authencesn</code> writes its scratch data to the target offset of <code>/usr/bin/su</code> in the page cache. Although the function returns <code>-EBADMSG</code>, the 4-byte write is now in the global page cache.</p></li><li><p><b>Execution:</b> Running <code>execve("/usr/bin/su")</code> loads the tainted page cache. Since the binary is setuid-root, the injected shellcode executes with <b>root</b> privileges.</p></li></ol><p>The upstream fix (<a href="https://github.com/torvalds/linux/commit/a664bf3d603d"><u>commit a664bf3d603d</u></a>) reverts the 2017 in-place optimization, removing the exploit.</p>
    <div>
      <h3>How we responded </h3>
      <a href="#how-we-responded">
        
      </a>
    </div>
    <p>When the vulnerability was disclosed, many workstreams started in parallel:</p><ul><li><p><b>Mapping the blast radius:</b> Our security team worked with kernel engineers to determine which kernel versions were vulnerable and assess the potential exposure.</p></li><li><p><b>Validating coverage:</b> Security reviewed the exploit technique and confirmed that our existing behavioral detections could identify the exploit pattern during authorized internal validation.</p></li><li><p><b>Proactive threat hunting:</b> Security began searching for signs that the vulnerability had been exploited before it was publicly known, going back 48 hours in our fleet-wide logs.</p></li><li><p><b>Engineering a mitigation:</b> Kernel engineers began building a runtime mitigation that would protect the fleet without breaking production services.</p></li><li><p><b>Continuing software updates</b>: Our engineering teams worked on delivering an updated Linux kernel, which required carefully rebooting and rolling it out across our servers.</p></li></ul><p>There was no customer impact at any point during this response.</p>
    <div>
      <h4>Validating detection coverage</h4>
      <a href="#validating-detection-coverage">
        
      </a>
    </div>
    <p>One of the first things our security team did was confirm that our existing endpoint detection would catch this exploit. Our servers run behavioral detection that continuously monitors process execution patterns. It doesn't rely on knowing about specific vulnerabilities; it watches for anomalous behavior across the fleet.</p><p>When our engineers validated the vulnerability internally as part of the response, the detection platform flagged it within minutes. The system linked the entire execution chain—starting at the script interpreter, moving through the kernel’s cryptographic subsystem, and ending at the privilege escalation binary—flagging it as malicious based on fleet-wide behavioral patterns.</p><p>This happened without a signature update, without a rule change, and without human intervention. Our behavioral detection coverage existed before we wrote any custom logic for this particular Copy File exploit. </p><p>The confirmation was important because it meant we had coverage before writing a vulnerability-specific rule.</p>
    <div>
      <h4>Hunting for exploitation</h4>
      <a href="#hunting-for-exploitation">
        
      </a>
    </div>
    <p>While our engineering team moved to a more targeted mitigation, our security investigation had been running since disclosure. This is our standard procedure for any critical vulnerability.</p><p>Our security team operates on a simple principle for critical vulnerabilities: assume compromise until you can prove otherwise. The investigation started from the assumption that exploitation could have occurred before the vulnerability was public, and we worked systematically to either confirm or rule it out.</p><p>The exploit leaves a distinctive trace in kernel logs when it runs. We searched for that trace across our centralized logging infrastructure, covering 48 hours before the vulnerability was publicly disclosed. If someone had exploited this before the world knew about it, we would have seen it.</p><p>We pulled access logs for affected systems and reconstructed who connected, when, and what commands they ran. This gave us a complete forensic picture of interactive activity on potentially affected infrastructure.</p><p>We checked that system binaries had not been tampered with, validated cryptographic hashes against known-good package manifests, looked for persistence mechanisms, and audited network connections for anything unusual. Everything was clean. </p>
    <div>
      <h2>Incident timeline and impact</h2>
      <a href="#incident-timeline-and-impact">
        
      </a>
    </div>
    
<div><table><colgroup>
<col></col>
<col></col>
</colgroup>
<thead>
  <tr>
    <th><span>Time (UTC)</span></th>
    <th><span>Event</span></th>
  </tr></thead>
<tbody>
  <tr>
    <td><span>2026-04-29 16:00</span></td>
    <td><span>Copy Fail publicly disclosed.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-29 ~21:00</span></td>
    <td><span>Security and Engineering teams began assessing fleet exposure and mitigation options before full declaration of the Incident Response process</span></td>
  </tr>
  <tr>
    <td><span>2026-04-29 22:52</span></td>
    <td><span>Security confirmed existing behavioral detection covered the Copy Fail exploit pattern. During authorized internal validation, detection flagged the activity within minutes.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-29 23:01</span></td>
    <td><span>Existing behavioral detection generated a high-severity alert for exploit-like activity, confirming detection coverage for the technique.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-29 (evening)</span></td>
    <td><span>First mitigation attempt pushed to our staging datacenter. The deployment process surfaced a dependency conflict; the mitigation was rolled back. No production systems were affected.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-29 (overnight)</span></td>
    <td><span>Engineering drafted bpf-lsm mitigation program.</span></td>
  </tr>
  <tr>
    <td><span> 2026-04-30 03:14</span></td>
    <td><span>Security incident declared to drive cross-functional collaboration and urgency. Security performed fleetwide threat hunting of historical data to confirm that no malicious activity was present on Cloudflare systems.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-30 (morning)</span></td>
    <td><span>Engineering tested the bpf-lsm mitigation program and made it production-ready.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-30 14:25</span></td>
    <td><span>Engineering incident declared to coordinate mitigation program and Linux patch rollout. </span></td>
  </tr>
  <tr>
    <td><span>2026-04-30 ~17:00</span></td>
    <td><span>Decision made: ship a patched build of the previous LTS line through reboot automation; do not accelerate the new LTS; lean on bpf-lsm in the meantime.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-30 (afternoon)</span></td>
    <td><span>Visibility pipeline (eBPF tracing of AF_ALG socket usage) deployed fleet-wide. Gives a complete picture of all legitimate AF_ALG users.</span></td>
  </tr>
  <tr>
    <td><span>2026-04-30 (evening)</span></td>
    <td><span>bpf-lsm mitigation program rolled out behind a separate gate to fully mitigate the fleet. End-to-end verification on a previously-vulnerable test node confirms the exploit no longer works.</span></td>
  </tr>
  <tr>
    <td><span>2026-05-04 (morning)</span></td>
    <td><span>Reboot automation resumed at normal pace with the patched kernel.</span></td>
  </tr>
  <tr>
    <td><span>2026-05-04 onward</span></td>
    <td><span>Servers that had already passed through reboot automation earlier in the week manually rebooted to pick up the patched kernel. Unpatched servers update per our normal reboot automation.</span></td>
  </tr>
</tbody></table></div>
          <figure>
          <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/7LI0k0FJgbLKzOkSEtYPwW/997234a334b3694c63417fad5810b679/BLOG-3308_3.png" />
          </figure><p>This graph shows the progress of our mitigation program as it progressed through our infrastructure.</p>
    <div>
      <h3>How did we mitigate it?</h3>
      <a href="#how-did-we-mitigate-it">
        
      </a>
    </div>
    <p>Because of the long timeframe involved in deploying a patched Linux kernel, we also pursued mitigating this exploit without a reboot.</p>
    <div>
      <h4>Removing the module</h4>
      <a href="#removing-the-module">
        
      </a>
    </div>
    <p>The bug was in the <code>algif_aead</code> kernel module. Therefore, the simple fix was to just remove this module and disallow it from being reloaded.</p><p>This mitigation was therefore exactly what the <a href="https://copy.fail/"><u>Copy Fail</u></a> write-up from the security researchers who identified it recommends.</p>
            <pre><code>echo "install algif_aead /bin/false" &gt; /etc/modprobe.d/disable-algif.conf
rmmod algif_aead 2&gt;/dev/null || true</code></pre>
            <p>Unfortunately removing the module would have impacted software that leverages the kernel crypto API.  This meant that we had to figure out a more surgical mitigation.</p>
    <div>
      <h4>Bpf-lsm</h4>
      <a href="#bpf-lsm">
        
      </a>
    </div>
    
          <figure>
          <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2VYFKst8aUkkHCaEdb8yQ4/91ad9a855d6185bccd179fcf092ed636/BLOG-3308_4.png" />
          </figure><p>We’ve already developed and deployed such a tool for this exact scenario: <a href="https://blog.cloudflare.com/live-patch-security-vulnerabilities-with-ebpf-lsm/"><u>bpf-lsm</u></a>. Instead of removing the module, this tool leaves it loaded for legitimate users and uses a BPF Linux Security Module program to deny the <code>socket_bind</code> LSM hook for everyone else. This completely blocks the front door for any exploits.</p><p>A draft of the eBPF program was put together overnight. Team members picked it up the following morning, ran validations, and made it production-ready. The program is fairly straightforward. On every <code>socket_bind</code> call:</p><ol><li><p>If the socket family is not <code>AF_ALG</code>, allow the call through unchanged.</p></li><li><p>If the family is <code>AF_ALG</code>, check the calling binary's path against an allow-list of the binaries we know to be legitimate users.</p></li><li><p>If the binary is on the allow-list, allow the bind. Otherwise, deny it.</p></li></ol><p>To verify the mitigation on a given machine without exploiting it, the <a href="https://copy.fail/"><u>Copy Fail</u></a> write-up gives a one-liner:</p>
            <pre><code>python3 -c 'import socket; s = socket.socket(socket.AF_ALG, socket.SOCK_SEQPACKET, 0); s.bind(("aead","authencesn(hmac(sha256),cbc(aes))"));'</code></pre>
            <p>On a mitigated machine you get PermissionError: [Errno 1] Operation not permitted (or FileNotFoundError, depending on which mitigation is active) instead of a successful bind.</p>
    <div>
      <h4>Rolling it out</h4>
      <a href="#rolling-it-out">
        
      </a>
    </div>
    <p><b>Before enabling enforcement, we verified that our known internal service was the sole legitimate </b><code><b>AF_ALG</b></code><b> user to avoid accidental outages.</b> We used <a href="https://github.com/cloudflare/ebpf_exporter"><code>prometheus-ebpf-exporter</code></a> to hook the <code>socket()</code> syscall and track <code>AF_ALG</code> usage per binary across the fleet. This required no kernel changes and provided aggregate data from hundreds of thousands of servers within hours. Results confirmed the identified service was indeed the only legitimate user.</p><p>So the bpf-lsm rollout was deliberately staged in two steps:</p><ol><li><p><b>Get visibility first.</b> Push the ebpf-exporter config gated by salt. Confirm at the metric layer that the known service is effectively the only thing creating <code>AF_ALG</code> sockets.</p></li><li><p><b>Then enforce.</b> Push the bpf-lsm program behind a separate enforcement gate.</p></li></ol><p>In parallel, the upstream backport for our majority LTS line finally became available, and our internal automation built a patched kernel against it.</p><p>We started to test the patched kernel in our staging datacenters as soon as possible, then we resumed the longer reboot process in order to fully patch our fleet.</p>
    <div>
      <h2>Remediation and follow-up steps</h2>
      <a href="#remediation-and-follow-up-steps">
        
      </a>
    </div>
    <p>While we were prepared for this scenario, at Cloudflare we’re always learning and improving. Key areas we identified for improvement:</p><ul><li><p><b>Better visibility into kernel-API dependencies.</b> We will review kernel-subsystem usage across production services, so we can continue to quickly mitigate exploits without service disruption.</p></li><li><p><b>Better runtime mitigation.</b> bpf-lsm is a valuable tool for mitigations, but we want to make this tool even better. This will include looking into faster deployments, better playbooks, and better logging and visibility of the tool. </p></li><li><p><b>Reduce attack surface of Linux Kernel</b>. Review and audit our kernel configuration. Proactively identify unused modules or features so that we can remove them from our build entirely.</p></li></ul>
    <div>
      <h2>Conclusion</h2>
      <a href="#conclusion">
        
      </a>
    </div>
    <p>The "Copy Fail" vulnerability presented a unique challenge for us. Despite our practice of deploying Linux patch updates every two weeks, we remained vulnerable because a month-old mainline fix had yet to be backported to our primary kernel line. Despite that, we were still able to roll out patched kernels within hours of the backport's release. In the interim, bpf-lsm provided a surgical, no-reboot mitigation that secured our fleet. While our initial attempt to disable the problematic module failed, it did so safely within our internal staging environment rather than production, allowing us to identify this dependency.</p><p>By the end of the rollout, every machine in our fleet was protected by either a patched kernel or a bpf-lsm program denying the vulnerable code path to non-allow-listed binaries. There was no customer impact at any point during this incident, and we have committed to the follow-up work above to make our response faster and our visibility better the next time something like this lands. Responsible disclosure works, in-kernel visibility tooling pays off in moments exactly like this one, and bpf-lsm continues to be one of the most useful primitives we have for runtime kernel mitigation.</p><p>At Cloudflare, critical vulnerability response is a coordinated effort across Security, Engineering, Product, and many other teams. Special thanks to Ali Adnan, Ivan Babrou, Frederik Baetens, Curtis Bray, Piers Cornwell, Everton Didone Foscarini, Rob Dinh, Elle Dougherty, Kevin Flansburg, Matt Fleming, Kimberley Hall, Brandon Harris, Jerry Ho, Oxana Kharitonova, Marek Kroemeke, Fred Lawler, James Munson, Nafeez Nazer, Walead Parviz, Miguel Pato, Evan Pratten, Josh Seba, June Slater, Ryan Timken, Michael Wolf, Jianxin Zeng and everyone else who contributed to the investigation, mitigation, and remediation of Copy Fail. We'd also like to thank the Linux upstream maintainers and Copy Fail researchers whose work helped make a rapid response possible.</p> ]]></content:encoded>
            <category><![CDATA[Linux]]></category>
            <category><![CDATA[Security]]></category>
            <category><![CDATA[Incident Response]]></category>
            <category><![CDATA[Kernel]]></category>
            <category><![CDATA[Vulnerabilities]]></category>
            <category><![CDATA[Mitigation]]></category>
            <category><![CDATA[eBPF]]></category>
            <guid isPermaLink="false">7JN0oOT8V9YgCD6JFW92my</guid>
            <dc:creator>Chris J Arges</dc:creator>
            <dc:creator>Sourov Zaman</dc:creator>
            <dc:creator>Rian Islam</dc:creator>
        </item>
        <item>
            <title><![CDATA[Network flow monitoring is GA, providing end-to-end traffic visibility]]></title>
            <link>https://blog.cloudflare.com/network-flow-monitoring-generally-available/</link>
            <pubDate>Wed, 18 Oct 2023 13:00:53 GMT</pubDate>
            <description><![CDATA[ Network engineers often need better visibility into their network’s traffic when analyzing DDoS attacks or troubleshooting other traffic anomalies. To solve this problem, Cloudflare offers a network flow monitoring product that gives customers end-to-end traffic visibility across their network. ]]></description>
            <content:encoded><![CDATA[ <p></p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4EZamNYbSPCC1yBqXXwaZR/d3e36168073dcc8f08b715ab7d4bbe5e/image4-4.png" />
            
            </figure><p>Network engineers often find they need better visibility into their network’s traffic and operations while analyzing DDoS attacks or troubleshooting other traffic anomalies. These engineers typically have some high level metrics about their network traffic, but they struggle to collect essential information on the specific traffic flows that would clarify the issue. To solve this problem, Cloudflare has been piloting a <a href="https://www.cloudflare.com/network-services/solutions/network-monitoring-tools/">cloud network flow monitoring product</a> called <a href="https://www.cloudflare.com/network-services/products/magic-network-monitoring/">Magic Network Monitoring</a> that gives customers end-to-end visibility into all traffic across their network.</p><p>Today, Cloudflare is excited to announce that Magic Network Monitoring (previously called <a href="/flow-based-monitoring-for-magic-transit/">Flow Based Monitoring</a>) is now generally available to all enterprise customers. Over the last year, the Cloudflare engineering team has significantly improved Magic Network Monitoring; we’re excited to offer a network services product that will help our customers identify threats faster, reduce vulnerabilities, and <a href="https://www.cloudflare.com/network-services/solutions/enterprise-network-security/">make their network more secure</a>.</p><p>Magic Network Monitoring is automatically enabled for all Magic Transit and Magic WAN enterprise customers. The product is located at the account level of the Cloudflare dashboard and can be opened by navigating to “Analytics &amp; Logs &gt; Magic Monitoring”. The onboarding process for Magic Network Monitoring is self-serve, and all enterprise customers with access can begin configuring the product today.</p><p>Any enterprise customers without Magic Transit or Magic WAN that are interested in testing Magic Network Monitoring can receive access to the free version (with some <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">limitations</a> on traffic volume) by submitting a request to their Cloudflare account team or filling out this form to <a href="https://cloudflare.com/network-services/products/magic-network-monitoring/">talk with an expert</a>.</p>
    <div>
      <h3>What is Magic Network Monitoring?</h3>
      <a href="#what-is-magic-network-monitoring">
        
      </a>
    </div>
    <p>Magic Network Monitoring is a cloud network flow monitor. <a href="https://en.wikipedia.org/wiki/Traffic_flow_(computer_networking)">Network traffic flow</a> refers to any stream of packets between one source and one destination with the same Internet protocol and set of ports. Customers can send network flow reports from their routers (or any other network flow generator) to a publicly available endpoint on <a href="https://www.cloudflare.com/learning/cdn/glossary/anycast-network/">Cloudflare’s anycast network</a>, even if the traffic didn’t originally pass through Cloudflare’s network. Cloudflare analyzes the network flow data, then provides customers visibility into key network traffic metrics via an analytics dashboard. These metrics include: traffic volume (in bits or packets) over time, source IPs, destination IPs, ports, traffic protocols, and router IPs. Customers can also configure alerts to identify <a href="https://www.cloudflare.com/learning/ddos/what-is-a-ddos-attack/">DDoS attacks</a> and any other abnormal traffic volume activities.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3CrObnYrLzKlSOjSUS8dH6/c59b39388b98ba4e7492121d5db3bacf/1-1.png" />
            
            </figure><p>Send flow data from your network to Cloudflare for analysis</p>
    <div>
      <h3>Enterprise DDoS attack type detection</h3>
      <a href="#enterprise-ddos-attack-type-detection">
        
      </a>
    </div>
    <p><a href="https://developers.cloudflare.com/magic-transit/on-demand/">Magic Transit On Demand</a> (MTOD) customers will experience significant traffic visibility benefits when using Magic Network Monitoring. <a href="https://www.cloudflare.com/network-services/products/magic-transit/">Magic Transit</a> is a <a href="https://www.cloudflare.com/network-security/">network security solution</a> that offers DDoS protection and traffic acceleration from every Cloudflare data center for on-premise, cloud-hosted, and hybrid networks. Magic Transit On Demand customers can activate Magic Transit for protection when a DDoS attack is detected.</p><p>In general, we noticed that some MTOD customers lacked the network visibility tools to quickly identify DDoS attacks and take the appropriate mitigation action. Now, MTOD customers can use Magic Network Monitoring to analyze their network data and receive an alert if a DDoS attack is detected.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6HcgWfT995D5YTtTjI7t0x/8f5265dc6c920df9aa4de7db814bfc71/2-1.png" />
            
            </figure><p>Cloudflare detects a DDoS attack from the customer’s network flow data</p><p>Once a DDoS attack is detected, Magic Network Monitoring customers can choose to either manually or automatically enable Magic Transit to mitigate any DDoS attacks.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5FlxXObNPK0L8lx2sN0S6S/8a47e805c9ec45f41c1f9d3bf6d84a33/3-1.png" />
            
            </figure><p>Activate Magic Transit for DDoS protection</p>
    <div>
      <h3>Enterprise network monitoring</h3>
      <a href="#enterprise-network-monitoring">
        
      </a>
    </div>
    <p>Cloudflare’s Magic WAN and Cloudflare One customers can also benefit from using Magic Network Monitoring. Today, these customers have excellent visibility into the traffic they send through Cloudflare’s network, but sometimes they may lack visibility into traffic that isn’t sent through Cloudflare. This can include traffic that remains on a local network, or network traffic sent in between cloud environments. Magic WAN and Cloudflare One customers can add Magic Network Monitoring into their suite of product solutions to establish end-to-end network visibility across all traffic on their network.</p>
    <div>
      <h3>A deep dive into network flow and network traffic sampling</h3>
      <a href="#a-deep-dive-into-network-flow-and-network-traffic-sampling">
        
      </a>
    </div>
    <p>Magic Network Monitoring gives customers better visibility into their network traffic by ingesting and analyzing network flow data.</p><p>The process starts when a router (or other network flow generation device) collects <a href="https://en.wikipedia.org/wiki/Sampling_(statistics)">statistical samples</a> of inbound and / or outbound packet data. These samples are collected by examining 1 in every X packets, where X is the sampling rate configured on the router. Typical sampling rates range from 1 in every 1,000 to 1 in every 4,000 packets. The ideal sampling rate depends on the traffic volume, traffic diversity, and the compute / memory power of your router’s hardware. You can read more about the <a href="https://developers.cloudflare.com/magic-network-monitoring/routers/recommended-sampling-rate/">recommended network flow sampling rate</a> in Cloudflare’s MNM Developer Docs.</p><p>The sampled data is packaged into one of two industry standard formats for network flow data: NetFlow or sFlow. In NetFlow, the sampled packet data is grouped by different packet characteristics such as source / destination IP, port, and protocol. Each group of sampled packet data also includes a traffic volume estimate. In sFlow, the entire packet header is selected as the representative sample, and there isn’t any data summarization. As a result, sFlow is a richer data format and includes more details about network traffic than NetFlow data. Once either the NetFlow or sFlow data samples are collected, they’re sent to Magic Network Monitoring for analysis and alerting.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2XoUWHVTlsaVD6wYjekYm6/951cff39344b3912444f239618af64c6/4-1.png" />
            
            </figure>
    <div>
      <h3>Why simple random sampling didn’t work for Magic Network Monitoring</h3>
      <a href="#why-simple-random-sampling-didnt-work-for-magic-network-monitoring">
        
      </a>
    </div>
    <p>Magic Network Monitoring has come a long way from its early access release one year ago. In particular, the Cloudflare engineering team invested significant time in improving the accuracy of the traffic volume estimations in MNM. In the early access version of Magic Network Monitoring, customers were unexpectedly reporting that their network traffic volume estimates were too high and didn’t match the expected value.</p><p>Magic Network Monitoring performs its own sampling of the NetFlow or sFlow data it receives, so it can effectively scale and manage the data ingested across Cloudflare’s global network. Increasing the accuracy of the traffic volume estimations was more difficult than expected, as the NetFlow or sFlow data parsed by MNM is already built on sampled packet data. This introduces multiple distinct layers of data sampling in the product’s analytics.</p><p>The first version of Magic Network Monitoring used <a href="https://en.wikipedia.org/wiki/Simple_random_sample">random sampling</a> where a random subset of network flow data with the same timestamp was selected to represent the traffic volume at that point in time. A characteristic of network flow data is that some samples are more significant than others and represent a greater volume of network traffic. In order to account for this significance, we can associate a <a href="https://en.wikipedia.org/wiki/Weighting">weight</a> with each sample based on the traffic volume it represents. Network flow data weights are always positive numbers, and they follow a <a href="https://en.wikipedia.org/wiki/Long_tail">long tail distribution</a>. These data characteristics caused MNM’s random sampling to incorrectly estimate the traffic volume of a customer’s network. Customers would see false spikes in their traffic volume analytics when an outlying data sample from the long tail was randomly selected to be the representative of all traffic at that point in time.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2Tje0Xn9GucCoNamBEyvVE/0d097130617a1c6584efa8679f91c87a/5-1.png" />
            
            </figure>
    <div>
      <h3>Increasing accuracy with VarOpt reservoir sampling</h3>
      <a href="#increasing-accuracy-with-varopt-reservoir-sampling">
        
      </a>
    </div>
    <p>To solve this problem, the Cloudflare engineering team implemented an alternative <a href="https://en.wikipedia.org/wiki/Reservoir_sampling">reservoir sampling</a> technique called <a href="https://arxiv.org/pdf/0803.0473.pdf">VarOpt</a>. VarOpt is designed to collect samples from a stream of data when the length of the data stream is unknown (a perfect application for analyzing incoming network flow data). In the MNM implementation of VarOpt, we start with an empty reservoir of a fixed size that is filled with samples of network flow data. When the reservoir is full, and there is still new incoming network flow data, an old sample is randomly discarded from the reservoir and replaced with a new one.</p><p>After a certain number of samples have been observed, we calculate the traffic volume across all weighted samples in the reservoir, and that is the estimated traffic volume of a customer’s network flow at that point in time. Finally, the reservoir is emptied, and the VarOpt loop is restarted by filling the reservoir with the next set of the latest network flow samples.</p><p>The new VarOpt sampling method significantly increased the accuracy of the traffic volume estimations in Magic Network Monitoring, and solved our customer’s problems. These sampling improvements paved the way for general availability, and we’re excited to make accurate network flow analytics available to everyone.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2NYGpyTodAgtP9K8KycjGZ/fa5e290cdf3286c7efcbbe53954e1540/6-1.png" />
            
            </figure>
    <div>
      <h3>Developer Docs and Discord Community</h3>
      <a href="#developer-docs-and-discord-community">
        
      </a>
    </div>
    <p>There are detailed <a href="https://developers.cloudflare.com/magic-network-monitoring/">Developer Docs for Magic Network Monitoring</a> that explain the product’s features and outlines a step-by-step configuration guide for new customers. As you’re working through the Magic Network Monitoring documentation, please feel free to provide feedback by clicking the “Give Feedback” button in the top right corner of the Developer Docs.</p><p>We’ve also created a channel in Cloudflare’s Discord community built around debugging configuration problems, testing new features, and providing product feedback. You can follow this link to join the <a href="https://discord.gg/cloudflaredev">Cloudflare Discord server</a>.</p>
    <div>
      <h3>Free version</h3>
      <a href="#free-version">
        
      </a>
    </div>
    <p>A <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">free version of Magic Network Monitoring</a> is available to all Enterprise customers on request to their Cloudflare account team. The free version is designed to enable Enterprise customers to quickly test and evaluate Magic Network Monitoring before purchasing Magic Transit, Magic WAN, or Cloudflare One. Enterprise customers can fully configure Magic Network Monitoring themselves by following the <a href="https://developers.cloudflare.com/magic-network-monitoring/get-started/">step-by-step onboarding guide</a> in the product’s documentation. The free version has some <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">limitations</a> on the quantity of traffic that can be processed which are further outlined in the product’s documentation.</p><p>The free version of Magic Network Monitoring is also available to all Free, Pro, and Business plan Cloudflare customers via a closed beta. Anyone can request access to the free version by <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">reading the free version documentation</a> and <a href="https://forms.gle/z93ghpydpKdAFZ7P9">filling out this form</a>. Priority access is granted to anyone that joins <a href="https://discord.com/invite/cloudflaredev">Cloudflare’s Discord server</a> and sends a message in the Magic Network Monitoring Discord channel.</p>
    <div>
      <h3>Next steps that you can take today</h3>
      <a href="#next-steps-that-you-can-take-today">
        
      </a>
    </div>
    <p>Magic Network Monitoring is generally available, and all Magic Transit and Magic WAN customers have been automatically granted access to the product today. You can navigate to the product by going to the account level of the Cloudflare dashboard, then selecting “Analytics &amp; Logs &gt; Magic Monitoring”.</p><p>If you’re an enterprise customer without Magic Transit or Magic WAN, and you want to use Magic Network Monitoring to improve your traffic visibility, you can <a href="https://cloudflare.com/network-services/products/magic-network-monitoring/">talk with an MNM expert today</a>.</p><p>If you’re interested in using Magic Transit and Magic Network Monitoring for DDoS protection, you can <a href="https://www.cloudflare.com/network-services/products/magic-transit/">request a demo of Magic Transit</a>. If you want to use Magic WAN and Magic Network Monitoring together to establish end-to-end network traffic visibility, you can <a href="https://www.cloudflare.com/network-services/products/magic-wan/">talk with a Magic WAN expert</a>.</p> ]]></content:encoded>
            <category><![CDATA[Magic Network Monitoring]]></category>
            <category><![CDATA[Network Services]]></category>
            <category><![CDATA[Magic Transit]]></category>
            <category><![CDATA[Magic WAN]]></category>
            <category><![CDATA[Product News]]></category>
            <guid isPermaLink="false">5Q496AB243DF9bETeys1Pq</guid>
            <dc:creator>Chris Draper</dc:creator>
            <dc:creator>Chris J Arges</dc:creator>
            <dc:creator>Ana Oliveira</dc:creator>
            <dc:creator>João Santos</dc:creator>
            <dc:creator>Luís Franco</dc:creator>
            <dc:creator>Nadin El-Yabroudi</dc:creator>
            <dc:creator>Dan Geraghty</dc:creator>
        </item>
        <item>
            <title><![CDATA[How We Used eBPF to Build Programmable Packet Filtering in Magic Firewall]]></title>
            <link>https://blog.cloudflare.com/programmable-packet-filtering-with-magic-firewall/</link>
            <pubDate>Mon, 06 Dec 2021 13:59:53 GMT</pubDate>
            <description><![CDATA[ By combining the power of eBPF and Nftables, Magic Firewall can mitigate sophisticated attacks on infrastructure by enforcing a positive security model. ]]></description>
            <content:encoded><![CDATA[ <p></p><p>Cloudflare actively protects services from sophisticated attacks day after day. For users of Magic Transit, <a href="https://www.cloudflare.com/ddos/">DDoS protection</a> detects and drops attacks, while <a href="https://www.cloudflare.com/magic-firewall/">Magic Firewall</a> allows custom packet-level rules, enabling customers to deprecate hardware firewall appliances and block malicious traffic at Cloudflare’s network. The types of attacks and sophistication of attacks continue to evolve, as recent DDoS and reflection <a href="/attacks-on-voip-providers/">attacks</a> <a href="/update-on-voip-attacks/">against</a> VoIP services targeting protocols such as <a href="https://en.wikipedia.org/wiki/Session_Initiation_Protocol">Session Initiation Protocol</a> (SIP) have shown. Fighting these attacks requires pushing the limits of packet filtering beyond what traditional firewalls are capable of. We did this by taking best of class technologies and combining them in new ways to turn Magic Firewall into a blazing fast, fully programmable firewall that can stand up to even the most sophisticated of attacks.</p>
    <div>
      <h3>Magical Walls of Fire</h3>
      <a href="#magical-walls-of-fire">
        
      </a>
    </div>
    <p><a href="/introducing-magic-firewall/">Magic Firewall</a> is a distributed stateless packet firewall built on Linux nftables. It runs on every server, in every Cloudflare data center around the world. To provide isolation and flexibility, each customer’s nftables rules are configured within their own Linux network namespace.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/7IjaJVGQWr5ssJPteOj4DR/2a0a310c33b86840a752386253f555b9/image1-20.png" />
            
            </figure><p>This diagram shows the life of an example packet when using <a href="/magic-transit-network-functions/">Magic Transit</a>, which has Magic Firewall built in. First, packets go into the server and DDoS protections are applied, which drops attacks as early as possible. Next, the packet is routed into a customer-specific network namespace, which applies the nftables rules to the packets. After this, packets are routed back to the origin via a GRE tunnel. Magic Firewall users can construct firewall statements from a <a href="https://developers.cloudflare.com/magic-firewall">single API</a>, using a flexible <a href="https://github.com/cloudflare/wirefilter">Wirefilter syntax</a>. In addition, rules can be configured via the Cloudflare dashboard, using friendly UI drag and drop elements.</p><p>Magic Firewall provides a very powerful syntax for matching on various packet parameters, but it is also limited to the matches provided by nftables. While this is more than sufficient for many use cases, it does not provide enough flexibility to implement the advanced packet parsing and content matching we want. We needed more power.</p>
    <div>
      <h3>Hello eBPF, meet Nftables!</h3>
      <a href="#hello-ebpf-meet-nftables">
        
      </a>
    </div>
    <p>When looking to add more power to your Linux networking needs, Extended Berkeley Packet Filter (<a href="https://ebpf.io/">eBPF</a>) is a natural choice. With eBPF, you can insert packet processing programs that execute <i>in the kernel</i>, giving you the flexibility of familiar programming paradigms with the speed of in-kernel execution. Cloudflare <a href="/tag/ebpf/">loves eBPF</a> and this technology has been transformative in enabling many of our products. Naturally, we wanted to find a way to use eBPF to extend our use of nftables in Magic Firewall. This means being able to match, using an eBPF program within a table and chain as a rule. By doing this we can have our cake and eat it too, by keeping our existing infrastructure and code, and extending it further.</p><p>If nftables could leverage eBPF natively, this story would be much shorter; alas, we had to continue our quest. To get us started in our search, we know that iptables integrates with eBPF. For example, one can use iptables and a pinned eBPF program for dropping packets with the following command:</p>
            <pre><code>iptables -A INPUT -m bpf --object-pinned /sys/fs/bpf/match -j DROP</code></pre>
            <p>This clue helped to put us on the right path. Iptables uses the <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/netfilter/xt_bpf.c#n60">xt_bpf</a> extension to match on an eBPF program. This extension uses the BPF_PROG_TYPE_SOCKET_FILTER eBPF program type, which allows us to load the packet information from the socket buffer and return a value based on our code.</p><p>Since we know iptables can use eBPF, why not just use that? Magic Firewall currently leverages nftables, which is a great choice for our use case due to its flexibility in syntax and programmable interface. Thus, we need to find a way to use the xt_bpf extension with nftables.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4EnxwNmNsjU68l44Mf0M3J/8d5f3b9cfc9f74f1d398c2955925e0c0/image2-13.png" />
            
            </figure><p>This <a href="https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables#using_iptables_nft">diagram</a> helps explain the relationship between iptables, nftables and the kernel. The nftables API can be used by both the iptables and nft userspace programs, and can configure both xtables matches (including xt_bpf) and normal nftables matches.</p><p>This means that given the right API calls (netlink/netfilter messages), we can embed an xt_bpf match within an nftables rule. In order to do this, we need to understand which netfilter messages we need to send. By using tools such as strace, Wireshark, and especially using the <a href="https://github.com/torvalds/linux/blob/master/net/netfilter/xt_bpf.c">source</a> we were able to construct a message that could append an eBPF rule given a table and chain.</p>
            <pre><code>NFTA_RULE_TABLE table
NFTA_RULE_CHAIN chain
NFTA_RULE_EXPRESSIONS | NFTA_MATCH_NAME
	NFTA_LIST_ELEM | NLA_F_NESTED
	NFTA_EXPR_NAME "match"
		NLA_F_NESTED | NFTA_EXPR_DATA
		NFTA_MATCH_NAME "bpf"
		NFTA_MATCH_REV 1
		NFTA_MATCH_INFO ebpf_bytes	</code></pre>
            <p>The structure of the netlink/netfilter message to add an eBPF match should look like the above example. Of course, this message needs to be properly embedded and include a conditional step, such as a verdict, when there is a match. The next step was decoding the format of <code>ebpf_bytes</code> as shown in the example below.</p>
            <pre><code> struct xt_bpf_info_v1 {
	__u16 mode;
	__u16 bpf_program_num_elem;
	__s32 fd;
	union {
		struct sock_filter bpf_program[XT_BPF_MAX_NUM_INSTR];
		char path[XT_BPF_PATH_MAX];
	};
};</code></pre>
            <p>The bytes format can be found in the kernel header definition of <a href="https://git.netfilter.org/iptables/tree/include/linux/netfilter/xt_bpf.h#n27">struct xt_bpf_info_v1</a>. The code example above shows the relevant parts of the structure.</p><p>The xt_bpf module supports both raw bytecodes, as well as a path to a pinned ebpf program. The later mode is the technique we used to combine the ebpf program with nftables.</p><p>With this information we were able to write code that could create netlink messages and properly serialize any relevant data fields. This approach was just the first step, we are also looking into incorporating this into proper tooling instead of sending custom netfilter messages.</p>
    <div>
      <h3>Just Add eBPF</h3>
      <a href="#just-add-ebpf">
        
      </a>
    </div>
    <p>Now we needed to construct an eBPF program and load it into an existing nftables table and chain. Starting to use eBPF can be a bit daunting. Which program type do we want to use? How do we compile and load our eBPF program? We started this process by doing some exploration and research.</p><p>First we constructed an example program to try it out.</p>
            <pre><code>SEC("socket")
int filter(struct __sk_buff *skb) {
  /* get header */
  struct iphdr iph;
  if (bpf_skb_load_bytes(skb, 0, &amp;iph, sizeof(iph))) {
    return BPF_DROP;
  }

  /* read last 5 bytes in payload of udp */
  __u16 pkt_len = bswap_16(iph.tot_len);
  char data[5];
  if (bpf_skb_load_bytes(skb, pkt_len - sizeof(data), &amp;data, sizeof(data))) {
    return BPF_DROP;
  }

  /* only packets with the magic word at the end of the payload are allowed */
  const char SECRET_TOKEN[5] = "xyzzy";
  for (int i = 0; i &lt; sizeof(SECRET_TOKEN); i++) {
    if (SECRET_TOKEN[i] != data[i]) {
      return BPF_DROP;
    }
  }

  return BPF_OK;
}</code></pre>
            <p>The excerpt mentioned is an example of an eBPF program that only accepts packets that have a magic string at the end of the payload. This requires checking the total length of the packet to find where to start the search. For clarity, this example omits error checking and headers.</p><p>Once we had a program, the next step was integrating it into our tooling. We tried a few technologies to load the program, like BCC, libbpf, and we even created a custom loader. Ultimately, we ended up using <a href="https://github.com/cilium/ebpf/">cilium’s ebpf library</a>, since we are using Golang for our control-plane program and the library makes it easy to generate, embed and load eBPF programs.</p>
            <pre><code># nft list ruleset
table ip mfw {
	chain input {
		#match bpf pinned /sys/fs/bpf/mfw/match drop
	}
}</code></pre>
            <p>Once the program is compiled and pinned, we can add matches into nftables using netlink commands. Listing the ruleset shows the match is present. This is incredible! We are now able to deploy custom C programs to provide advanced matching inside a Magic Firewall ruleset!</p>
    <div>
      <h3>More Magic</h3>
      <a href="#more-magic">
        
      </a>
    </div>
    <p>With the addition of eBPF to our toolkit, Magic Firewall is an even more flexible and powerful way to protect your network from bad actors. We are now able to look deeper into packets and implement more complex matching logic than nftables alone could provide. Since our firewall is running as software on all Cloudflare servers, we can quickly iterate and update features.</p><p>One outcome of this project is SIP protection, which is currently in beta. That’s only the beginning. We are currently exploring using eBPF for protocol validations, advanced field matching, looking into payloads, and supporting even larger sets of IP lists.</p><p>We welcome your help here, too! If you have other use cases and ideas, please talk to your account team. If you find this technology interesting, come <a href="https://www.cloudflare.com/careers/">join our team</a>!</p> ]]></content:encoded>
            <category><![CDATA[CIO Week]]></category>
            <category><![CDATA[Magic Firewall]]></category>
            <category><![CDATA[Magic Transit]]></category>
            <category><![CDATA[Security]]></category>
            <category><![CDATA[VoIP]]></category>
            <category><![CDATA[eBPF]]></category>
            <guid isPermaLink="false">1RUM6TLPNlUYMBqyfPL81y</guid>
            <dc:creator>Chris J Arges</dc:creator>
        </item>
    </channel>
</rss>