|
Jakub Jelen |
6cf9b8 |
diff -up openssh-7.4p1/openbsd-compat/port-linux.h.privsep-selinux openssh-7.4p1/openbsd-compat/port-linux.h
|
|
Jakub Jelen |
6cf9b8 |
--- openssh-7.4p1/openbsd-compat/port-linux.h.privsep-selinux 2016-12-23 18:58:52.972122201 +0100
|
|
Jakub Jelen |
6cf9b8 |
+++ openssh-7.4p1/openbsd-compat/port-linux.h 2016-12-23 18:58:52.974122201 +0100
|
|
Jakub Jelen |
6cf9b8 |
@@ -23,6 +23,7 @@ void ssh_selinux_setup_pty(char *, const
|
|
Jakub Jelen |
6cf9b8 |
void ssh_selinux_change_context(const char *);
|
|
Jakub Jelen |
6cf9b8 |
void ssh_selinux_setfscreatecon(const char *);
|
|
Jakub Jelen |
6cf9b8 |
|
|
Jakub Jelen |
6cf9b8 |
+void sshd_selinux_copy_context(void);
|
|
Jakub Jelen |
6cf9b8 |
void sshd_selinux_setup_exec_context(char *);
|
|
Jakub Jelen |
6cf9b8 |
#endif
|
|
Jakub Jelen |
6cf9b8 |
|
|
Jakub Jelen |
6cf9b8 |
diff -up openssh-7.4p1/openbsd-compat/port-linux-sshd.c.privsep-selinux openssh-7.4p1/openbsd-compat/port-linux-sshd.c
|
|
Jakub Jelen |
6cf9b8 |
--- openssh-7.4p1/openbsd-compat/port-linux-sshd.c.privsep-selinux 2016-12-23 18:58:52.973122201 +0100
|
|
Jakub Jelen |
6cf9b8 |
+++ openssh-7.4p1/openbsd-compat/port-linux-sshd.c 2016-12-23 18:58:52.974122201 +0100
|
|
Jakub Jelen |
6cf9b8 |
@@ -419,6 +419,28 @@ sshd_selinux_setup_exec_context(char *pw
|
|
Petr Lautrbach |
94c6f8 |
debug3("%s: done", __func__);
|
|
Petr Lautrbach |
afd52c |
}
|
|
Petr Lautrbach |
afd52c |
|
|
Petr Lautrbach |
afd52c |
+void
|
|
Petr Lautrbach |
94c6f8 |
+sshd_selinux_copy_context(void)
|
|
Petr Lautrbach |
afd52c |
+{
|
|
bach |
dfa0cd |
+ security_context_t *ctx;
|
|
Petr Lautrbach |
afd52c |
+
|
|
Petr Lautrbach |
afd52c |
+ if (!ssh_selinux_enabled())
|
|
Petr Lautrbach |
afd52c |
+ return;
|
|
Petr Lautrbach |
afd52c |
+
|
|
Petr Lautrbach |
afd52c |
+ if (getexeccon((security_context_t *)&ctx) != 0) {
|
|
Petr Lautrbach |
afd52c |
+ logit("%s: getcon failed with %s", __func__, strerror (errno));
|
|
Petr Lautrbach |
afd52c |
+ return;
|
|
Petr Lautrbach |
afd52c |
+ }
|
|
bach |
dfa0cd |
+ if (ctx != NULL) {
|
|
Jakub Jelen |
22a08c |
+ /* unset exec context before we will lose this capabililty */
|
|
Jakub Jelen |
22a08c |
+ if (setexeccon(NULL) != 0)
|
|
Jakub Jelen |
22a08c |
+ fatal("%s: setexeccon failed with %s", __func__, strerror (errno));
|
|
bach |
dfa0cd |
+ if (setcon(ctx) != 0)
|
|
Jakub Jelen |
22a08c |
+ fatal("%s: setcon failed with %s", __func__, strerror (errno));
|
|
bach |
dfa0cd |
+ freecon(ctx);
|
|
bach |
dfa0cd |
+ }
|
|
Petr Lautrbach |
afd52c |
+}
|
|
Petr Lautrbach |
afd52c |
+
|
|
Petr Lautrbach |
94c6f8 |
#endif
|
|
Petr Lautrbach |
94c6f8 |
#endif
|
|
Petr Lautrbach |
afd52c |
|
|
Jakub Jelen |
6cf9b8 |
diff -up openssh-7.4p1/session.c.privsep-selinux openssh-7.4p1/session.c
|
|
Jakub Jelen |
6cf9b8 |
--- openssh-7.4p1/session.c.privsep-selinux 2016-12-19 05:59:41.000000000 +0100
|
|
Jakub Jelen |
6cf9b8 |
+++ openssh-7.4p1/session.c 2016-12-23 18:58:52.974122201 +0100
|
|
Jakub Jelen |
6cf9b8 |
@@ -1331,7 +1331,7 @@ do_setusercontext(struct passwd *pw)
|
|
Petr Lautrbach |
94c6f8 |
|
|
Jakub Jelen |
6cf9b8 |
platform_setusercontext(pw);
|
|
Petr Lautrbach |
afd52c |
|
|
Jakub Jelen |
6cf9b8 |
- if (platform_privileged_uidswap()) {
|
|
Jakub Jelen |
6cf9b8 |
+ if (platform_privileged_uidswap() && (!is_child || !use_privsep)) {
|
|
Jakub Jelen |
6cf9b8 |
#ifdef HAVE_LOGIN_CAP
|
|
Jakub Jelen |
6cf9b8 |
if (setusercontext(lc, pw, pw->pw_uid,
|
|
Jakub Jelen |
6cf9b8 |
(LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETUSER))) < 0) {
|
|
Jakub Jelen |
6cf9b8 |
@@ -1361,6 +1361,9 @@ do_setusercontext(struct passwd *pw)
|
|
Petr Lautrbach |
f578f0 |
pw->pw_uid);
|
|
Petr Lautrbach |
f578f0 |
chroot_path = percent_expand(tmp, "h", pw->pw_dir,
|
|
Petr Lautrbach |
f578f0 |
"u", pw->pw_name, (char *)NULL);
|
|
Petr Lautrbach |
f578f0 |
+#ifdef WITH_SELINUX
|
|
Petr Lautrbach |
94c6f8 |
+ sshd_selinux_copy_context();
|
|
Petr Lautrbach |
f578f0 |
+#endif
|
|
Petr Lautrbach |
f578f0 |
safely_chroot(chroot_path, pw->pw_uid);
|
|
Petr Lautrbach |
f578f0 |
free(tmp);
|
|
Petr Lautrbach |
f578f0 |
free(chroot_path);
|
|
Jakub Jelen |
6cf9b8 |
@@ -1396,6 +1399,11 @@ do_setusercontext(struct passwd *pw)
|
|
Petr Lautrbach |
f578f0 |
/* Permanently switch to the desired uid. */
|
|
Petr Lautrbach |
f578f0 |
permanently_set_uid(pw);
|
|
Petr Lautrbach |
f578f0 |
#endif
|
|
Petr Lautrbach |
581bf3 |
+
|
|
Petr Lautrbach |
0c438f |
+#ifdef WITH_SELINUX
|
|
Jakub Jelen |
13073f |
+ if (in_chroot == 0)
|
|
Petr Lautrbach |
94c6f8 |
+ sshd_selinux_copy_context();
|
|
Petr Lautrbach |
0c438f |
+#endif
|
|
Petr Lautrbach |
84822b |
} else if (options.chroot_directory != NULL &&
|
|
Petr Lautrbach |
84822b |
strcasecmp(options.chroot_directory, "none") != 0) {
|
|
Petr Lautrbach |
84822b |
fatal("server lacks privileges to chroot to ChrootDirectory");
|
|
Jakub Jelen |
6cf9b8 |
@@ -1413,9 +1421,6 @@ do_pwchange(Session *s)
|
|
Jakub Jelen |
22a08c |
if (s->ttyfd != -1) {
|
|
Jakub Jelen |
22a08c |
fprintf(stderr,
|
|
Jakub Jelen |
22a08c |
"You must change your password now and login again!\n");
|
|
Jakub Jelen |
22a08c |
-#ifdef WITH_SELINUX
|
|
Jakub Jelen |
22a08c |
- setexeccon(NULL);
|
|
Jakub Jelen |
22a08c |
-#endif
|
|
Jakub Jelen |
22a08c |
#ifdef PASSWD_NEEDS_USERNAME
|
|
Jakub Jelen |
22a08c |
execl(_PATH_PASSWD_PROG, "passwd", s->pw->pw_name,
|
|
Jakub Jelen |
22a08c |
(char *)NULL);
|
|
Jakub Jelen |
6cf9b8 |
@@ -1625,9 +1630,6 @@ do_child(Session *s, const char *command
|
|
Petr Lautrbach |
afd52c |
argv[i] = NULL;
|
|
Petr Lautrbach |
afd52c |
optind = optreset = 1;
|
|
Petr Lautrbach |
afd52c |
__progname = argv[0];
|
|
Petr Lautrbach |
afd52c |
-#ifdef WITH_SELINUX
|
|
Petr Lautrbach |
afd52c |
- ssh_selinux_change_context("sftpd_t");
|
|
Petr Lautrbach |
afd52c |
-#endif
|
|
Petr Lautrbach |
afd52c |
exit(sftp_server_main(i, argv, s->pw));
|
|
Petr Lautrbach |
cd5891 |
}
|
|
Petr Lautrbach |
cd5891 |
|
|
Jakub Jelen |
6cf9b8 |
diff -up openssh-7.4p1/sshd.c.privsep-selinux openssh-7.4p1/sshd.c
|
|
Jakub Jelen |
6cf9b8 |
--- openssh-7.4p1/sshd.c.privsep-selinux 2016-12-23 18:58:52.973122201 +0100
|
|
Jakub Jelen |
6cf9b8 |
+++ openssh-7.4p1/sshd.c 2016-12-23 18:59:13.808124269 +0100
|
|
Jakub Jelen |
6cf9b8 |
@@ -540,6 +540,10 @@ privsep_preauth_child(void)
|
|
Petr Lautrbach |
338e71 |
/* Demote the private keys to public keys. */
|
|
Petr Lautrbach |
338e71 |
demote_sensitive_data();
|
|
Petr Lautrbach |
338e71 |
|
|
Petr Lautrbach |
338e71 |
+#ifdef WITH_SELINUX
|
|
Petr Lautrbach |
338e71 |
+ ssh_selinux_change_context("sshd_net_t");
|
|
Petr Lautrbach |
338e71 |
+#endif
|
|
Petr Lautrbach |
338e71 |
+
|
|
Jakub Jelen |
13073f |
/* Demote the child */
|
|
Jakub Jelen |
5b55d0 |
if (privsep_chroot) {
|
|
Jakub Jelen |
13073f |
/* Change our root directory */
|
|
Jakub Jelen |
6cf9b8 |
@@ -633,6 +637,9 @@ privsep_postauth(Authctxt *authctxt)
|
|
Jakub Jelen |
6cf9b8 |
{
|
|
Jakub Jelen |
0ebe96 |
#ifdef DISABLE_FD_PASSING
|
|
Jakub Jelen |
0ebe96 |
if (1) {
|
|
Jakub Jelen |
0ebe96 |
+#elif defined(WITH_SELINUX)
|
|
Jakub Jelen |
6cf9b8 |
+ if (0) {
|
|
Jakub Jelen |
0ebe96 |
+ /* even root user can be confined by SELinux */
|
|
Jakub Jelen |
0ebe96 |
#else
|
|
Jakub Jelen |
6cf9b8 |
if (authctxt->pw->pw_uid == 0) {
|
|
Jakub Jelen |
0ebe96 |
#endif
|