Skip to content

Commit 2cedd27

Browse files
authored
Merge pull request #423 from swomf/polkit-write-anywhere
SECURITY: Prevent create_ap's --mkconfig switch from overwriting any file without explicit authorization
2 parents c46049b + 826f0a8 commit 2cedd27

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/scripts/create_ap

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,26 @@ send_stop() {
10061006
write_config() {
10071007
local i=1
10081008

1009-
if ! eval 'echo -n > "$STORE_CONFIG"' > /dev/null 2>&1; then
1009+
# If using pkexec, evaluate permissions before writing.
1010+
# However, the /etc/create_ap.conf
1011+
# location is excepted.
1012+
if [[ "$STORE_CONFIG" != "/etc/create_ap.conf" && $PKEXEC_UID ]]; then
1013+
if [ -e "$STORE_CONFIG" ]; then
1014+
if ! pkexec --user "$(id -nu $PKEXEC_UID)" test -w "$STORE_CONFIG"; then
1015+
echo "ERROR: 1 $(id -nu $PKEXEC_UID) has insufficient permissions to write to config file $STORE_CONFIG"
1016+
exit 1
1017+
fi
1018+
elif ! pkexec --user "$(id -nu $PKEXEC_UID)" test -w "$(dirname "$STORE_CONFIG")"; then
1019+
echo "ERROR: 2 $(id -nu $PKEXEC_UID) has insufficient permissions to write to config file $STORE_CONFIG"
1020+
exit 1
1021+
fi
1022+
# Assume that the user is making a conf file in a directory they normally
1023+
# have control over, and keep permissions strictly private. (i.e. they will
1024+
# need to run create_ap directly with sudo in order to write to, say, /etc/create_ap2.conf)
1025+
touch "$STORE_CONFIG"
1026+
chown "$(id -nu $PKEXEC_UID):$(id -ng $PKEXEC_GID)" "$STORE_CONFIG"
1027+
chmod 600 "$STORE_CONFIG"
1028+
elif ! eval 'echo -n > "$STORE_CONFIG"' > /dev/null 2>&1; then
10101029
echo "ERROR: Unable to create config file $STORE_CONFIG" >&2
10111030
exit 1
10121031
fi

0 commit comments

Comments
 (0)