kentpeacock / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
3e8b5b
diff -up openssh/auth2.c.role-mls openssh/auth2.c
3e8b5b
--- openssh/auth2.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/auth2.c	2018-08-22 11:14:56.815430916 +0200
3e8b5b
@@ -256,6 +256,9 @@ input_userauth_request(int type, u_int32
3e8b5b
 	Authctxt *authctxt = ssh->authctxt;
3e8b5b
 	Authmethod *m = NULL;
3e8b5b
 	char *user = NULL, *service = NULL, *method = NULL, *style = NULL;
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	char *role = NULL;
3e8b5b
+#endif
3e8b5b
 	int r, authenticated = 0;
3e8b5b
 	double tstart = monotime_double();
3e8b5b
 
3e8b5b
@@ -268,6 +271,11 @@ input_userauth_request(int type, u_int32
3e8b5b
 	debug("userauth-request for user %s service %s method %s", user, service, method);
3e8b5b
 	debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
3e8b5b
 
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	if ((role = strchr(user, '/')) != NULL)
3e8b5b
+		*role++ = 0;
3e8b5b
+#endif
3e8b5b
+
3e8b5b
 	if ((style = strchr(user, ':')) != NULL)
3e8b5b
 		*style++ = 0;
3e8b5b
 
3e8b5b
@@ -296,8 +304,15 @@ input_userauth_request(int type, u_int32
3e8b5b
 		    use_privsep ? " [net]" : "");
3e8b5b
 		authctxt->service = xstrdup(service);
3e8b5b
 		authctxt->style = style ? xstrdup(style) : NULL;
3e8b5b
-		if (use_privsep)
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+		authctxt->role = role ? xstrdup(role) : NULL;
3e8b5b
+#endif
3e8b5b
+		if (use_privsep) {
3e8b5b
 			mm_inform_authserv(service, style);
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+			mm_inform_authrole(role);
3e8b5b
+#endif
3e8b5b
+		}
3e8b5b
 		userauth_banner(ssh);
3e8b5b
 		if (auth2_setup_methods_lists(authctxt) != 0)
3e8b5b
 			ssh_packet_disconnect(ssh,
3e8b5b
diff -up openssh/auth2-gss.c.role-mls openssh/auth2-gss.c
3e8b5b
--- openssh/auth2-gss.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/auth2-gss.c	2018-08-22 11:15:42.459799171 +0200
3e8b5b
@@ -281,6 +281,7 @@ input_gssapi_mic(int type, u_int32_t ple
3e8b5b
 	Authctxt *authctxt = ssh->authctxt;
3e8b5b
 	Gssctxt *gssctxt;
3e8b5b
 	int r, authenticated = 0;
3e8b5b
+	char *micuser;
3e8b5b
 	struct sshbuf *b;
3e8b5b
 	gss_buffer_desc mic, gssbuf;
3e8b5b
 	const char *displayname;
3e8b5b
@@ -298,7 +299,13 @@ input_gssapi_mic(int type, u_int32_t ple
3e8b5b
 		fatal("%s: sshbuf_new failed", __func__);
3e8b5b
 	mic.value = p;
3e8b5b
 	mic.length = len;
3e8b5b
-	ssh_gssapi_buildmic(b, authctxt->user, authctxt->service,
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	if (authctxt->role && authctxt->role[0] != 0)
3e8b5b
+		xasprintf(&micuser, "%s/%s", authctxt->user, authctxt->role);
3e8b5b
+	else
3e8b5b
+#endif
3e8b5b
+		micuser = authctxt->user;
3e8b5b
+	ssh_gssapi_buildmic(b, micuser, authctxt->service,
3e8b5b
 	    "gssapi-with-mic");
3e8b5b
 
3e8b5b
 	if ((gssbuf.value = sshbuf_mutable_ptr(b)) == NULL)
3e8b5b
@@ -311,6 +318,8 @@ input_gssapi_mic(int type, u_int32_t ple
3e8b5b
 		logit("GSSAPI MIC check failed");
3e8b5b
 
3e8b5b
 	sshbuf_free(b);
3e8b5b
+	if (micuser != authctxt->user)
3e8b5b
+		free(micuser);
3e8b5b
 	free(mic.value);
3e8b5b
 
3e8b5b
 	if ((!use_privsep || mm_is_monitor()) &&
3e8b5b
diff -up openssh/auth2-hostbased.c.role-mls openssh/auth2-hostbased.c
3e8b5b
--- openssh/auth2-hostbased.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/auth2-hostbased.c	2018-08-22 11:14:56.816430924 +0200
3e8b5b
@@ -123,7 +123,16 @@ userauth_hostbased(struct ssh *ssh)
3e8b5b
 	/* reconstruct packet */
3e8b5b
 	if ((r = sshbuf_put_string(b, session_id2, session_id2_len)) != 0 ||
3e8b5b
 	    (r = sshbuf_put_u8(b, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	    (authctxt->role
3e8b5b
+	    ? ( (r = sshbuf_put_u32(b, strlen(authctxt->user)+strlen(authctxt->role)+1)) != 0 ||
3e8b5b
+	        (r = sshbuf_put(b, authctxt->user, strlen(authctxt->user))) != 0 ||
3e8b5b
+	        (r = sshbuf_put_u8(b, '/') != 0) ||
3e8b5b
+	        (r = sshbuf_put(b, authctxt->role, strlen(authctxt->role))) != 0)
3e8b5b
+	    : (r = sshbuf_put_cstring(b, authctxt->user)) != 0) ||
3e8b5b
+#else
3e8b5b
 	    (r = sshbuf_put_cstring(b, authctxt->user)) != 0 ||
3e8b5b
+#endif
3e8b5b
 	    (r = sshbuf_put_cstring(b, authctxt->service)) != 0 ||
3e8b5b
 	    (r = sshbuf_put_cstring(b, "hostbased")) != 0 ||
3e8b5b
 	    (r = sshbuf_put_string(b, pkalg, alen)) != 0 ||
3e8b5b
diff -up openssh/auth2-pubkey.c.role-mls openssh/auth2-pubkey.c
3e8b5b
--- openssh/auth2-pubkey.c.role-mls	2018-08-22 11:14:56.816430924 +0200
3e8b5b
+++ openssh/auth2-pubkey.c	2018-08-22 11:17:07.331483958 +0200
3e8b5b
@@ -169,9 +169,16 @@ userauth_pubkey(struct ssh *ssh)
3e8b5b
 			goto done;
3e8b5b
 		}
3e8b5b
 		/* reconstruct packet */
3e8b5b
-		xasprintf(&userstyle, "%s%s%s", authctxt->user,
3e8b5b
+		xasprintf(&userstyle, "%s%s%s%s%s", authctxt->user,
3e8b5b
 		    authctxt->style ? ":" : "",
3e8b5b
-		    authctxt->style ? authctxt->style : "");
3e8b5b
+		    authctxt->style ? authctxt->style : "",
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+		    authctxt->role ? "/" : "",
3e8b5b
+		    authctxt->role ? authctxt->role : ""
3e8b5b
+#else
3e8b5b
+		    "", ""
3e8b5b
+#endif
3e8b5b
+		    );
3e8b5b
 		if ((r = sshbuf_put_u8(b, SSH2_MSG_USERAUTH_REQUEST)) != 0 ||
3e8b5b
 		    (r = sshbuf_put_cstring(b, userstyle)) != 0 ||
3e8b5b
 		    (r = sshbuf_put_cstring(b, authctxt->service)) != 0 ||
3e8b5b
diff -up openssh/auth.h.role-mls openssh/auth.h
3e8b5b
--- openssh/auth.h.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/auth.h	2018-08-22 11:14:56.816430924 +0200
3e8b5b
@@ -65,6 +65,9 @@ struct Authctxt {
3e8b5b
 	char		*service;
3e8b5b
 	struct passwd	*pw;		/* set if 'valid' */
3e8b5b
 	char		*style;
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	char		*role;
3e8b5b
+#endif
3e8b5b
 
3e8b5b
 	/* Method lists for multiple authentication */
3e8b5b
 	char		**auth_methods;	/* modified from server config */
3e8b5b
diff -up openssh/auth-pam.c.role-mls openssh/auth-pam.c
3e8b5b
--- openssh/auth-pam.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/auth-pam.c	2018-08-22 11:14:56.816430924 +0200
3e8b5b
@@ -1172,7 +1172,7 @@ is_pam_session_open(void)
3e8b5b
  * during the ssh authentication process.
3e8b5b
  */
3e8b5b
 int
3e8b5b
-do_pam_putenv(char *name, char *value)
3e8b5b
+do_pam_putenv(char *name, const char *value)
3e8b5b
 {
3e8b5b
 	int ret = 1;
3e8b5b
 #ifdef HAVE_PAM_PUTENV
3e8b5b
diff -up openssh/auth-pam.h.role-mls openssh/auth-pam.h
3e8b5b
--- openssh/auth-pam.h.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/auth-pam.h	2018-08-22 11:14:56.817430932 +0200
3e8b5b
@@ -33,7 +33,7 @@ u_int do_pam_account(void);
3e8b5b
 void do_pam_session(struct ssh *);
3e8b5b
 void do_pam_setcred(int );
3e8b5b
 void do_pam_chauthtok(void);
3e8b5b
-int do_pam_putenv(char *, char *);
3e8b5b
+int do_pam_putenv(char *, const char *);
3e8b5b
 char ** fetch_pam_environment(void);
3e8b5b
 char ** fetch_pam_child_environment(void);
3e8b5b
 void free_pam_environment(char **);
3e8b5b
diff -up openssh/configure.ac.role-mls openssh/configure.ac
3e8b5b
--- openssh/configure.ac.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/configure.ac	2018-08-22 11:14:56.820430957 +0200
3e8b5b
@@ -4241,10 +4241,7 @@ AC_ARG_WITH([selinux],
3e8b5b
 			  LIBS="$LIBS -lselinux"
3e8b5b
 			],
3e8b5b
 			AC_MSG_ERROR([SELinux support requires libselinux library]))
3e8b5b
-		SSHLIBS="$SSHLIBS $LIBSELINUX"
3e8b5b
-		SSHDLIBS="$SSHDLIBS $LIBSELINUX"
3e8b5b
 		AC_CHECK_FUNCS([getseuserbyname get_default_context_with_level])
3e8b5b
-		LIBS="$save_LIBS"
3e8b5b
 	fi ]
3e8b5b
 )
3e8b5b
 AC_SUBST([SSHLIBS])
3e8b5b
diff -up openssh/misc.c.role-mls openssh/misc.c
3e8b5b
--- openssh/misc.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/misc.c	2018-08-22 11:14:56.817430932 +0200
3e8b5b
@@ -542,6 +542,7 @@ char *
3e8b5b
 colon(char *cp)
3e8b5b
 {
3e8b5b
 	int flag = 0;
3e8b5b
+	int start = 1;
3e8b5b
 
3e8b5b
 	if (*cp == ':')		/* Leading colon is part of file name. */
3e8b5b
 		return NULL;
3e8b5b
@@ -557,6 +558,13 @@ colon(char *cp)
3e8b5b
 			return (cp);
3e8b5b
 		if (*cp == '/')
3e8b5b
 			return NULL;
3e8b5b
+		if (start) {
3e8b5b
+		/* Slash on beginning or after dots only denotes file name. */
3e8b5b
+			if (*cp == '/')
3e8b5b
+				return (0);
3e8b5b
+			if (*cp != '.')
3e8b5b
+				start = 0;
3e8b5b
+		}
3e8b5b
 	}
3e8b5b
 	return NULL;
3e8b5b
 }
3e8b5b
diff -up openssh/monitor.c.role-mls openssh/monitor.c
3e8b5b
--- openssh/monitor.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/monitor.c	2018-08-22 11:19:56.006844867 +0200
3e8b5b
@@ -115,6 +115,9 @@ int mm_answer_sign(int, struct sshbuf *)
3e8b5b
 int mm_answer_pwnamallow(struct ssh *, int, struct sshbuf *);
3e8b5b
 int mm_answer_auth2_read_banner(struct ssh *, int, struct sshbuf *);
3e8b5b
 int mm_answer_authserv(struct ssh *, int, struct sshbuf *);
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+int mm_answer_authrole(struct ssh *, int, struct sshbuf *);
3e8b5b
+#endif
3e8b5b
 int mm_answer_authpassword(struct ssh *, int, struct sshbuf *);
3e8b5b
 int mm_answer_bsdauthquery(struct ssh *, int, struct sshbuf *);
3e8b5b
 int mm_answer_bsdauthrespond(struct ssh *, int, struct sshbuf *);
3e8b5b
@@ -189,6 +192,9 @@ struct mon_table mon_dispatch_proto20[]
3e8b5b
     {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
3e8b5b
     {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
3e8b5b
     {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+    {MONITOR_REQ_AUTHROLE, MON_ONCE, mm_answer_authrole},
3e8b5b
+#endif
3e8b5b
     {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
3e8b5b
     {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
3e8b5b
 #ifdef USE_PAM
3e8b5b
@@ -796,6 +802,9 @@ mm_answer_pwnamallow(int sock, struct ss
3e8b5b
 
3e8b5b
 	/* Allow service/style information on the auth context */
3e8b5b
 	monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	monitor_permit(mon_dispatch, MONITOR_REQ_AUTHROLE, 1);
3e8b5b
+#endif
3e8b5b
 	monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
3e8b5b
 
3e8b5b
 #ifdef USE_PAM
3e8b5b
@@ -842,6 +851,26 @@ mm_answer_authserv(int sock, struct sshb
3e8b5b
 	return found;
3e8b5b
 }
3e8b5b
 
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+int
3e8b5b
+mm_answer_authrole(struct ssh *ssh, int sock, struct sshbuf *m)
3e8b5b
+{
3e8b5b
+	int r;
3e8b5b
+	monitor_permit_authentications(1);
3e8b5b
+
3e8b5b
+	if ((r = sshbuf_get_cstring(m, &authctxt->role, NULL)) != 0)
3e8b5b
+		fatal("%s: buffer error: %s", __func__, ssh_err(r));
3e8b5b
+	debug3("%s: role=%s", __func__, authctxt->role);
3e8b5b
+
3e8b5b
+	if (strlen(authctxt->role) == 0) {
3e8b5b
+		free(authctxt->role);
3e8b5b
+		authctxt->role = NULL;
3e8b5b
+	}
3e8b5b
+
3e8b5b
+	return (0);
3e8b5b
+}
3e8b5b
+#endif
3e8b5b
+
3e8b5b
 int
3e8b5b
 mm_answer_authpassword(struct ssh *ssh, int sock, struct sshbuf *m)
3e8b5b
 {
3e8b5b
@@ -1218,7 +1247,7 @@ monitor_valid_userblob(u_char *data, u_i
3e8b5b
 {
3e8b5b
 	struct sshbuf *b;
3e8b5b
 	const u_char *p;
3e8b5b
-	char *userstyle, *cp;
3e8b5b
+	char *userstyle, *s, *cp;
3e8b5b
 	size_t len;
3e8b5b
 	u_char type;
3e8b5b
 	int r, fail = 0;
3e8b5b
@@ -1251,6 +1280,8 @@ monitor_valid_userblob(u_char *data, u_i
3e8b5b
 		fail++;
3e8b5b
 	if ((r = sshbuf_get_cstring(b, &cp, NULL)) != 0)
3e8b5b
 		fatal("%s: buffer error: %s", __func__, ssh_err(r));
3e8b5b
+	if ((s = strchr(cp, '/')) != NULL)
3e8b5b
+		*s = '\0';
3e8b5b
 	xasprintf(&userstyle, "%s%s%s", authctxt->user,
3e8b5b
 	    authctxt->style ? ":" : "",
3e8b5b
 	    authctxt->style ? authctxt->style : "");
3e8b5b
@@ -1286,7 +1317,7 @@ monitor_valid_hostbasedblob(u_char *data
3e8b5b
 {
3e8b5b
 	struct sshbuf *b;
3e8b5b
 	const u_char *p;
3e8b5b
-	char *cp, *userstyle;
3e8b5b
+	char *cp, *s, *userstyle;
3e8b5b
 	size_t len;
3e8b5b
 	int r, fail = 0;
3e8b5b
 	u_char type;
3e8b5b
@@ -1308,6 +1339,8 @@ monitor_valid_hostbasedblob(u_char *data
3e8b5b
 		fail++;
3e8b5b
 	if ((r = sshbuf_get_cstring(b, &cp, NULL)) != 0)
3e8b5b
 		fatal("%s: buffer error: %s", __func__, ssh_err(r));
7afad6
+	if ((s = strchr(cp, '/')) != NULL)
3e8b5b
+		*s = '\0';
3e8b5b
 	xasprintf(&userstyle, "%s%s%s", authctxt->user,
3e8b5b
 	    authctxt->style ? ":" : "",
3e8b5b
 	    authctxt->style ? authctxt->style : "");
3e8b5b
diff -up openssh/monitor.h.role-mls openssh/monitor.h
3e8b5b
--- openssh/monitor.h.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/monitor.h	2018-08-22 11:14:56.818430941 +0200
3e8b5b
@@ -55,6 +55,10 @@ enum monitor_reqtype {
3e8b5b
 	MONITOR_REQ_GSSCHECKMIC = 48, MONITOR_ANS_GSSCHECKMIC = 49,
3e8b5b
 	MONITOR_REQ_TERM = 50,
3e8b5b
 
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	MONITOR_REQ_AUTHROLE = 80,
3e8b5b
+#endif
3e8b5b
+
3e8b5b
 	MONITOR_REQ_PAM_START = 100,
3e8b5b
 	MONITOR_REQ_PAM_ACCOUNT = 102, MONITOR_ANS_PAM_ACCOUNT = 103,
3e8b5b
 	MONITOR_REQ_PAM_INIT_CTX = 104, MONITOR_ANS_PAM_INIT_CTX = 105,
3e8b5b
diff -up openssh/monitor_wrap.c.role-mls openssh/monitor_wrap.c
3e8b5b
--- openssh/monitor_wrap.c.role-mls	2018-08-22 11:14:56.818430941 +0200
3e8b5b
+++ openssh/monitor_wrap.c	2018-08-22 11:21:47.938747968 +0200
3e8b5b
@@ -390,6 +390,27 @@ mm_inform_authserv(char *service, char *
3e8b5b
 	sshbuf_free(m);
3e8b5b
 }
3e8b5b
 
3e8b5b
+/* Inform the privileged process about role */
3e8b5b
+
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+void
3e8b5b
+mm_inform_authrole(char *role)
3e8b5b
+{
3e8b5b
+	int r;
3e8b5b
+	struct sshbuf *m;
3e8b5b
+
3e8b5b
+	debug3("%s entering", __func__);
3e8b5b
+
3e8b5b
+	if ((m = sshbuf_new()) == NULL)
3e8b5b
+		fatal("%s: sshbuf_new failed", __func__);
3e8b5b
+	if ((r = sshbuf_put_cstring(m, role ? role : "")) != 0)
3e8b5b
+		fatal("%s: buffer error: %s", __func__, ssh_err(r));
3e8b5b
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHROLE, m);
3e8b5b
+
3e8b5b
+	sshbuf_free(m);
3e8b5b
+}
3e8b5b
+#endif
3e8b5b
+
3e8b5b
 /* Do the password authentication */
3e8b5b
 int
3e8b5b
 mm_auth_password(struct ssh *ssh, char *password)
3e8b5b
diff -up openssh/monitor_wrap.h.role-mls openssh/monitor_wrap.h
3e8b5b
--- openssh/monitor_wrap.h.role-mls	2018-08-22 11:14:56.818430941 +0200
3e8b5b
+++ openssh/monitor_wrap.h	2018-08-22 11:22:10.439929513 +0200
3e8b5b
@@ -44,6 +44,9 @@ DH *mm_choose_dh(int, int, int);
3e8b5b
 int mm_sshkey_sign(struct ssh *, struct sshkey *, u_char **, size_t *,
3e8b5b
     const u_char *, size_t, const char *, u_int compat);
3e8b5b
 void mm_inform_authserv(char *, char *);
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+void mm_inform_authrole(char *);
3e8b5b
+#endif
3e8b5b
 struct passwd *mm_getpwnamallow(struct ssh *, const char *);
3e8b5b
 char *mm_auth2_read_banner(void);
3e8b5b
 int mm_auth_password(struct ssh *, char *);
3e8b5b
diff -up openssh/openbsd-compat/Makefile.in.role-mls openssh/openbsd-compat/Makefile.in
3e8b5b
--- openssh/openbsd-compat/Makefile.in.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/openbsd-compat/Makefile.in	2018-08-22 11:14:56.819430949 +0200
3e8b5b
@@ -92,7 +92,8 @@ PORTS=	port-aix.o \
3e8b5b
 	port-linux.o \
3e8b5b
 	port-solaris.o \
3e8b5b
 	port-net.o \
3e8b5b
-	port-uw.o
3e8b5b
+	port-uw.o \
3e8b5b
+	port-linux-sshd.o
3e8b5b
 
3e8b5b
 .c.o:
3e8b5b
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
3e8b5b
diff -up openssh/openbsd-compat/port-linux.c.role-mls openssh/openbsd-compat/port-linux.c
3e8b5b
--- openssh/openbsd-compat/port-linux.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/openbsd-compat/port-linux.c	2018-08-22 11:14:56.819430949 +0200
3e8b5b
@@ -100,37 +100,6 @@ ssh_selinux_getctxbyname(char *pwname)
3e8b5b
 	return sc;
3e8b5b
 }
3e8b5b
 
3e8b5b
-/* Set the execution context to the default for the specified user */
3e8b5b
-void
3e8b5b
-ssh_selinux_setup_exec_context(char *pwname)
3e8b5b
-{
3e8b5b
-	security_context_t user_ctx = NULL;
3e8b5b
-
3e8b5b
-	if (!ssh_selinux_enabled())
3e8b5b
-		return;
3e8b5b
-
3e8b5b
-	debug3("%s: setting execution context", __func__);
3e8b5b
-
3e8b5b
-	user_ctx = ssh_selinux_getctxbyname(pwname);
3e8b5b
-	if (setexeccon(user_ctx) != 0) {
3e8b5b
-		switch (security_getenforce()) {
3e8b5b
-		case -1:
3e8b5b
-			fatal("%s: security_getenforce() failed", __func__);
3e8b5b
-		case 0:
3e8b5b
-			error("%s: Failed to set SELinux execution "
3e8b5b
-			    "context for %s", __func__, pwname);
3e8b5b
-			break;
3e8b5b
-		default:
3e8b5b
-			fatal("%s: Failed to set SELinux execution context "
3e8b5b
-			    "for %s (in enforcing mode)", __func__, pwname);
3e8b5b
-		}
3e8b5b
-	}
3e8b5b
-	if (user_ctx != NULL)
3e8b5b
-		freecon(user_ctx);
3e8b5b
-
3e8b5b
-	debug3("%s: done", __func__);
3e8b5b
-}
3e8b5b
-
3e8b5b
 /* Set the TTY context for the specified user */
3e8b5b
 void
3e8b5b
 ssh_selinux_setup_pty(char *pwname, const char *tty)
3e8b5b
@@ -145,7 +114,11 @@ ssh_selinux_setup_pty(char *pwname, cons
3e8b5b
 
3e8b5b
 	debug3("%s: setting TTY context on %s", __func__, tty);
3e8b5b
 
3e8b5b
-	user_ctx = ssh_selinux_getctxbyname(pwname);
3e8b5b
+	if (getexeccon(&user_ctx) != 0) {
3e8b5b
+		error("%s: getexeccon: %s", __func__, strerror(errno));
3e8b5b
+		goto out;
3e8b5b
+	}
3e8b5b
+
3e8b5b
 
3e8b5b
 	/* XXX: should these calls fatal() upon failure in enforcing mode? */
3e8b5b
 
3e8b5b
diff -up openssh/openbsd-compat/port-linux.h.role-mls openssh/openbsd-compat/port-linux.h
3e8b5b
--- openssh/openbsd-compat/port-linux.h.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/openbsd-compat/port-linux.h	2018-08-22 11:14:56.819430949 +0200
3e8b5b
@@ -20,9 +20,10 @@
3e8b5b
 #ifdef WITH_SELINUX
3e8b5b
 int ssh_selinux_enabled(void);
3e8b5b
 void ssh_selinux_setup_pty(char *, const char *);
3e8b5b
-void ssh_selinux_setup_exec_context(char *);
3e8b5b
 void ssh_selinux_change_context(const char *);
3e8b5b
 void ssh_selinux_setfscreatecon(const char *);
3e8b5b
+
3e8b5b
+void sshd_selinux_setup_exec_context(char *);
3e8b5b
 #endif
3e8b5b
 
3e8b5b
 #ifdef LINUX_OOM_ADJUST
3e8b5b
diff -up openssh/openbsd-compat/port-linux-sshd.c.role-mls openssh/openbsd-compat/port-linux-sshd.c
3e8b5b
--- openssh/openbsd-compat/port-linux-sshd.c.role-mls	2018-08-22 11:14:56.819430949 +0200
3e8b5b
+++ openssh/openbsd-compat/port-linux-sshd.c	2018-08-22 11:14:56.819430949 +0200
3e8b5b
@@ -0,0 +1,425 @@
3e8b5b
+/*
3e8b5b
+ * Copyright (c) 2005 Daniel Walsh <dwalsh@redhat.com>
3e8b5b
+ * Copyright (c) 2014 Petr Lautrbach <plautrba@redhat.com>
3e8b5b
+ *
3e8b5b
+ * Permission to use, copy, modify, and distribute this software for any
3e8b5b
+ * purpose with or without fee is hereby granted, provided that the above
3e8b5b
+ * copyright notice and this permission notice appear in all copies.
3e8b5b
+ *
3e8b5b
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e8b5b
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e8b5b
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e8b5b
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e8b5b
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e8b5b
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e8b5b
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e8b5b
+ */
3e8b5b
+
3e8b5b
+/*
3e8b5b
+ * Linux-specific portability code - just SELinux support for sshd at present
3e8b5b
+ */
3e8b5b
+
3e8b5b
+#include "includes.h"
3e8b5b
+
3e8b5b
+#if defined(WITH_SELINUX) || defined(LINUX_OOM_ADJUST)
3e8b5b
+#include <errno.h>
3e8b5b
+#include <stdarg.h>
3e8b5b
+#include <string.h>
3e8b5b
+#include <stdio.h>
3e8b5b
+#include <stdlib.h>
3e8b5b
+
3e8b5b
+#include "log.h"
3e8b5b
+#include "xmalloc.h"
3e8b5b
+#include "misc.h"      /* servconf.h needs misc.h for struct ForwardOptions */
3e8b5b
+#include "servconf.h"
3e8b5b
+#include "port-linux.h"
3e8b5b
+#include "sshkey.h"
3e8b5b
+#include "hostfile.h"
3e8b5b
+#include "auth.h"
3e8b5b
+
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+#include <selinux/selinux.h>
3e8b5b
+#include <selinux/context.h>
3e8b5b
+#include <selinux/get_context_list.h>
3e8b5b
+#include <selinux/get_default_type.h>
3e8b5b
+
3e8b5b
+#ifdef HAVE_LINUX_AUDIT
3e8b5b
+#include <libaudit.h>
3e8b5b
+#include <unistd.h>
3e8b5b
+#endif
3e8b5b
+
3e8b5b
+extern ServerOptions options;
3e8b5b
+extern Authctxt *the_authctxt;
3e8b5b
+extern int inetd_flag;
3e8b5b
+extern int rexeced_flag;
3e8b5b
+
3e8b5b
+/* Send audit message */
3e8b5b
+static int
3e8b5b
+sshd_selinux_send_audit_message(int success, security_context_t default_context,
3e8b5b
+		       security_context_t selected_context)
3e8b5b
+{
3e8b5b
+	int rc=0;
3e8b5b
+#ifdef HAVE_LINUX_AUDIT
3e8b5b
+	char *msg = NULL;
3e8b5b
+	int audit_fd = audit_open();
3e8b5b
+	security_context_t default_raw=NULL;
3e8b5b
+	security_context_t selected_raw=NULL;
3e8b5b
+	rc = -1;
3e8b5b
+	if (audit_fd < 0) {
3e8b5b
+		if (errno == EINVAL || errno == EPROTONOSUPPORT ||
3e8b5b
+					errno == EAFNOSUPPORT)
3e8b5b
+				return 0; /* No audit support in kernel */
3e8b5b
+		error("Error connecting to audit system.");
3e8b5b
+		return rc;
3e8b5b
+	}
3e8b5b
+	if (selinux_trans_to_raw_context(default_context, &default_raw) < 0) {
3e8b5b
+		error("Error translating default context.");
3e8b5b
+		default_raw = NULL;
3e8b5b
+	}
3e8b5b
+	if (selinux_trans_to_raw_context(selected_context, &selected_raw) < 0) {
3e8b5b
+		error("Error translating selected context.");
3e8b5b
+		selected_raw = NULL;
3e8b5b
+	}
3e8b5b
+	if (asprintf(&msg, "sshd: default-context=%s selected-context=%s",
3e8b5b
+		     default_raw ? default_raw : (default_context ? default_context: "?"),
3e8b5b
+		     selected_context ? selected_raw : (selected_context ? selected_context :"?")) < 0) {
3e8b5b
+		error("Error allocating memory.");
3e8b5b
+		goto out;
3e8b5b
+	}
3e8b5b
+	if (audit_log_user_message(audit_fd, AUDIT_USER_ROLE_CHANGE,
3e8b5b
+				   msg, NULL, NULL, NULL, success) <= 0) {
3e8b5b
+		error("Error sending audit message.");
3e8b5b
+		goto out;
3e8b5b
+	}
3e8b5b
+	rc = 0;
3e8b5b
+      out:
3e8b5b
+	free(msg);
3e8b5b
+	freecon(default_raw);
3e8b5b
+	freecon(selected_raw);
3e8b5b
+	close(audit_fd);
3e8b5b
+#endif
3e8b5b
+	return rc;
3e8b5b
+}
3e8b5b
+
3e8b5b
+static int
3e8b5b
+mls_range_allowed(security_context_t src, security_context_t dst)
3e8b5b
+{
3e8b5b
+	struct av_decision avd;
3e8b5b
+	int retval;
3e8b5b
+	access_vector_t bit;
3e8b5b
+	security_class_t class;
3e8b5b
+
3e8b5b
+	debug("%s: src:%s dst:%s", __func__, src, dst);
3e8b5b
+	class = string_to_security_class("context");
3e8b5b
+	if (!class) {
3e8b5b
+		error("string_to_security_class failed to translate security class context");
3e8b5b
+		return 1;
3e8b5b
+	}
3e8b5b
+	bit = string_to_av_perm(class, "contains");
3e8b5b
+	if (!bit) {
3e8b5b
+		error("string_to_av_perm failed to translate av perm contains");
3e8b5b
+		return 1;
3e8b5b
+	}
3e8b5b
+	retval = security_compute_av(src, dst, class, bit, &avd);
3e8b5b
+	if (retval || ((bit & avd.allowed) != bit))
3e8b5b
+		return 0;
3e8b5b
+
3e8b5b
+	return 1;
3e8b5b
+}
3e8b5b
+
3e8b5b
+static int
3e8b5b
+get_user_context(const char *sename, const char *role, const char *lvl,
3e8b5b
+	security_context_t *sc) {
3e8b5b
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
3e8b5b
+	if (lvl == NULL || lvl[0] == '\0' || get_default_context_with_level(sename, lvl, NULL, sc) != 0) {
3e8b5b
+	        /* User may have requested a level completely outside of his 
3e8b5b
+	           allowed range. We get a context just for auditing as the
3e8b5b
+	           range check below will certainly fail for default context. */
3e8b5b
+#endif
3e8b5b
+		if (get_default_context(sename, NULL, sc) != 0) {
3e8b5b
+			*sc = NULL;
3e8b5b
+			return -1;
3e8b5b
+		}
3e8b5b
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
3e8b5b
+	}
3e8b5b
+#endif
3e8b5b
+	if (role != NULL && role[0]) {
3e8b5b
+		context_t con;
3e8b5b
+		char *type=NULL;
3e8b5b
+		if (get_default_type(role, &type) != 0) {
3e8b5b
+			error("get_default_type: failed to get default type for '%s'",
3e8b5b
+				role);
3e8b5b
+			goto out;
3e8b5b
+		}
3e8b5b
+		con = context_new(*sc);
3e8b5b
+		if (!con) {
3e8b5b
+			goto out;
3e8b5b
+		}
3e8b5b
+		context_role_set(con, role);
3e8b5b
+		context_type_set(con, type);
3e8b5b
+		freecon(*sc);
3e8b5b
+		*sc = strdup(context_str(con));
3e8b5b
+		context_free(con);
3e8b5b
+		if (!*sc)
3e8b5b
+			return -1;
3e8b5b
+	}
3e8b5b
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
3e8b5b
+	if (lvl != NULL && lvl[0]) {
3e8b5b
+		/* verify that the requested range is obtained */
3e8b5b
+		context_t con;
3e8b5b
+		security_context_t obtained_raw;
3e8b5b
+		security_context_t requested_raw;
3e8b5b
+		con = context_new(*sc);
3e8b5b
+		if (!con) {
3e8b5b
+			goto out;
3e8b5b
+		}
3e8b5b
+		context_range_set(con, lvl);
3e8b5b
+		if (selinux_trans_to_raw_context(*sc, &obtained_raw) < 0) {
3e8b5b
+			context_free(con);
3e8b5b
+			goto out;
3e8b5b
+		}
3e8b5b
+		if (selinux_trans_to_raw_context(context_str(con), &requested_raw) < 0) {
3e8b5b
+			freecon(obtained_raw);
3e8b5b
+			context_free(con);
3e8b5b
+			goto out;
3e8b5b
+		}
3e8b5b
+
3e8b5b
+		debug("get_user_context: obtained context '%s' requested context '%s'",
3e8b5b
+			obtained_raw, requested_raw);
3e8b5b
+		if (strcmp(obtained_raw, requested_raw)) {
3e8b5b
+			/* set the context to the real requested one but fail */
3e8b5b
+			freecon(requested_raw);
3e8b5b
+			freecon(obtained_raw);
3e8b5b
+			freecon(*sc);
3e8b5b
+			*sc = strdup(context_str(con));
3e8b5b
+			context_free(con);
3e8b5b
+			return -1;
3e8b5b
+		}
3e8b5b
+		freecon(requested_raw);
3e8b5b
+		freecon(obtained_raw);
3e8b5b
+		context_free(con);
3e8b5b
+	}
3e8b5b
+#endif
3e8b5b
+	return 0;
3e8b5b
+      out:
3e8b5b
+	freecon(*sc);
3e8b5b
+	*sc = NULL;
3e8b5b
+	return -1;
3e8b5b
+}
3e8b5b
+
3e8b5b
+static void
3e8b5b
+ssh_selinux_get_role_level(char **role, const char **level)
3e8b5b
+{
3e8b5b
+	*role = NULL;
3e8b5b
+	*level = NULL;
3e8b5b
+	if (the_authctxt) {
3e8b5b
+		if (the_authctxt->role != NULL) {
3e8b5b
+			char *slash;
3e8b5b
+			*role = xstrdup(the_authctxt->role);
3e8b5b
+			if ((slash = strchr(*role, '/')) != NULL) {
3e8b5b
+				*slash = '\0';
3e8b5b
+				*level = slash + 1;
3e8b5b
+			}
3e8b5b
+		}
3e8b5b
+	}
3e8b5b
+}
3e8b5b
+
3e8b5b
+/* Return the default security context for the given username */
3e8b5b
+static int
3e8b5b
+sshd_selinux_getctxbyname(char *pwname,
3e8b5b
+	security_context_t *default_sc, security_context_t *user_sc)
3e8b5b
+{
3e8b5b
+	char *sename, *lvl;
3e8b5b
+	char *role;
3e8b5b
+	const char *reqlvl;
3e8b5b
+	int r = 0;
3e8b5b
+	context_t con = NULL;
3e8b5b
+
3e8b5b
+	ssh_selinux_get_role_level(&role, &reqlvl);
3e8b5b
+
3e8b5b
+#ifdef HAVE_GETSEUSERBYNAME
3e8b5b
+	if ((r=getseuserbyname(pwname, &sename, &lvl)) != 0) {
3e8b5b
+		sename = NULL;
3e8b5b
+		lvl = NULL;
3e8b5b
+	}
3e8b5b
+#else
3e8b5b
+	sename = pwname;
3e8b5b
+	lvl = "";
3e8b5b
+#endif
3e8b5b
+
3e8b5b
+	if (r == 0) {
3e8b5b
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
3e8b5b
+		r = get_default_context_with_level(sename, lvl, NULL, default_sc);
3e8b5b
+#else
3e8b5b
+		r = get_default_context(sename, NULL, default_sc);
3e8b5b
+#endif
3e8b5b
+	}
3e8b5b
+
3e8b5b
+	if (r == 0) {
3e8b5b
+		/* If launched from xinetd, we must use current level */
3e8b5b
+		if (inetd_flag && !rexeced_flag) {
3e8b5b
+			security_context_t sshdsc=NULL;
3e8b5b
+
3e8b5b
+			if (getcon_raw(&sshdsc) < 0)
3e8b5b
+				fatal("failed to allocate security context");
3e8b5b
+
3e8b5b
+			if ((con=context_new(sshdsc)) == NULL)
3e8b5b
+				fatal("failed to allocate selinux context");
3e8b5b
+			reqlvl = context_range_get(con);
3e8b5b
+			freecon(sshdsc);
3e8b5b
+			if (reqlvl !=NULL && lvl != NULL && strcmp(reqlvl, lvl) == 0)
3e8b5b
+			    /* we actually don't change level */
3e8b5b
+			    reqlvl = "";
3e8b5b
+
3e8b5b
+			debug("%s: current connection level '%s'", __func__, reqlvl);
3e8b5b
+
3e8b5b
+		}
3e8b5b
+
3e8b5b
+		if ((reqlvl != NULL && reqlvl[0]) || (role != NULL && role[0])) {
3e8b5b
+			r = get_user_context(sename, role, reqlvl, user_sc);
3e8b5b
+
3e8b5b
+			if (r == 0 && reqlvl != NULL && reqlvl[0]) {
3e8b5b
+				security_context_t default_level_sc = *default_sc;
3e8b5b
+				if (role != NULL && role[0]) {
3e8b5b
+					if (get_user_context(sename, role, lvl, &default_level_sc) < 0)
3e8b5b
+						default_level_sc = *default_sc;
3e8b5b
+				}
3e8b5b
+				/* verify that the requested range is contained in the user range */
3e8b5b
+				if (mls_range_allowed(default_level_sc, *user_sc)) {
3e8b5b
+					logit("permit MLS level %s (user range %s)", reqlvl, lvl);
3e8b5b
+				} else {
3e8b5b
+					r = -1;
3e8b5b
+					error("deny MLS level %s (user range %s)", reqlvl, lvl);
3e8b5b
+				}
3e8b5b
+				if (default_level_sc != *default_sc)
3e8b5b
+					freecon(default_level_sc);
3e8b5b
+			}
3e8b5b
+		} else {
3e8b5b
+			*user_sc = *default_sc;
3e8b5b
+		}
3e8b5b
+	}
3e8b5b
+	if (r != 0) {
3e8b5b
+		error("%s: Failed to get default SELinux security "
3e8b5b
+		    "context for %s", __func__, pwname);
3e8b5b
+	}
3e8b5b
+
3e8b5b
+#ifdef HAVE_GETSEUSERBYNAME
3e8b5b
+	free(sename);
3e8b5b
+	free(lvl);
3e8b5b
+#endif
3e8b5b
+
3e8b5b
+	if (role != NULL)
3e8b5b
+		free(role);
3e8b5b
+	if (con)
3e8b5b
+		context_free(con);
3e8b5b
+
3e8b5b
+	return (r);
3e8b5b
+}
3e8b5b
+
3e8b5b
+/* Setup environment variables for pam_selinux */
3e8b5b
+static int
3e8b5b
+sshd_selinux_setup_pam_variables(void)
3e8b5b
+{
3e8b5b
+	const char *reqlvl;
3e8b5b
+	char *role;
3e8b5b
+	char *use_current;
3e8b5b
+	int rv;
3e8b5b
+
3e8b5b
+	debug3("%s: setting execution context", __func__);
3e8b5b
+
3e8b5b
+	ssh_selinux_get_role_level(&role, &reqlvl);
3e8b5b
+
3e8b5b
+	rv = do_pam_putenv("SELINUX_ROLE_REQUESTED", role ? role : "");
3e8b5b
+
3e8b5b
+	if (inetd_flag && !rexeced_flag) {
3e8b5b
+		use_current = "1";
3e8b5b
+	} else {
3e8b5b
+		use_current = "";
3e8b5b
+		rv = rv || do_pam_putenv("SELINUX_LEVEL_REQUESTED", reqlvl ? reqlvl: "");
3e8b5b
+	}
3e8b5b
+
3e8b5b
+	rv = rv || do_pam_putenv("SELINUX_USE_CURRENT_RANGE", use_current);
3e8b5b
+
3e8b5b
+	if (role != NULL)
3e8b5b
+		free(role);
3e8b5b
+
3e8b5b
+	return rv;
3e8b5b
+}
3e8b5b
+
3e8b5b
+/* Set the execution context to the default for the specified user */
3e8b5b
+void
3e8b5b
+sshd_selinux_setup_exec_context(char *pwname)
3e8b5b
+{
3e8b5b
+	security_context_t user_ctx = NULL;
3e8b5b
+	int r = 0;
3e8b5b
+	security_context_t default_ctx = NULL;
3e8b5b
+
3e8b5b
+	if (!ssh_selinux_enabled())
3e8b5b
+		return;
3e8b5b
+
3e8b5b
+	if (options.use_pam) {
3e8b5b
+		/* do not compute context, just setup environment for pam_selinux */
3e8b5b
+		if (sshd_selinux_setup_pam_variables()) {
3e8b5b
+			switch (security_getenforce()) {
3e8b5b
+			case -1:
3e8b5b
+				fatal("%s: security_getenforce() failed", __func__);
3e8b5b
+			case 0:
3e8b5b
+				error("%s: SELinux PAM variable setup failure. Continuing in permissive mode.",
3e8b5b
+				    __func__);
3e8b5b
+			break;
3e8b5b
+			default:
3e8b5b
+				fatal("%s: SELinux PAM variable setup failure. Aborting connection.",
3e8b5b
+				    __func__);
3e8b5b
+			}
3e8b5b
+		}
3e8b5b
+		return;
3e8b5b
+	}
3e8b5b
+
3e8b5b
+	debug3("%s: setting execution context", __func__);
3e8b5b
+
3e8b5b
+	r = sshd_selinux_getctxbyname(pwname, &default_ctx, &user_ctx);
3e8b5b
+	if (r >= 0) {
3e8b5b
+		r = setexeccon(user_ctx);
3e8b5b
+		if (r < 0) {
3e8b5b
+			error("%s: Failed to set SELinux execution context %s for %s",
3e8b5b
+			    __func__, user_ctx, pwname);
3e8b5b
+		}
3e8b5b
+#ifdef HAVE_SETKEYCREATECON
3e8b5b
+		else if (setkeycreatecon(user_ctx) < 0) {
3e8b5b
+			error("%s: Failed to set SELinux keyring creation context %s for %s",
3e8b5b
+			    __func__, user_ctx, pwname);
3e8b5b
+		}
3e8b5b
+#endif
3e8b5b
+	}
3e8b5b
+	if (user_ctx == NULL) {
3e8b5b
+		user_ctx = default_ctx;
3e8b5b
+	}
3e8b5b
+	if (r < 0 || user_ctx != default_ctx) {
3e8b5b
+		/* audit just the case when user changed a role or there was
3e8b5b
+		   a failure */
3e8b5b
+		sshd_selinux_send_audit_message(r >= 0, default_ctx, user_ctx);
3e8b5b
+	}
3e8b5b
+	if (r < 0) {
3e8b5b
+		switch (security_getenforce()) {
3e8b5b
+		case -1:
3e8b5b
+			fatal("%s: security_getenforce() failed", __func__);
3e8b5b
+		case 0:
3e8b5b
+			error("%s: SELinux failure. Continuing in permissive mode.",
3e8b5b
+			    __func__);
3e8b5b
+			break;
3e8b5b
+		default:
3e8b5b
+			fatal("%s: SELinux failure. Aborting connection.",
3e8b5b
+			    __func__);
3e8b5b
+		}
3e8b5b
+	}
3e8b5b
+	if (user_ctx != NULL && user_ctx != default_ctx)
3e8b5b
+		freecon(user_ctx);
3e8b5b
+	if (default_ctx != NULL)
3e8b5b
+		freecon(default_ctx);
3e8b5b
+
3e8b5b
+	debug3("%s: done", __func__);
3e8b5b
+}
3e8b5b
+
3e8b5b
+#endif
3e8b5b
+#endif
3e8b5b
+
3e8b5b
diff -up openssh/platform.c.role-mls openssh/platform.c
3e8b5b
--- openssh/platform.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/platform.c	2018-08-22 11:14:56.819430949 +0200
3e8b5b
@@ -183,7 +183,7 @@ platform_setusercontext_post_groups(stru
3e8b5b
 	}
3e8b5b
 #endif /* HAVE_SETPCRED */
3e8b5b
 #ifdef WITH_SELINUX
3e8b5b
-	ssh_selinux_setup_exec_context(pw->pw_name);
3e8b5b
+	sshd_selinux_setup_exec_context(pw->pw_name);
3e8b5b
 #endif
3e8b5b
 }
3e8b5b
 
3e8b5b
diff -up openssh/sshd.c.role-mls openssh/sshd.c
3e8b5b
--- openssh/sshd.c.role-mls	2018-08-20 07:57:29.000000000 +0200
3e8b5b
+++ openssh/sshd.c	2018-08-22 11:14:56.820430957 +0200
3e8b5b
@@ -2186,6 +2186,9 @@ main(int ac, char **av)
3e8b5b
 		restore_uid();
3e8b5b
 	}
3e8b5b
 #endif
3e8b5b
+#ifdef WITH_SELINUX
3e8b5b
+	sshd_selinux_setup_exec_context(authctxt->pw->pw_name);
3e8b5b
+#endif
3e8b5b
 #ifdef USE_PAM
3e8b5b
 	if (options.use_pam) {
3e8b5b
 		do_pam_setcred(1);