Skip to content

Commit 8a1904d

Browse files
committedFeb 15, 2024
MDEV-33301 memlock with systemd still not working
CapabilityBoundingSet included CAP_IPC_LOCK in MDEV-9095, however it requires that the executable has the capability marked in extended attributes also. The alternate to this is raising the RLIMIT_MEMLOCK for the service/ process to be able to complete the mlockall system call. This needs to be adjusted to whatever the MariaDB server was going to allocate. Rather than leave the non-obvious mapping of settings and tuning, add the capability so its easier for the user. We set the capability, if possible, but may never be used depending on user settings. As such in the Debian postinst script, don't complain if this fails. The CAP_IPC_LOCK also facilitates the mmaping of huge memory pages. (see man mmap), like mariadb uses with --large-pages.
1 parent 0185ac6 commit 8a1904d

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed
 

‎cmake/cpack_rpm.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ SET(CPACK_RPM_server_USER_FILELIST
163163
${ignored}
164164
"%config(noreplace) ${INSTALL_SYSCONF2DIR}/*"
165165
"%config(noreplace) ${INSTALL_SYSCONFDIR}/logrotate.d/mysql"
166+
"%caps(cap_ipc_lock=pe) %{_sbindir}/mysqld"
166167
)
167168
SET(CPACK_RPM_common_USER_FILELIST ${ignored} "%config(noreplace) ${INSTALL_SYSCONFDIR}/my.cnf")
168169
SET(CPACK_RPM_shared_USER_FILELIST ${ignored} "%config(noreplace) ${INSTALL_SYSCONF2DIR}/*")
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# inspired by iputils-ping
6+
#
7+
# cap_ipc_lock is required if a user wants to use --memlock
8+
# and has insufficient RLIMIT_MEMLOCK (MDEV-33301)
9+
10+
PROGRAM=$(dpkg-divert --truename /usr/sbin/mysqld)
11+
12+
if [ "$1" = configure ]; then
13+
# If we have setcap installed, try setting
14+
# which allows us to install our binaries without the setuid
15+
# bit.
16+
if command -v setcap > /dev/null; then
17+
if ! setcap cap_ipc_lock+ep "$PROGRAM"; then
18+
echo "Setcap failed on $PROGRAM, required with --memlock if insufficent RLIMIT_MEMLOCK" >&2
19+
fi
20+
fi
21+
fi
22+
23+
24+
#DEBHELPER#
25+
26+
exit 0

‎support-files/policy/apparmor/usr.sbin.mysqld

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
capability chown,
1616
capability dac_override,
17+
capability ipc_lock,
1718
capability setgid,
1819
capability setuid,
1920
capability sys_rawio,

‎support-files/policy/selinux/mariadb-server.te

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require {
2525
class lnk_file read;
2626
class process { getattr signull };
2727
class unix_stream_socket connectto;
28-
class capability { sys_resource sys_nice };
28+
class capability { ipc_lock sys_resource sys_nice };
2929
class tcp_socket { name_bind name_connect };
3030
class file { execute setattr read create getattr execute_no_trans write ioctl open append unlink };
3131
class sock_file { create unlink getattr };
@@ -87,6 +87,8 @@ allow mysqld_t bin_t:file { getattr read execute open execute_no_trans ioctl };
8787

8888
# MariaDB additions
8989
allow mysqld_t self:process setpgid;
90+
allow mysqld_t self:capability { ipc_lock };
91+
9092
# This rule allows port tcp/4444
9193
allow mysqld_t kerberos_port_t:tcp_socket { name_bind name_connect };
9294
# This rule allows port tcp/4567 (tram_port_t may not be available on

0 commit comments

Comments
 (0)