privsep patch, Please test (take 3)
Tim Rice
tim at multitalents.net
Thu Jun 6 11:22:39 EST 2002
Here is the version I'll commit to CVS if there are no objections.
--
Tim Rice Multitalents (707) 887-1469
tim at multitalents.net
-------------- next part --------------
--- openssh/acconfig.h.old Sun May 12 20:25:01 2002
+++ openssh/acconfig.h Mon Jun 3 19:53:46 2002
@@ -355,6 +355,18 @@
/* Path that unprivileged child will chroot() to in privep mode */
#undef PRIVSEP_PATH
+/* Define if you have the `mmap' function that supports MAP_ANON|SHARED */
+#undef HAVE_MMAP_ANON_SHARED
+
+/* Define if you have the `mmap' function that supports MAP_ANON|PRIVATE */
+#undef HAVE_MMAP_ANON_PRIVATE
+
+/* Define if you have the `mmap' function that supports /dev/zero SHARED */
+#undef HAVE_MMAP_DEV_ZERO_SHARED
+
+/* Define if you have the `mmap' function that supports /dev/zero PRIVATE */
+#undef HAVE_MMAP_DEV_ZERO_PRIVATE
+
@BOTTOM@
/* ******************* Shouldn't need to edit below this line ************** */
--- openssh/configure.ac.old Mon May 27 17:37:33 2002
+++ openssh/configure.ac Mon Jun 3 21:07:29 2002
@@ -576,6 +576,92 @@
strlcat strlcpy strmode strsep sysconf tcgetpgrp truncate utimes \
vhangup vsnprintf waitpid __b64_ntop _getpty)
+if test $ac_cv_func_mmap = yes ; then
+AC_MSG_CHECKING([for mmap anon shared])
+AC_TRY_RUN(
+ [
+#include <stdio.h>
+#include <sys/mman.h>
+#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
+#define MAP_ANON MAP_ANONYMOUS
+#endif
+main() { char *p;
+p = (char *) mmap(NULL, 10, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, -1, 0);
+if (p == (char *)-1)
+ exit(1);
+exit(0);
+}
+ ],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_MMAP_ANON_SHARED)
+ ],
+ [ AC_MSG_RESULT(no) ]
+)
+AC_MSG_CHECKING([for mmap anon private])
+AC_TRY_RUN(
+ [
+#include <stdio.h>
+#include <sys/mman.h>
+#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
+#define MAP_ANON MAP_ANONYMOUS
+#endif
+main() { char *p;
+p = (char *) mmap(NULL, 10, PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0);
+if (p == (char *)-1)
+ exit(1);
+exit(0);
+}
+ ],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_MMAP_ANON_PRIVATE)
+ ],
+ [ AC_MSG_RESULT(no) ]
+)
+AC_MSG_CHECKING([for mmap /dev/zero shared])
+AC_TRY_RUN(
+ [
+#include <stdio.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+main() { char *p = (char *) mmap(NULL, 10, PROT_WRITE|PROT_READ, MAP_SHARED,
+ open("/dev/zero", O_RDWR), 0);
+if (p == (char *)-1)
+ exit(1);
+exit(0);
+}
+ ],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_MMAP_DEV_ZERO_SHARED)
+ ],
+ [ AC_MSG_RESULT(no) ]
+)
+AC_MSG_CHECKING([for mmap /dev/zero private])
+AC_TRY_RUN(
+ [
+#include <stdio.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#ifndef MAP_FAILED
+# define MAP_FAILED ((void *)-1)
+#endif
+main() { char *p = (char *) mmap(NULL, 10, PROT_WRITE|PROT_READ, MAP_PRIVATE,
+ open("/dev/zero", O_RDWR), 0);
+if (p == (char *)-1)
+ exit(1);
+exit(0);
+}
+ ],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_MMAP_DEV_ZERO_PRIVATE)
+ ],
+ [ AC_MSG_RESULT(no) ]
+)
+fi
+
dnl IRIX and Solaris 2.5.1 have dirname() in libgen
AC_CHECK_FUNCS(dirname, [AC_CHECK_HEADERS(libgen.h)] ,[
AC_CHECK_LIB(gen, dirname,[
--- openssh/monitor_mm.c.old Fri Apr 12 17:49:51 2002
+++ openssh/monitor_mm.c Mon Jun 3 19:59:54 2002
@@ -84,9 +84,20 @@
*/
mm->mmalloc = mmalloc;
-#if defined(HAVE_MMAP) && defined(MAP_ANON)
+#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_ANON_SHARED
address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED,
-1, 0);
+#elif defined(HAVE_MMAP_DEV_ZERO_SHARED)
+ address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED,
+ open("/dev/zero", O_RDWR), 0);
+#elif defined(HAVE_MMAP_ANON_PRIVATE)
+ address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE,
+ -1, 0);
+#elif defined(HAVE_MMAP_DEV_ZERO_PRIVATE)
+ address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_PRIVATE,
+ open("/dev/zero", O_RDWR), 0);
+#endif
if (address == MAP_FAILED)
fatal("mmap(%lu)", (u_long)size);
#else
--- openssh/session.c.old Sun May 12 20:25:02 2002
+++ openssh/session.c Wed May 29 07:39:22 2002
@@ -1089,10 +1089,11 @@
exit(1);
}
/* Initialize the group list. */
- if (initgroups(pw->pw_name, pw->pw_gid) < 0) {
- perror("initgroups");
- exit(1);
- }
+ if (strcmp(pw->pw_name, SSH_PRIVSEP_USER))
+ if (initgroups(pw->pw_name, pw->pw_gid) < 0) {
+ perror("initgroups");
+ exit(1);
+ }
endgrent();
# ifdef USE_PAM
/*
More information about the openssh-unix-dev
mailing list