mirror of
https://github.com/openwrt/openwrt.git
synced 2026-11-27 14:41:12 +04:00
ppp: run pppd in ujail as an unprivileged user
pppd drops to user ppp (uid 454, created via USERID) with CAP_NET_ADMIN (/dev/ppp, PPPIOCNEWUNIT, SIOCSIF*) and CAP_NET_RAW (pppoe PF_PACKET), both ambient so ip-up/ip-down scripts keep them, with PR_SET_NO_NEW_PRIVS. The wrapper covers every proto that routes through ppp_generic_setup() and is skipped when /sbin/ujail, the capabilities file or the ppp user is missing. ujail exits EXIT_FAILURE on a -U name it cannot resolve, and a sysupgrade can preserve an /etc/passwd that predates the uid. pppd's euid != 0 gate (EXIT_NOT_ROOT) would stop the drop. ppp 2.5.4 lets pppd run without root when it holds CAP_NET_ADMIN (ppp-project/ppp#608) and grants the privileged option flag on the capability, which proto_pppoe_setup() needs for its OPT_PRIV "plugin pppoe.so", unless the exec itself raised the privileges (AT_SECURE). The wrapper also hands /dev/ppp to the ppp user. The node is opened at link setup (generic_establish_ppp), not only in the (stubbed) kernel support check, and ships 0600 root:root. chown keeps it reachable for uid 454 alone; the kernel's ppp_open() gates on ns_capable(CAP_NET_ADMIN) either way. pppd mkdir_recursive()s PPP_PATH_VARRUN and writes its <ifname>.pid and pppd2.tdb there, which is /var/run/pppd with OpenWrt's --localstatedir=/var; nothing in this package creates that directory today, and uid 454 cannot do it in a root-owned /var/run, so the wrapper pre-creates and chowns it. A failure to write the pid file is a logged error and a failed tdb open a warning (multilink drops), neither fatal. usepeerdns makes pppd rewrite /etc/ppp/resolv.conf, the package's symlink to /tmp/resolv.conf.ppp, at every connect; a copy left by a root-run instance across an in-place upgrade refuses uid 454, so the wrapper removes it first. Nothing in OpenWrt reads that file, the DNS servers reach netifd through the DNS1/DNS2 environment. The ip-up/ip-down scripts run inside the jail and report back to netifd over ubus; ubusd's ACL default is deny for every non-root uid, so the jailed notify_proto call failed silently and the interface never completed setup while the PPP session sat connected. Ship /usr/share/acl.d/pppd.json granting uid 454 access to network.interface notify_proto and network add_dynamic (ppp6-up's dynamic-interface registry call). The postinst reloads the ubusd ACLs, so an upgrade on a running router does not leave the interface down. User hooks in /etc/ppp/ip-up.d and ip-down.d run the same way, as uid 454 with CAP_NET_ADMIN and CAP_NET_RAW only; a hook that needs root no longer gets it. Two things the unprivileged uid cannot reach on its own. A serial link is handed its TTY as a pppd argument - first by proto_ppp_setup, last by comgt's proto_3g_setup - and a TTY is root:dialout 0660, which CAP_NET_ADMIN does not override, so the wrapper grants whichever argument is a character device, the same way it already grants /dev/ppp. And the secrets pppd authenticates from ship 0600 root:root - chap-secrets here, the RADIUS server list in ppp-mod-radius - so a uci-defaults script regrades them to 0640 root:ppp. That has to run on the device: a postinst runs on the build host with IPKG_INSTROOT set, where chgrp resolves the group name through the host's /etc/group and not the target's, so the image would ship them root:root regardless. Assisted-by: Claude:claude-opus-5 Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de> Link: https://github.com/openwrt/openwrt/pull/25537 Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
1 parent
e9c8d91f6d
commit
b855f33ea9
6 files changed
+93
-2
No files matched your search
@@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=ppp
|
||||
PKG_VERSION:=2.5.4
|
||||
PKG_RELEASE:=2
|
||||
PKG_RELEASE:=3
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://download.samba.org/pub/ppp
|
||||
@@ -53,6 +53,7 @@ define Package/ppp
|
||||
$(call Package/ppp/Default)
|
||||
DEPENDS:= +USE_GLIBC:libcrypt-compat +kmod-ppp
|
||||
TITLE:=PPP daemon
|
||||
USERID:=ppp=454:ppp=454
|
||||
VARIANT:=default
|
||||
endef
|
||||
|
||||
@@ -60,6 +61,7 @@ define Package/ppp-multilink
|
||||
$(call Package/ppp/Default)
|
||||
DEPENDS:= +USE_GLIBC:libcrypt-compat +kmod-ppp
|
||||
TITLE:=PPP daemon (with multilink support)
|
||||
USERID:=ppp=454:ppp=454
|
||||
VARIANT:=multilink
|
||||
endef
|
||||
|
||||
@@ -209,14 +211,28 @@ define Package/ppp/install
|
||||
$(INSTALL_DATA) ./files/etc/ppp/filter $(1)/etc/ppp/
|
||||
$(INSTALL_DATA) ./files/etc/ppp/options $(1)/etc/ppp/
|
||||
$(LN) /tmp/resolv.conf.ppp $(1)/etc/ppp/resolv.conf
|
||||
$(INSTALL_DIR) $(1)/etc/capabilities
|
||||
$(INSTALL_DATA) ./files/pppd.capabilities $(1)/etc/capabilities/pppd.json
|
||||
$(INSTALL_DIR) $(1)/usr/share/acl.d
|
||||
$(INSTALL_DATA) ./files/pppd_acl.json $(1)/usr/share/acl.d/pppd.json
|
||||
$(INSTALL_DIR) $(1)/lib/netifd/proto
|
||||
$(INSTALL_BIN) ./files/ppp.sh $(1)/lib/netifd/proto/
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp-up $(1)/lib/netifd/
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp6-up $(1)/lib/netifd/
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp-down $(1)/lib/netifd/
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/50-ppp-secrets-mode.sh $(1)/etc/uci-defaults
|
||||
endef
|
||||
Package/ppp-multilink/install=$(Package/ppp/install)
|
||||
|
||||
define Package/ppp/postinst
|
||||
#!/bin/sh
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
killall -s HUP ubusd || true
|
||||
fi
|
||||
endef
|
||||
Package/ppp-multilink/postinst=$(Package/ppp/postinst)
|
||||
|
||||
define Package/ppp-mod-pppoa/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/pppd/$(PKG_VERSION)
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/pppd/$(PKG_VERSION)/pppoatm.so \
|
||||
@@ -240,6 +256,8 @@ define Package/ppp-mod-radius/install
|
||||
$(1)/etc/ppp/radius/
|
||||
$(INSTALL_CONF) ./files/etc/ppp/radius/servers \
|
||||
$(1)/etc/ppp/radius/
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/50-ppp-radius-servers-mode.sh $(1)/etc/uci-defaults
|
||||
endef
|
||||
|
||||
define Package/ppp-mod-pppol2tp/install
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
# The RADIUS secret is read by uid ppp; INSTALL_CONF ships it 0600 root:root.
|
||||
[ -f /etc/ppp/radius/servers ] || exit 0
|
||||
chgrp ppp /etc/ppp/radius/servers
|
||||
chmod 0640 /etc/ppp/radius/servers
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# pppd reads these as uid ppp, and INSTALL_CONF ships them 0600 root:root -
|
||||
# as does a file preserved across sysupgrade from an install predating the uid.
|
||||
for secret in /etc/ppp/chap-secrets /etc/ppp/pap-secrets; do
|
||||
[ -f "$secret" ] || continue
|
||||
chgrp ppp "$secret"
|
||||
chmod 0640 "$secret"
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -146,7 +146,24 @@ ppp_generic_setup() {
|
||||
[ "$delegate" != "0" ] && delegate=""
|
||||
[ "$norelease" = "1" ] || norelease=""
|
||||
|
||||
proto_run_command "$config" /usr/sbin/pppd \
|
||||
local jail arg caps=/etc/capabilities/pppd.json
|
||||
[ -x /sbin/ujail ] && [ -f "$caps" ] && id -u ppp >/dev/null 2>&1 && {
|
||||
jail="/sbin/ujail -t 5 -n pppd -U ppp -G ppp -C $caps -c --"
|
||||
chown ppp /dev/ppp
|
||||
mkdir -p /var/run/pppd
|
||||
chown ppp /var/run/pppd
|
||||
# pppd rewrites the peer DNS file behind /etc/ppp/resolv.conf at
|
||||
# every connect; one left by a root-run instance refuses uid 454
|
||||
rm -f /tmp/resolv.conf.ppp
|
||||
# A serial link is handed its TTY as a pppd argument - first by
|
||||
# proto_ppp_setup, last by comgt's proto_3g_setup - and a TTY is
|
||||
# root:dialout 0660, which no capability overrides.
|
||||
for arg in "$@"; do
|
||||
[ -c "$arg" ] && chown ppp "$arg"
|
||||
done
|
||||
}
|
||||
|
||||
proto_run_command "$config" $jail /usr/sbin/pppd \
|
||||
nodetach ipparam "$config" \
|
||||
ifname "$pppname" \
|
||||
${localip:+$localip:} \
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"bounding": [
|
||||
"CAP_NET_ADMIN",
|
||||
"CAP_NET_RAW"
|
||||
],
|
||||
"effective": [
|
||||
"CAP_NET_ADMIN",
|
||||
"CAP_NET_RAW"
|
||||
],
|
||||
"ambient": [
|
||||
"CAP_NET_ADMIN",
|
||||
"CAP_NET_RAW"
|
||||
],
|
||||
"permitted": [
|
||||
"CAP_NET_ADMIN",
|
||||
"CAP_NET_RAW"
|
||||
],
|
||||
"inheritable": [
|
||||
"CAP_NET_ADMIN",
|
||||
"CAP_NET_RAW"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"user": "ppp",
|
||||
"access": {
|
||||
"network.interface": {
|
||||
"methods": [
|
||||
"notify_proto"
|
||||
]
|
||||
},
|
||||
"network": {
|
||||
"methods": [
|
||||
"add_dynamic"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user