Public bug reported:
SUMMARY
-------
On Ubuntu 26.04 (kernel 7.0.0-44-generic), a task confined by any AppArmor
profile gets EACCES from sendmsg()/sendto() with MSG_FASTOPEN on a TCP socket,
and the kernel logs:
apparmor="DENIED" operation="connect" class="net" ... family="inet"
sock_type="stream" protocol=6 requested="connect" denied="connect"
This happens even when the profile grants unrestricted networking
("allow network,"). From the same task, a plain connect() to the same address
works, and so does TCP_FASTOPEN_CONNECT + connect(). Only the implicit connect
done by the MSG_FASTOPEN send path is denied.
Unconfined tasks are not affected.
It reproduces with the stock profiles unprivileged_userns and unpriv_bwrap
(from the apparmor package, used by Flatpak through bubblewrap) and with a
snapd-generated profile (snap.firefox.firefox, which has the network plug).
ENVIRONMENT
-----------
Ubuntu 26.04.1 LTS (resolute), x86_64
Kernel: Ubuntu 7.0.0-44.44-generic 7.0.14
apparmor: 5.0.2-0ubuntu1~26.04.1
bubblewrap: 0.11.1-1ubuntu0.3
flatpak: 1.16.6-1
snapd: 2.78+ubuntu26.04
kernel.apparmor_restrict_unprivileged_userns = 1
net.ipv4.tcp_fastopen = 1 (default)
STEPS TO REPRODUCE (no root needed)
-----------------------------------
tfo_apparmor_repro.py (full source at the end of this report) starts a TCP
listener on 127.0.0.1 and
connects to it in four ways: plain connect(), TCP_FASTOPEN_CONNECT + connect(),
sendto(MSG_FASTOPEN) and sendmsg(MSG_FASTOPEN).
1. python3 tfo_apparmor_repro.py
2. aa-exec -p unprivileged_userns -- python3 tfo_apparmor_repro.py
3. aa-exec -p unpriv_bwrap -- python3 tfo_apparmor_repro.py
4. aa-exec -p snap.firefox.firefox -- python3 - < tfo_apparmor_repro.py
EXPECTED
--------
All four methods succeed under every profile, because each profile grants
network access (unprivileged_userns and unpriv_bwrap: "allow network,";
snap.firefox.firefox: network plug).
ACTUAL
------
Unconfined - all succeed:
connect() OK reply=b'pong'
TCP_FASTOPEN_CONNECT + connect() OK reply=b'pong'
sendto(MSG_FASTOPEN) OK reply=b'pong'
sendmsg(MSG_FASTOPEN) OK reply=b'pong'
unprivileged_userns (enforce):
connect() OK reply=b'pong'
TCP_FASTOPEN_CONNECT + connect() OK reply=b'pong'
sendto(MSG_FASTOPEN) FAIL errno=13 (EACCES)
sendmsg(MSG_FASTOPEN) FAIL errno=13 (EACCES)
unpriv_bwrap (enforce) and snap.firefox.firefox: identical to
unprivileged_userns (the two MSG_FASTOPEN cases fail with EACCES).
Kernel log, one pair of entries per confined run:
apparmor="DENIED" operation="connect" class="net"
profile="unprivileged_userns" comm="python3" family="inet" sock_type="stream"
protocol=6 requested="connect" denied="connect"
apparmor="DENIED" operation="connect" class="net"
profile="snap.firefox.firefox" comm="python3" family="inet" sock_type="stream"
protocol=6 requested="connect" denied="connect"
apparmor="DENIED" operation="connect" class="net" profile="unpriv_bwrap"
comm="python3" family="inet" sock_type="stream" protocol=6 requested="connect"
denied="connect"
OBSERVATIONS / POSSIBLE CAUSE
-----------------------------
The kernel advertises a TCP Fast Open network feature:
/sys/kernel/security/apparmor/features/network_v8/tcp-fast-open: yes
/sys/kernel/security/apparmor/features/network_v9/tcp-fast-open: yes
None of the policy ABI files shipped in apparmor 5.0.2 declare it. A grep for
"tcp-fast-open" in /etc/apparmor.d/abi/ (3.0, 4.0, 4.0-ip, 5.0,
5.0-interface, kernel-5.4-*) finds nothing. All of the profiles above use
"abi <abi/5.0>,".
This looks like the kernel enforcing the new TFO mediation against policy
compiled for an ABI that doesn't know about it. Normally the kernel would fall
back to allowing it for older ABIs. As a result, even "allow network," does not
grant the permission the MSG_FASTOPEN path checks. This is a hypothesis; I have
not confirmed it in the kernel source.
RELATED
-------
Bug #2163740 ("net_inet_tcp_fastopen from ubuntu_qrt_apparmor failed on
Resolute") covers the TCP Fast Open regression test and the parser issues
found while analysing it. This report describes a different, user-facing
symptom. Production profiles that grant "allow network," (unprivileged_userns,
unpriv_bwrap, snapd-generated profiles) deny connects made with MSG_FASTOPEN,
which breaks real applications in Flatpak and Snap. The profiles involved here
contain no deny rules.
REAL-WORLD IMPACT
-----------------
VLC 3.0.x (Flatpak org.videolan.VLC 3.0.24; the snap is expected to behave the
same) opens HTTP/1.1 connections with sendmsg(MSG_FASTOPEN) and treats EACCES
as a fatal error. Inside the Flatpak sandbox (stacked bwrap//&unpriv_bwrap
profile), every HTTP/1.1 request fails, even to a local server on 127.0.0.1:
http stream debug: outgoing request: GET ... HTTP/1.1
http stream debug: connection failed
adaptive demux error: Failed to create demuxer (nil) Unknown
VLC falls back to its legacy HTTP/1.0 module (plain connect()) for normal
URLs. Its adaptive demuxer (HLS/DASH) has no fallback, so no HLS or DASH
stream plays in Flatpak VLC on this system. The kernel log shows the same
denial with comm="vlc.bin" and profile="bwrap" / "unpriv_bwrap".
Any other confined application that uses TCP Fast Open through
MSG_FASTOPEN is likely affected as well.
WORKAROUNDS (tested)
--------------------
- Run the application unconfined (for example VLC from the Ubuntu archive
instead of Flatpak).
- VLC only: start it with --adaptive-use-access, which makes HLS/DASH use the
regular access modules (with the HTTP/1.0 fallback).
REPRODUCER: tfo_apparmor_repro.py
---------------------------------
#!/usr/bin/env python3
"""Minimal reproducer: AppArmor denies the implicit connect done by
sendmsg()/sendto() with MSG_FASTOPEN (TCP Fast Open) for confined tasks,
even when the profile grants `allow network,`. A plain connect() from the
same task is allowed.
No root needed. Run it unconfined and under a confined profile:
python3 tfo_apparmor_repro.py
aa-exec -p unprivileged_userns -- python3 tfo_apparmor_repro.py
aa-exec -p snap.firefox.firefox -- python3 - < tfo_apparmor_repro.py
"""
import errno
import socket
import struct
import threading
TCP_FASTOPEN_CONNECT = getattr(socket, "TCP_FASTOPEN_CONNECT", 30)
TIMEOUT = struct.pack("ll", 3, 0) # struct timeval, 3 s
def start_server():
srv = socket.socket()
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("127.0.0.1", 0))
srv.listen(8)
def loop():
while True:
conn, _ = srv.accept()
conn.settimeout(2)
try:
conn.recv(64)
conn.sendall(b"pong")
except OSError:
pass
conn.close()
threading.Thread(target=loop, daemon=True).start()
return srv.getsockname()
def plain_connect(s, addr):
s.connect(addr)
s.sendall(b"ping")
def fastopen_connect_sockopt(s, addr):
s.setsockopt(socket.IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 1)
s.connect(addr)
s.sendall(b"ping")
def sendto_msg_fastopen(s, addr):
s.sendto(b"ping", socket.MSG_FASTOPEN, addr)
def sendmsg_msg_fastopen(s, addr):
s.sendmsg([b"ping"], [], socket.MSG_NOSIGNAL | socket.MSG_FASTOPEN, addr)
def run(name, fn, addr):
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, TIMEOUT)
s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO, TIMEOUT)
try:
fn(s, addr)
print(f"{name:<34} OK reply={s.recv(4)!r}")
except OSError as e:
print(f"{name:<34} FAIL errno={e.errno} ({errno.errorcode.get(e.errno,
'?')})")
finally:
s.close()
def main():
try:
label = open("/proc/self/attr/current").read().strip()
except OSError:
label = "?"
with open("/proc/sys/net/ipv4/tcp_fastopen") as f:
tfo = f.read().strip()
print(f"apparmor label: {label}")
print(f"net.ipv4.tcp_fastopen = {tfo}")
addr = start_server()
run("connect()", plain_connect, addr)
run("TCP_FASTOPEN_CONNECT + connect()", fastopen_connect_sockopt, addr)
run("sendto(MSG_FASTOPEN)", sendto_msg_fastopen, addr)
run("sendmsg(MSG_FASTOPEN)", sendmsg_msg_fastopen, addr)
if __name__ == "__main__":
main()
** Affects: apparmor (Ubuntu)
Importance: Undecided
Status: New
** Tags: resolute
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2176089
Title:
AppArmor denies TCP Fast Open (sendmsg/sendto with MSG_FASTOPEN) with
EACCES for any confined task, even with "allow network," - breaks VLC
HLS/DASH in Flatpak and Snap
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2176089/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs