Skip to content

Commit

Permalink
Ignore '--dumpable' argument in 'krb5_child' and 'ldap_child' to avoi…
Browse files Browse the repository at this point in the history
…d leaking host keytab accidentially.

Take a note that this is rather a general precaution than a fix
of a real threat since normally those coredumps wouldn't be
accessible to non-privileged user anyway.

Reviewed-by: Pavel Březina <[email protected]>
Reviewed-by: Sumit Bose <[email protected]>
(cherry picked from commit 548fdb3)
  • Loading branch information
alexey-tikhonov committed Dec 10, 2024
1 parent 1614c5e commit 3c0c33d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/providers/krb5/krb5_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -4094,7 +4094,7 @@ int main(int argc, const char *argv[])
uint32_t offline;
int opt;
poptContext pc;
int dumpable = 1;
int dummy = 1;
int backtrace = 1;
int debug_fd = -1;
const char *opt_logger = NULL;
Expand All @@ -4109,8 +4109,8 @@ int main(int argc, const char *argv[])
struct poptOption long_options[] = {
POPT_AUTOHELP
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"dumpable", 0, POPT_ARG_INT, &dummy, 0,
_("Ignored, /proc/sys/fs/suid_dumpable setting is in force"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
Expand Down Expand Up @@ -4175,11 +4175,11 @@ int main(int argc, const char *argv[])

poptFreeContext(pc);

/* This call is more for the sake of consistency than
* anything else. Any change of euid will reset DUMPABLE
* to the value of '/proc/sys/fs/suid_dumpable'
/* Don't touch PR_SET_DUMPABLE as 'krb5_child' handles host keytab.
* Rely on system settings instead: this flag "is reset to the
* current value contained in the file /proc/sys/fs/suid_dumpable"
* when "the process executes a program that has file capabilities".
*/
prctl(PR_SET_DUMPABLE, (dumpable == 0) ? 0 : 1);

debug_prg_name = talloc_asprintf(NULL, "krb5_child[%d]", getpid());
if (!debug_prg_name) {
Expand Down
12 changes: 8 additions & 4 deletions src/providers/ldap/ldap_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ int main(int argc, const char *argv[])
{
int ret;
int opt;
int dumpable = 1;
int dummy = 1;
int backtrace = 1;
int debug_fd = -1;
const char *opt_logger = NULL;
Expand All @@ -991,8 +991,8 @@ int main(int argc, const char *argv[])
struct poptOption long_options[] = {
POPT_AUTOHELP
SSSD_DEBUG_OPTS
{"dumpable", 0, POPT_ARG_INT, &dumpable, 0,
_("Allow core dumps"), NULL },
{"dumpable", 0, POPT_ARG_INT, &dummy, 0,
_("Ignored, /proc/sys/fs/suid_dumpable setting is in force"), NULL },
{"backtrace", 0, POPT_ARG_INT, &backtrace, 0,
_("Enable debug backtrace"), NULL },
{"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0,
Expand All @@ -1017,7 +1017,11 @@ int main(int argc, const char *argv[])

poptFreeContext(pc);

prctl(PR_SET_DUMPABLE, (dumpable == 0) ? 0 : 1);
/* Don't touch PR_SET_DUMPABLE as 'ldap_child' handles host keytab.
* Rely on system settings instead: this flag "is reset to the
* current value contained in the file /proc/sys/fs/suid_dumpable"
* when "the process executes a program that has file capabilities".
*/

debug_prg_name = talloc_asprintf(NULL, "ldap_child[%d]", getpid());
if (!debug_prg_name) {
Expand Down
4 changes: 4 additions & 0 deletions src/util/child_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,10 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx,
goto fail;
}

/* Some helpers, namely 'krb5_child' and 'ldap_child',
* will ignore '--dumpable' argument to avoid leaking
* host keytab accidentially.
*/
argv[--argc] = talloc_asprintf(argv, "--dumpable=%d",
prctl(PR_GET_DUMPABLE));
if (argv[argc] == NULL) {
Expand Down

0 comments on commit 3c0c33d

Please sign in to comment.