Skip to content

Commit 96f6cc1

Browse files
committed
Add rlimit and prevent the process from forking
While it doesn't prevent all exploitations, it make like harder for a attacker who would want to spawn a shell or similar type of attack.
1 parent ae396da commit 96f6cc1

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
0.0.14 XXX
2+
Use prlimit on Linux to prevent tlsdate SSL code from forking again
13
0.0.13 Thu 28, May, 2015
24
Update default host to google.com - www.ptb.de randomized timestamps
35
0.0.12 Sun 26, Oct, 2014

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ AM_CONDITIONAL(HAVE_STRCHRNUL, [test "x${ac_cv_func_strchrnul}" = xyes])
183183
AC_CHECK_FUNCS([strnlen])
184184
AM_CONDITIONAL(HAVE_STRNLEN, [test "x${ac_cv_func_strnlen}" = xyes])
185185

186+
AC_CHECK_FUNCS([prlimit])
187+
AM_CONDITIONAL(HAVE_PRLIMIT, [test "x${ac_cv_func_prlmit}" = xyes])
188+
186189
AC_CHECK_FUNCS_ONCE(m4_flatten([
187190
gettimeofday
188191
prctl

src/tlsdate-helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,7 @@ main(int argc, char **argv)
13531353
if (0 == ssl_child)
13541354
{
13551355
drop_privs_to (UNPRIV_USER, UNPRIV_GROUP);
1356+
forbid_fork ();
13561357
run_ssl (time_map, leap, http);
13571358
(void) munmap (time_map, sizeof (uint32_t));
13581359
_exit (0);

src/util.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdio.h>
2121
#include <stdlib.h>
2222
#include <sys/ioctl.h>
23+
#include <sys/resource.h>
2324
#include <sys/stat.h>
2425
#include <sys/time.h>
2526
#include <sys/types.h>
@@ -149,6 +150,26 @@ void enable_seccomp(void)
149150
#endif
150151
}
151152

153+
/** Use prlimit to prevent a process from forking, thus making exploitation harder */
154+
void forbid_fork(void)
155+
{
156+
#ifdef TARGET_OS_LINUX
157+
#ifdef HAVE_PRLIMIT
158+
static const struct rlimit limit = {
159+
.rlim_cur = 0,
160+
.rlim_max = 0,
161+
};
162+
163+
if (-1 == prlimit(0, RLIMIT_NPROC, &limit, NULL))
164+
{
165+
die ("Failed to prlimit: %s\n", strerror (errno));
166+
}
167+
#else
168+
verb ("V: prlimit is not supported");
169+
#endif
170+
#endif
171+
}
172+
152173
void
153174
drop_privs_to (const char *user, const char *group)
154175
{

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static inline int min (int x, int y)
6565

6666
void drop_privs_to (const char *user, const char *group);
6767
void no_new_privs (void);
68+
void forbid_fork (void);
6869
const char *sync_type_str (int sync_type);
6970

7071
struct state;

0 commit comments

Comments
 (0)