2014-06-03 14:51:07 +00:00
|
|
|
diff --git a/openbsd-compat/port-linux-sshd.c b/openbsd-compat/port-linux-sshd.c
|
|
|
|
index c18524e..d04f4ed 100644
|
|
|
|
--- a/openbsd-compat/port-linux-sshd.c
|
|
|
|
+++ b/openbsd-compat/port-linux-sshd.c
|
2015-10-15 14:12:18 +00:00
|
|
|
@@ -409,6 +409,28 @@ sshd_selinux_setup_exec_context(char *pwname)
|
2014-06-03 14:51:07 +00:00
|
|
|
debug3("%s: done", __func__);
|
2012-10-23 14:51:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+void
|
2014-06-03 14:51:07 +00:00
|
|
|
+sshd_selinux_copy_context(void)
|
2012-10-23 14:51:33 +00:00
|
|
|
+{
|
2012-11-05 15:18:52 +00:00
|
|
|
+ security_context_t *ctx;
|
2012-10-23 14:51:33 +00:00
|
|
|
+
|
|
|
|
+ if (!ssh_selinux_enabled())
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ if (getexeccon((security_context_t *)&ctx) != 0) {
|
|
|
|
+ logit("%s: getcon failed with %s", __func__, strerror (errno));
|
|
|
|
+ return;
|
|
|
|
+ }
|
2012-11-05 15:18:52 +00:00
|
|
|
+ if (ctx != NULL) {
|
2015-10-15 14:12:18 +00:00
|
|
|
+ /* unset exec context before we will lose this capabililty */
|
|
|
|
+ if (setexeccon(NULL) != 0)
|
|
|
|
+ fatal("%s: setexeccon failed with %s", __func__, strerror (errno));
|
2012-11-05 15:18:52 +00:00
|
|
|
+ if (setcon(ctx) != 0)
|
2015-10-15 14:12:18 +00:00
|
|
|
+ fatal("%s: setcon failed with %s", __func__, strerror (errno));
|
2012-11-05 15:18:52 +00:00
|
|
|
+ freecon(ctx);
|
|
|
|
+ }
|
2012-10-23 14:51:33 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-06-03 14:51:07 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2012-10-23 14:51:33 +00:00
|
|
|
|
2014-06-03 14:51:07 +00:00
|
|
|
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
|
|
|
|
index 8ef6cc4..b18893c 100644
|
|
|
|
--- a/openbsd-compat/port-linux.h
|
|
|
|
+++ b/openbsd-compat/port-linux.h
|
|
|
|
@@ -25,6 +25,7 @@ void ssh_selinux_setup_pty(char *, const char *);
|
2012-10-23 14:51:33 +00:00
|
|
|
void ssh_selinux_change_context(const char *);
|
|
|
|
void ssh_selinux_setfscreatecon(const char *);
|
2014-06-03 14:51:07 +00:00
|
|
|
|
|
|
|
+void sshd_selinux_copy_context(void);
|
|
|
|
void sshd_selinux_setup_exec_context(char *);
|
2012-10-23 14:51:33 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-03 14:51:07 +00:00
|
|
|
diff --git a/session.c b/session.c
|
|
|
|
index 2bcf818..b5dc144 100644
|
|
|
|
--- a/session.c
|
|
|
|
+++ b/session.c
|
2015-10-15 14:12:18 +00:00
|
|
|
@@ -1532,7 +1532,7 @@ void
|
|
|
|
do_setusercontext(struct passwd *pw)
|
|
|
|
{
|
|
|
|
char *chroot_path, *tmp;
|
|
|
|
-#ifdef USE_LIBIAF
|
|
|
|
+#if defined(USE_LIBIAF) || defined(WITH_SELINUX)
|
|
|
|
int doing_chroot = 0;
|
|
|
|
#endif
|
|
|
|
|
2014-06-03 14:51:07 +00:00
|
|
|
@@ -1538,6 +1538,9 @@ do_setusercontext(struct passwd *pw)
|
2012-12-03 09:25:26 +00:00
|
|
|
pw->pw_uid);
|
|
|
|
chroot_path = percent_expand(tmp, "h", pw->pw_dir,
|
|
|
|
"u", pw->pw_name, (char *)NULL);
|
|
|
|
+#ifdef WITH_SELINUX
|
2014-06-03 14:51:07 +00:00
|
|
|
+ sshd_selinux_copy_context();
|
2012-12-03 09:25:26 +00:00
|
|
|
+#endif
|
|
|
|
safely_chroot(chroot_path, pw->pw_uid);
|
|
|
|
free(tmp);
|
|
|
|
free(chroot_path);
|
2015-10-15 14:12:18 +00:00
|
|
|
@@ -1557,7 +1557,7 @@ do_setusercontext(struct passwd *pw)
|
|
|
|
/* Make sure we don't attempt to chroot again */
|
|
|
|
free(options.chroot_directory);
|
|
|
|
options.chroot_directory = NULL;
|
|
|
|
-#ifdef USE_LIBIAF
|
|
|
|
+#if defined(USE_LIBIAF) || defined(WITH_SELINUX)
|
|
|
|
doing_chroot = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
@@ -1565,6 +1568,11 @@ do_setusercontext(struct passwd *pw)
|
2012-12-03 09:25:26 +00:00
|
|
|
/* Permanently switch to the desired uid. */
|
|
|
|
permanently_set_uid(pw);
|
|
|
|
#endif
|
2012-09-15 10:26:36 +00:00
|
|
|
+
|
|
|
|
+#ifdef WITH_SELINUX
|
2015-10-15 14:12:18 +00:00
|
|
|
+ if (doing_chroot == 0)
|
2014-06-03 14:51:07 +00:00
|
|
|
+ sshd_selinux_copy_context();
|
2012-09-15 10:26:36 +00:00
|
|
|
+#endif
|
2013-10-14 13:54:41 +00:00
|
|
|
} else if (options.chroot_directory != NULL &&
|
|
|
|
strcasecmp(options.chroot_directory, "none") != 0) {
|
|
|
|
fatal("server lacks privileges to chroot to ChrootDirectory");
|
2015-10-15 14:12:18 +00:00
|
|
|
@@ -1588,9 +1588,6 @@ do_pwchange(Session *s)
|
|
|
|
if (s->ttyfd != -1) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"You must change your password now and login again!\n");
|
|
|
|
-#ifdef WITH_SELINUX
|
|
|
|
- setexeccon(NULL);
|
|
|
|
-#endif
|
|
|
|
#ifdef PASSWD_NEEDS_USERNAME
|
|
|
|
execl(_PATH_PASSWD_PROG, "passwd", s->pw->pw_name,
|
|
|
|
(char *)NULL);
|
2014-06-03 14:51:07 +00:00
|
|
|
@@ -1826,9 +1835,6 @@ do_child(Session *s, const char *command)
|
2012-10-23 14:51:33 +00:00
|
|
|
argv[i] = NULL;
|
|
|
|
optind = optreset = 1;
|
|
|
|
__progname = argv[0];
|
|
|
|
-#ifdef WITH_SELINUX
|
|
|
|
- ssh_selinux_change_context("sftpd_t");
|
|
|
|
-#endif
|
|
|
|
exit(sftp_server_main(i, argv, s->pw));
|
2012-09-15 10:26:36 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 14:51:07 +00:00
|
|
|
diff --git a/sshd.c b/sshd.c
|
|
|
|
index 07f9926..a97f8b7 100644
|
|
|
|
--- a/sshd.c
|
|
|
|
+++ b/sshd.c
|
|
|
|
@@ -632,6 +632,10 @@ privsep_preauth_child(void)
|
2013-02-24 15:36:18 +00:00
|
|
|
/* Demote the private keys to public keys. */
|
|
|
|
demote_sensitive_data();
|
|
|
|
|
|
|
|
+#ifdef WITH_SELINUX
|
|
|
|
+ ssh_selinux_change_context("sshd_net_t");
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Change our root directory */
|
|
|
|
if (chroot(_PATH_PRIVSEP_CHROOT_DIR) == -1)
|
|
|
|
fatal("chroot(\"%s\"): %s", _PATH_PRIVSEP_CHROOT_DIR,
|
2015-10-16 07:41:20 +00:00
|
|
|
@@ -755,6 +755,9 @@ privsep_postauth(Authctxt *authctxt)
|
2012-09-15 10:26:36 +00:00
|
|
|
|
2015-10-16 07:41:20 +00:00
|
|
|
#ifdef DISABLE_FD_PASSING
|
|
|
|
if (1) {
|
|
|
|
+#elif defined(WITH_SELINUX)
|
|
|
|
+ if (options.use_login) {
|
|
|
|
+ /* even root user can be confined by SELinux */
|
|
|
|
#else
|
|
|
|
if (authctxt->pw->pw_uid == 0 || options.use_login) {
|
|
|
|
#endif
|