From ab60d82ca57252e4d5f7146acf34aaee52c6fc3b Mon Sep 17 00:00:00 2001 From: Andy Chiang Date: Thu, 29 Oct 2026 10:40:10 +0700 Subject: [PATCH] ppp: keep credentials off the ujail command line Read the username and password from a file to avoid exposing the password in the `ujail` command line. pppd parses options files itself, so backslash and double quote in the username and password are escaped with a backslash when the file is written. Values passed on the command line are not parsed and needed no escaping. Use `net-init-script` to delete the temporary file after `pppd` has read its options, and unconditionally delete it when the interface is brought down. Fixes: b855f33ea916 ("ppp: run pppd in ujail as an unprivileged user") Signed-off-by: Andy Chiang Link: https://github.com/openwrt/openwrt/pull/26293 Signed-off-by: Robert Marko --- package/network/services/ppp/Makefile | 3 ++- .../ppp/files/lib/netifd/ppp-net-init | 7 +++++ package/network/services/ppp/files/ppp.sh | 26 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 package/network/services/ppp/files/lib/netifd/ppp-net-init diff --git a/package/network/services/ppp/Makefile b/package/network/services/ppp/Makefile index 5a87016fbbd..f9360ec8e65 100644 --- a/package/network/services/ppp/Makefile +++ b/package/network/services/ppp/Makefile @@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=ppp PKG_VERSION:=2.5.4 -PKG_RELEASE:=3 +PKG_RELEASE:=4 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://download.samba.org/pub/ppp @@ -220,6 +220,7 @@ define Package/ppp/install $(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_BIN) ./files/lib/netifd/ppp-net-init $(1)/lib/netifd/ $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_BIN) ./files/50-ppp-secrets-mode.sh $(1)/etc/uci-defaults endef diff --git a/package/network/services/ppp/files/lib/netifd/ppp-net-init b/package/network/services/ppp/files/lib/netifd/ppp-net-init new file mode 100644 index 00000000000..f0b5ecf94f4 --- /dev/null +++ b/package/network/services/ppp/files/lib/netifd/ppp-net-init @@ -0,0 +1,7 @@ +#!/bin/sh +# pppd net-init script. It runs once the ppp unit is known, which is after +# pppd has parsed its options, so the credentials file written by ppp.sh is +# no longer needed. +# $1 ifname $2 tty $3 speed $4 ipparam (the netifd interface name) +[ -n "$4" ] && rm -f "/var/run/pppd/$4.opts" +exit 0 diff --git a/package/network/services/ppp/files/ppp.sh b/package/network/services/ppp/files/ppp.sh index c61c034e2f9..0405606804d 100755 --- a/package/network/services/ppp/files/ppp.sh +++ b/package/network/services/ppp/files/ppp.sh @@ -65,6 +65,20 @@ ppp_exitcode_tostring() esac } +ppp_opt_quote() { + printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g' +} + +ppp_write_auth_file() { + local file="$1" user="$2" pass="$3" + + ( + umask 077 + printf 'user "%s"\npassword "%s"\n' \ + "$(ppp_opt_quote "$user")" "$(ppp_opt_quote "$pass")" > "$file" + ) +} + ppp_generic_init_config() { proto_config_add_string username proto_config_add_string password @@ -163,6 +177,14 @@ ppp_generic_setup() { done } + local optfile + [ -n "$username" ] && { + optfile="/var/run/pppd/$config.opts" + mkdir -p /var/run/pppd + ppp_write_auth_file "$optfile" "$username" "$password" + [ -n "$jail" ] && chown ppp "$optfile" + } + proto_run_command "$config" $jail /usr/sbin/pppd \ nodetach ipparam "$config" \ ifname "$pppname" \ @@ -180,7 +202,7 @@ ppp_generic_setup() { usepeerdns \ $demand $persist maxfail $maxfail \ ${holdoff:+holdoff "$holdoff"} \ - ${username:+user "$username" password "$password"} \ + ${optfile:+file "$optfile" net-init-script /lib/netifd/ppp-net-init} \ ${connect:+connect "$connect"} \ ${disconnect:+disconnect "$disconnect"} \ ip-up-script /lib/netifd/ppp-up \ @@ -195,6 +217,8 @@ ppp_generic_teardown() { local interface="$1" local errorstring=$(ppp_exitcode_tostring $ERROR) + rm -f "/var/run/pppd/$interface.opts" + case "$ERROR" in 0) ;;