[BUG] jemalloc is never loaded when NET_ADMIN/NET_RAW are added
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- docker, linux
- Lĩnh vực
- backend, infrastructure
Hướng nghiên cứu
Start with the svc-homeassistant/run script mentioned in the issue and trace both capability branches, including where setcap runs and how Home Assistant is launched. The report gives an ambient-capability capsh example to compare with the current setup; verify behavior in a rebuilt image with and without Bluetooth capabilities, then confirm jemalloc is mapped in /proc/<pid>/maps in both cases.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
AI disclosure: I found and diagnosed this with an AI assistant (Claude Code). The commands and output below were run on my own Pi, and I've reviewed the report before posting.
svc-homeassistant/run exports LD_PRELOAD=/usr/local/lib/libjemalloc.so.2, but when the container has NET_ADMIN + NET_RAW (as the readme suggests for Bluetooth), the same script first runs setcap on the python binary. A binary with file capabilities runs in secure-execution mode (AT_SECURE=1), and the musl loader ignores LD_PRELOAD in that mode. So Home Assistant silently runs on musl's malloc and MALLOC_CONF does nothing.
In the running container the variable is set, but the library is not mapped:
$ P=$(docker top homeassistant -o pid,args | awk '/python3 -m homeassistant/{print $1}')
$ sudo tr '\0' '\n' < /proc/$P/environ | grep LD_PRELOAD
LD_PRELOAD=/usr/local/lib/libjemalloc.so.2
$ sudo grep -c jemalloc /proc/$P/maps
0
/etc/ld.so.preload isn't a workaround: musl doesn't support it,
Expected Behavior
jemalloc is loaded whether or not the Bluetooth capabilities are enabled, as the run script intends.
Possible fix: grant the capabilities as ambient capabilities instead of file capabilities. Ambient caps don't trigger secure-execution mode, so LD_PRELOAD keeps working. In the repro below, the process ends up with the same effective set (CapEff: 0000000000003400: net_bind_service, net_admin, net_raw) and still runs as abc. Roughly:
exec \
s6-notifyoncheck -d -n 60 -w 5000 -c "nc -z localhost 8123" \
capsh --caps="cap_net_raw,cap_net_admin,cap_net_bind_service+eip cap_setpcap,cap_setuid,cap_setgid+ep" \
--keep=1 --user=abc --addamb=cap_net_raw,cap_net_admin,cap_net_bind_service \
-- -c "exec python3 -m homeassistant -c /config"
The no-Bluetooth branch would need the same treatment with only cap_net_bind_service, since it also runs setcap. I've tested the mechanism, not a rebuilt image with this run script.
Steps To Reproduce
This uses a copy of busybox in place of python, so it doesn't need the full init:
docker run --rm --cap-add NET_ADMIN --cap-add NET_RAW --entrypoint bash \
lscr.io/linuxserver/homeassistant:latest -c '
id abc >/dev/null 2>&1 || adduser -D -u 911 abc
J=/usr/local/lib/libjemalloc.so.2; mkdir /tmp/x; B=/tmp/x/busybox; cp /bin/busybox $B
echo -n "no file caps: "; LD_PRELOAD=$J s6-setuidgid abc $B grep -c jemalloc /proc/self/maps
setcap cap_net_raw,cap_net_admin=+ep $B
echo -n "file caps: "; LD_PRELOAD=$J s6-setuidgid abc $B grep -c jemalloc /proc/self/maps
setcap -r $B
echo -n "ambient caps: "; LD_PRELOAD=$J capsh \
--caps="cap_net_raw,cap_net_admin,cap_net_bind_service+eip cap_setpcap,cap_setuid,cap_setgid+ep" \
--keep=1 --user=abc --addamb=cap_net_raw,cap_net_admin,cap_net_bind_service \
-- -c "$B grep -c jemalloc /proc/self/maps"'
Output (a count of 0 means jemalloc is not loaded):
no file caps: 3
file caps: 0
ambient caps: 3
Environment
- OS: Debian 12 (bookworm), Raspberry Pi 5 Model B 8GB
- How docker service was installed: Docker's official apt repo (docker-ce 29.8.2)
CPU architecture
arm64
Docker creation
homeassistant:
image: lscr.io/linuxserver/homeassistant:latest # 2026.10.4-ls260
network_mode: host
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
volumes:
- ./config:/config
- /var/run/dbus:/var/run/dbus:ro
cap_add:
- NET_ADMIN
- NET_RAW
restart: unless-stopped
Container logs
[migrations] started
[migrations] no migrations found
───────────────────────────────────────
GID/UID
───────────────────────────────────────
User UID: 1000
User GID: 1000
───────────────────────────────────────
Linuxserver.io version: 2026.10.4-ls260
Build-date: 2026-10-24T23:03:55+00:00
───────────────────────────────────────
**** New container detected, fixing python package permissions. This may take a while. ****
Setting permissions
[custom-init] No custom files found, skipping...
Adding cap_net_admin and cap_net_raw to python binary for bt access
[... custom integration warnings omitted ...]
Connection to localhost (::1) 8123 port [tcp/*] succeeded!
[ls.io-init] done.
Note: there is no error to show. The loader drops LD_PRELOAD silently; the relevant line is "Adding cap_net_admin and cap_net_raw to python binary for bt access".
- Ngôn ngữ chính
- Dockerfile
- Star
- 285
- Fork
- 34
- Merge trung bình
- 41 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của linuxserver/docker-homeassistant
-
[BUG] memory leak issueĐang mởno-issue-activity
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
linuxserver/docker-homeassistant#146 · 5 bình luận ·
Tất cả issue của linuxserver/docker-homeassistant
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Fei2411/DeepSeek-Bot#1824 ·
-
sweep
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
bketelsen/truenas-mcp#79 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
sandbox-quantum/switch#2162 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug ready-for-pr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
kunchenguid/no-mistakes#1805 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
self-host
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
funmusicplace/mirlo#2625 ·
Maintainer thường phản hồi trong vòng 1 ngày