2012-10-23 14:51:33 +00:00
|
|
|
diff -up openssh-6.1p1/openbsd-compat/port-linux.c.privsep-selinux openssh-6.1p1/openbsd-compat/port-linux.c
|
2012-11-05 15:18:52 +00:00
|
|
|
--- openssh-6.1p1/openbsd-compat/port-linux.c.privsep-selinux 2012-11-05 14:46:39.334809203 +0100
|
|
|
|
+++ openssh-6.1p1/openbsd-compat/port-linux.c 2012-11-05 14:54:32.614504884 +0100
|
|
|
|
@@ -505,6 +505,25 @@ ssh_selinux_change_context(const char *n
|
2012-10-23 14:51:33 +00:00
|
|
|
xfree(newctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
+void
|
|
|
|
+ssh_selinux_copy_context(void)
|
|
|
|
+{
|
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) {
|
|
|
|
+ if (setcon(ctx) != 0)
|
|
|
|
+ logit("%s: setcon failed with %s", __func__, strerror (errno));
|
|
|
|
+ freecon(ctx);
|
|
|
|
+ }
|
2012-10-23 14:51:33 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
#endif /* WITH_SELINUX */
|
|
|
|
|
|
|
|
#ifdef LINUX_OOM_ADJUST
|
|
|
|
diff -up openssh-6.1p1/openbsd-compat/port-linux.h.privsep-selinux openssh-6.1p1/openbsd-compat/port-linux.h
|
|
|
|
--- openssh-6.1p1/openbsd-compat/port-linux.h.privsep-selinux 2011-01-25 02:16:18.000000000 +0100
|
2012-11-05 15:18:52 +00:00
|
|
|
+++ openssh-6.1p1/openbsd-compat/port-linux.h 2012-11-05 14:46:39.339809234 +0100
|
2012-10-23 14:51:33 +00:00
|
|
|
@@ -24,6 +24,7 @@ int ssh_selinux_enabled(void);
|
|
|
|
void ssh_selinux_setup_pty(char *, const char *);
|
|
|
|
void ssh_selinux_setup_exec_context(char *);
|
|
|
|
void ssh_selinux_change_context(const char *);
|
|
|
|
+void ssh_selinux_copy_context(void);
|
|
|
|
void ssh_selinux_setfscreatecon(const char *);
|
|
|
|
#endif
|
|
|
|
|
2012-09-15 10:26:36 +00:00
|
|
|
diff -up openssh-6.1p1/session.c.privsep-selinux openssh-6.1p1/session.c
|
2012-12-03 09:25:26 +00:00
|
|
|
--- openssh-6.1p1/session.c.privsep-selinux 2012-12-03 09:43:11.727505761 +0100
|
|
|
|
+++ openssh-6.1p1/session.c 2012-12-03 09:54:50.455688902 +0100
|
|
|
|
@@ -1519,6 +1519,9 @@ do_setusercontext(struct passwd *pw)
|
|
|
|
pw->pw_uid);
|
|
|
|
chroot_path = percent_expand(tmp, "h", pw->pw_dir,
|
|
|
|
"u", pw->pw_name, (char *)NULL);
|
|
|
|
+#ifdef WITH_SELINUX
|
|
|
|
+ ssh_selinux_copy_context();
|
|
|
|
+#endif
|
|
|
|
safely_chroot(chroot_path, pw->pw_uid);
|
|
|
|
free(tmp);
|
|
|
|
free(chroot_path);
|
|
|
|
@@ -1533,6 +1536,12 @@ do_setusercontext(struct passwd *pw)
|
|
|
|
/* Permanently switch to the desired uid. */
|
|
|
|
permanently_set_uid(pw);
|
|
|
|
#endif
|
2012-09-15 10:26:36 +00:00
|
|
|
+
|
|
|
|
+#ifdef WITH_SELINUX
|
2012-12-03 09:25:26 +00:00
|
|
|
+ if (options.chroot_directory == NULL ||
|
|
|
|
+ strcasecmp(options.chroot_directory, "none") == 0)
|
|
|
|
+ ssh_selinux_copy_context();
|
2012-09-15 10:26:36 +00:00
|
|
|
+#endif
|
2012-12-03 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
|
|
|
|
@@ -1787,9 +1796,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
|
|
|
}
|
|
|
|
|
|
|
|
diff -up openssh-6.1p1/sshd.c.privsep-selinux openssh-6.1p1/sshd.c
|
2013-02-24 15:36:18 +00:00
|
|
|
--- openssh-6.1p1/sshd.c.privsep-selinux 2013-02-24 11:29:32.997823377 +0100
|
|
|
|
+++ openssh-6.1p1/sshd.c 2013-02-24 11:43:34.171182720 +0100
|
|
|
|
@@ -653,6 +653,10 @@ privsep_preauth_child(void)
|
|
|
|
/* 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,
|
|
|
|
@@ -794,6 +798,13 @@ privsep_postauth(Authctxt *authctxt)
|
2012-09-15 10:26:36 +00:00
|
|
|
do_setusercontext(authctxt->pw);
|
|
|
|
|
|
|
|
skip:
|
|
|
|
+#ifdef WITH_SELINUX
|
|
|
|
+ /* switch SELinux content for root too */
|
|
|
|
+ if (authctxt->pw->pw_uid == 0) {
|
|
|
|
+ ssh_selinux_copy_context();
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* It is safe now to apply the key state */
|
|
|
|
monitor_apply_keystate(pmonitor);
|
|
|
|
|