Avoid using RLIM_INFINITY for the nofile soft limit to prevent

closefrom_fallback() from closing too many file descriptors.
This commit is contained in:
Todd C. Miller
2021-07-23 15:10:46 -06:00
parent b48cd11a4b
commit b0ae7a566b

View File

@@ -1,7 +1,7 @@
/* /*
* SPDX-License-Identifier: ISC * SPDX-License-Identifier: ISC
* *
* Copyright (c) 1999-2020 Todd C. Miller <Todd.Miller@sudo.ws> * Copyright (c) 1999-2021 Todd C. Miller <Todd.Miller@sudo.ws>
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@@ -35,6 +35,10 @@
#include "sudo.h" #include "sudo.h"
/*
* Avoid using RLIM_INFINITY for the nofile soft limit to prevent
* closefrom_fallback() from closing too many file descriptors.
*/
#if defined(OPEN_MAX) && OPEN_MAX > 256 #if defined(OPEN_MAX) && OPEN_MAX > 256
# define SUDO_OPEN_MAX OPEN_MAX # define SUDO_OPEN_MAX OPEN_MAX
#else #else
@@ -66,7 +70,6 @@
* the stack hard limit to be infinite. * the stack hard limit to be infinite.
* Linux containers have a problem with an infinite stack soft limit. * Linux containers have a problem with an infinite stack soft limit.
*/ */
static struct rlimit nofile_fallback = { SUDO_OPEN_MAX, RLIM_INFINITY };
static struct rlimit stack_fallback = { SUDO_STACK_MIN, 65532 * 1024 }; static struct rlimit stack_fallback = { SUDO_STACK_MIN, 65532 * 1024 };
static struct saved_limit { static struct saved_limit {
@@ -141,9 +144,9 @@ static struct saved_limit {
RLIMIT_NOFILE, RLIMIT_NOFILE,
true, /* override */ true, /* override */
false, /* saved */ false, /* saved */
RLIM_INFINITY, /* minlimit */ SUDO_OPEN_MAX, /* minlimit */
&nofile_fallback, NULL,
{ RLIM_INFINITY, RLIM_INFINITY } { SUDO_OPEN_MAX, RLIM_INFINITY }
}, },
#ifdef RLIMIT_NPROC #ifdef RLIMIT_NPROC
{ {