|
|
f09e2e |
diff -up openssh-6.3p1/openbsd-compat/port-linux.c.privsep-selinux openssh-6.3p1/openbsd-compat/port-linux.c
|
|
|
f09e2e |
--- openssh-6.3p1/openbsd-compat/port-linux.c.privsep-selinux 2013-10-10 14:58:20.634762245 +0200
|
|
|
f09e2e |
+++ openssh-6.3p1/openbsd-compat/port-linux.c 2013-10-10 15:13:57.864306950 +0200
|
|
|
f09e2e |
@@ -503,6 +503,25 @@ ssh_selinux_change_context(const char *n
|
|
|
f09e2e |
free(newctx);
|
|
|
f09e2e |
}
|
|
|
f09e2e |
|
|
|
f09e2e |
+void
|
|
|
f09e2e |
+ssh_selinux_copy_context(void)
|
|
|
f09e2e |
+{
|
|
|
f09e2e |
+ security_context_t *ctx;
|
|
|
f09e2e |
+
|
|
|
f09e2e |
+ if (!ssh_selinux_enabled())
|
|
|
f09e2e |
+ return;
|
|
|
f09e2e |
+
|
|
|
f09e2e |
+ if (getexeccon((security_context_t *)&ctx) != 0) {
|
|
|
f09e2e |
+ logit("%s: getcon failed with %s", __func__, strerror (errno));
|
|
|
f09e2e |
+ return;
|
|
|
f09e2e |
+ }
|
|
|
f09e2e |
+ if (ctx != NULL) {
|
|
|
f09e2e |
+ if (setcon(ctx) != 0)
|
|
|
f09e2e |
+ logit("%s: setcon failed with %s", __func__, strerror (errno));
|
|
|
f09e2e |
+ freecon(ctx);
|
|
|
f09e2e |
+ }
|
|
|
f09e2e |
+}
|
|
|
f09e2e |
+
|
|
|
f09e2e |
#endif /* WITH_SELINUX */
|
|
|
f09e2e |
|
|
|
f09e2e |
#ifdef LINUX_OOM_ADJUST
|
|
|
f09e2e |
diff -up openssh-6.3p1/openbsd-compat/port-linux.h.privsep-selinux openssh-6.3p1/openbsd-compat/port-linux.h
|
|
|
f09e2e |
--- openssh-6.3p1/openbsd-compat/port-linux.h.privsep-selinux 2011-01-25 02:16:18.000000000 +0100
|
|
|
f09e2e |
+++ openssh-6.3p1/openbsd-compat/port-linux.h 2013-10-10 14:58:20.634762245 +0200
|
|
|
f09e2e |
@@ -24,6 +24,7 @@ int ssh_selinux_enabled(void);
|
|
|
f09e2e |
void ssh_selinux_setup_pty(char *, const char *);
|
|
|
f09e2e |
void ssh_selinux_setup_exec_context(char *);
|
|
|
f09e2e |
void ssh_selinux_change_context(const char *);
|
|
|
f09e2e |
+void ssh_selinux_copy_context(void);
|
|
|
f09e2e |
void ssh_selinux_setfscreatecon(const char *);
|
|
|
f09e2e |
#endif
|
|
|
f09e2e |
|
|
|
f09e2e |
diff -up openssh-6.3p1/session.c.privsep-selinux openssh-6.3p1/session.c
|
|
|
f09e2e |
--- openssh-6.3p1/session.c.privsep-selinux 2013-10-10 14:58:20.617762326 +0200
|
|
|
f09e2e |
+++ openssh-6.3p1/session.c 2013-10-10 15:13:16.520503590 +0200
|
|
|
f09e2e |
@@ -1522,6 +1522,9 @@ do_setusercontext(struct passwd *pw)
|
|
|
f09e2e |
pw->pw_uid);
|
|
|
f09e2e |
chroot_path = percent_expand(tmp, "h", pw->pw_dir,
|
|
|
f09e2e |
"u", pw->pw_name, (char *)NULL);
|
|
|
f09e2e |
+#ifdef WITH_SELINUX
|
|
|
f09e2e |
+ ssh_selinux_copy_context();
|
|
|
f09e2e |
+#endif
|
|
|
f09e2e |
safely_chroot(chroot_path, pw->pw_uid);
|
|
|
f09e2e |
free(tmp);
|
|
|
f09e2e |
free(chroot_path);
|
|
|
f09e2e |
@@ -1544,6 +1547,12 @@ do_setusercontext(struct passwd *pw)
|
|
|
f09e2e |
/* Permanently switch to the desired uid. */
|
|
|
f09e2e |
permanently_set_uid(pw);
|
|
|
f09e2e |
#endif
|
|
|
f09e2e |
+
|
|
|
f09e2e |
+#ifdef WITH_SELINUX
|
|
|
f09e2e |
+ if (options.chroot_directory == NULL ||
|
|
|
f09e2e |
+ strcasecmp(options.chroot_directory, "none") == 0)
|
|
|
f09e2e |
+ ssh_selinux_copy_context();
|
|
|
f09e2e |
+#endif
|
|
|
f09e2e |
} else if (options.chroot_directory != NULL &&
|
|
|
f09e2e |
strcasecmp(options.chroot_directory, "none") != 0) {
|
|
|
f09e2e |
fatal("server lacks privileges to chroot to ChrootDirectory");
|
|
|
f09e2e |
@@ -1808,9 +1817,6 @@ do_child(Session *s, const char *command
|
|
|
f09e2e |
argv[i] = NULL;
|
|
|
f09e2e |
optind = optreset = 1;
|
|
|
f09e2e |
__progname = argv[0];
|
|
|
f09e2e |
-#ifdef WITH_SELINUX
|
|
|
f09e2e |
- ssh_selinux_change_context("sftpd_t");
|
|
|
f09e2e |
-#endif
|
|
|
f09e2e |
exit(sftp_server_main(i, argv, s->pw));
|
|
|
f09e2e |
}
|
|
|
f09e2e |
|
|
|
f09e2e |
diff -up openssh-6.3p1/sshd.c.privsep-selinux openssh-6.3p1/sshd.c
|
|
|
f09e2e |
--- openssh-6.3p1/sshd.c.privsep-selinux 2013-10-10 14:58:20.632762255 +0200
|
|
|
f09e2e |
+++ openssh-6.3p1/sshd.c 2013-10-10 14:58:20.635762241 +0200
|
|
|
f09e2e |
@@ -668,6 +668,10 @@ privsep_preauth_child(void)
|
|
|
f09e2e |
/* Demote the private keys to public keys. */
|
|
|
f09e2e |
demote_sensitive_data();
|
|
|
f09e2e |
|
|
|
f09e2e |
+#ifdef WITH_SELINUX
|
|
|
f09e2e |
+ ssh_selinux_change_context("sshd_net_t");
|
|
|
f09e2e |
+#endif
|
|
|
f09e2e |
+
|
|
|
f09e2e |
/* Change our root directory */
|
|
|
f09e2e |
if (chroot(_PATH_PRIVSEP_CHROOT_DIR) == -1)
|
|
|
f09e2e |
fatal("chroot(\"%s\"): %s", _PATH_PRIVSEP_CHROOT_DIR,
|
|
|
f09e2e |
@@ -811,6 +815,13 @@ privsep_postauth(Authctxt *authctxt)
|
|
|
f09e2e |
do_setusercontext(authctxt->pw);
|
|
|
f09e2e |
|
|
|
f09e2e |
skip:
|
|
|
f09e2e |
+#ifdef WITH_SELINUX
|
|
|
f09e2e |
+ /* switch SELinux content for root too */
|
|
|
f09e2e |
+ if (authctxt->pw->pw_uid == 0) {
|
|
|
f09e2e |
+ ssh_selinux_copy_context();
|
|
|
f09e2e |
+ }
|
|
|
f09e2e |
+#endif
|
|
|
f09e2e |
+
|
|
|
f09e2e |
/* It is safe now to apply the key state */
|
|
|
f09e2e |
monitor_apply_keystate(pmonitor);
|
|
|
f09e2e |
|