From 4f092bee9fd818de4248f420388bf2d6eacea987 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sat, 9 Feb 2002 02:18:42 +0000 Subject: [PATCH] Make sure we call setgroups() after setuid(). (Ethan Benson) --- NEWS | 5 +++++ clientserver.c | 10 ++++++++++ configure.in | 2 +- log.c | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 8c54134c..0d1fc6a4 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ rsync 2.5.3 (not released yet) + SECURITY FIXES: + + * Make sure that supplementary groups are removed from a server + process after changing uid and gid. (Ethan Benson) + ENHANCEMENTS: * Command to initiate connections is only shown with -vv, rather diff --git a/clientserver.c b/clientserver.c index 87e79908..6f3edfa9 100644 --- a/clientserver.c +++ b/clientserver.c @@ -294,6 +294,16 @@ static int rsync_module(int fd, int i) return -1; } +#ifdef HAVE_SETGROUPS + /* Get rid of any supplementary groups this process + * might have inheristed. */ + if (setgroups(0, NULL)) { + rsyserr(FERROR, errno, "setgroups failed"); + io_printf(fd, "@ERROR: setgroups failed\n"); + return -1; + } +#endif + am_root = (getuid() == 0); } diff --git a/configure.in b/configure.in index 94565216..5eb0f777 100644 --- a/configure.in +++ b/configure.in @@ -351,7 +351,7 @@ AC_FUNC_UTIME_NULL AC_CHECK_FUNCS(waitpid wait4 getcwd strdup strerror chown chmod mknod) AC_CHECK_FUNCS(fchmod fstat strchr readlink link utime utimes strftime) AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf asprintf setsid glob strpbrk) -AC_CHECK_FUNCS(strlcat strlcpy mtrace mallinfo) +AC_CHECK_FUNCS(strlcat strlcpy mtrace mallinfo setgroups) AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[ AC_TRY_RUN([ diff --git a/log.c b/log.c index f07b64b1..532803f2 100644 --- a/log.c +++ b/log.c @@ -342,6 +342,8 @@ void rsyserr(enum logcode code, int errcode, const char *format, ...) len = vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); + /* TODO: Put in RSYNC_NAME at the start. */ + if ((size_t) len > sizeof(buf)-1) exit_cleanup(RERR_MESSAGEIO); -- 2.34.1