Skip to content

Commit 5a8cd03

Browse files
committed
MDEV-37899 galera sst generates numerous selinux AVCs when starting
From downstream bug RHEL-116757, the use of ss to map all the usage of ports to pids and process names under selinux is rather limited by the mysqld_exec_t limitations. The checking of the mapping is a bit excessive in a selinux environment where binding is limited. We replace the use of ss under selinux to raw reading of the /proc/tcp{,} interfaces of the linux that aren't selinux restricted.
1 parent 6ea2e99 commit 5a8cd03

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

scripts/wsrep_sst_common.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,13 @@ check_sockets_utils()
12301230
lsof_available=0
12311231
sockstat_available=0
12321232
ss_available=0
1233+
raw_socket_check=0
1234+
1235+
if [ -n "$(commandex selinuxenabled)" ] && selinuxenabled; then
1236+
raw_socket_check=1
1237+
wsrep_log_info "/proc/net/tcp{,6} is being used directly to avoid excessive selinux AVC notices"
1238+
return 0
1239+
fi
12331240

12341241
socket_utility="$(commandex ss)"
12351242
if [ -n "$socket_utility" ]; then
@@ -1298,7 +1305,11 @@ check_port()
12981305

12991306
local rc=2 # ENOENT
13001307

1301-
if [ $ss_available -ne 0 ]; then
1308+
if [ $raw_socket_check -ne 0 ]; then
1309+
for key in $(awk -v p="$port" 'BEGIN { hex_port = sprintf(":%04X", p) } $2 ~ hex_port && $4 == "0A" { print $10 }' /proc/net/tcp /proc/net/tcp6); do
1310+
return 0
1311+
done
1312+
elif [ $ss_available -ne 0 ]; then
13021313
$socket_utility $ss_opts -t "( sport = :$port )" 2>/dev/null | \
13031314
grep -q -E "[[:space:]]users:[[:space:]]?\\(.*\\(\"($utils)[^[:space:]]*\"[^)]*,pid=$pid(,[^)]*)?\\)" && rc=0
13041315
elif [ $sockstat_available -ne 0 ]; then

scripts/wsrep_sst_rsync.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ check_pid_and_port()
105105
local final
106106

107107
if ! check_port $pid "$port" "$utils"; then
108-
if [ $ss_available -ne 0 -o $sockstat_available -ne 0 ]; then
108+
if [ $raw_socket_check -ne 0 ]; then
109+
return 1
110+
elif [ $ss_available -ne 0 -o $sockstat_available -ne 0 ]; then
109111
if [ $ss_available -ne 0 ]; then
110112
port_info=$($socket_utility $ss_opts -t "( sport = :$port )" 2>/dev/null | \
111113
grep -E '[[:space:]]users:[[:space:]]?\(' | \
@@ -163,7 +165,10 @@ check_pid_and_port()
163165
fi
164166
fi
165167

166-
check_pid "$pid_file" && [ $CHECK_PID -eq $pid ]
168+
if [ $raw_socket_check -ne 0 ]; then
169+
return 0
170+
fi
171+
check_pid "$pid_file" && [ "$CHECK_PID" -eq "$pid" ]
167172
}
168173

169174
get_binlog

0 commit comments

Comments
 (0)