| Bug #21723 | Should be able to dump core after setuid() under Linux | ||
|---|---|---|---|
| Submitted: | 18 Aug 2006 18:37 | Modified: | 30 Sep 11:40 |
| Reporter: | Dean Ellis | ||
| Status: | Open | ||
| Category: | Server: General | Severity: | S4 (Feature request) |
| Version: | 5.0 | OS: | Linux (Linux) |
| Assigned to: | Target Version: | ||
| Tags: | Contribution, bfsm_2007_05_31 | ||
| Triage: | D5 (Feature request) | ||
[18 Aug 2006 22:38]
Domas Mituzas
This seems to be more a bug than feature request - --core-file functionality is broken if dumpable flag is not reset after setuid().
[5 Sep 2006 15:42]
Sergei Golubchik
I'd rather use HAVE_SYS_PRCTL_H or HAVE_PRCTL instead of __linux__
[5 Sep 2006 15:54]
Dean Ellis
Sure. Should probably also move this to the OPT_WANT_CORE test or to write_core() or similar (only do it if core-file option was specified).
[7 Sep 2006 11:20]
Michal Marek
The patch attached to bug#21361 contains a configure check and calls prctl() only of --core-file is given: http://bugs.mysql.com/file.php?id=4063
[1 Jun 2007 16:34]
Sergei Golubchik
no need for a special configure check, it's enough to add sys/prctl.h to
AC_CHECK_HEADERS() rule in configure.in. The code becomes:
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
...
+#ifdef PR_SET_DUMPABLE
+ if (test_flags & TEST_CORE_ON_SIGNAL)
+ {
+ prctl(PR_SET_DUMPABLE, 1);
+ }
+#endif
otherwise ok
[14 Jun 2007 20:25]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/28795 ChangeSet@1.2479, 2007-06-14 14:24:59-04:00, cmiller@zippy.cornsilk.net +2 -0 Bug#21723: Should be able to dump core after setuid() under Linux In many cases, binaries can no longer dump core after calling setuid(). Where the PR_SET_DUMPABLE macro is set, use the prctl() system call to tell the kernel that it's allowed to dump the core of the server.
[16 Jun 2007 6:50]
Bugs System
Pushed into 5.0.44
[16 Jun 2007 6:51]
Bugs System
Pushed into 5.1.20-beta
[18 Jun 2007 17:58]
Paul DuBois
Noted in 5.0.44, 5.1.20 changelogs. Linux binaries were unable to dump core after executing a setuid() call.
[30 Sep 11:34]
Yoshinori Matsunobu
Hi!
In 5.1, prctl() is called *before* setuid/setgid() so it doesn't work. Please fix.
----------
if ((user_info= check_user(mysqld_user)))
{
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT)
if (locked_in_memory) // getuid() == 0 here
set_effective_user(user_info);
else
#endif
set_user(mysqld_user, user_info);
}
----------
prctl() is called by check_user(), setuid()/setgid() are by set_user(), but prctl()
should be called after set_user().

Description: In many cases, binaries can no longer dump core after calling setuid(). Under Linux it is possible to re-enable this with a system call. How to repeat: n/a Suggested fix: ===== mysqld.cc 1.565 vs edited ===== --- 1.565/sql/mysqld.cc 2006-08-18 11:34:13 -05:00 +++ edited/mysqld.cc 2006-08-18 11:32:44 -05:00 @@ -64,6 +64,10 @@ #define ONE_THREAD #endif +#ifdef __linux__ +#include <sys/prctl.h> +#endif + #ifdef HAVE_purify #define IF_PURIFY(A,B) (A) #else @@ -1362,6 +1366,10 @@ sql_perror("setuid"); unireg_abort(1); } +#ifdef __linux__ + /* inform kernel that process is dumpable */ + prctl(PR_SET_DUMPABLE,1,0,0,0); +#endif /* __linux__ */ #endif }