|
Tomáš Mráz |
c2b35d |
--- openssh-4.5p1/openbsd-compat/port-linux.c.mls 2007-01-16 21:43:11.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
+++ openssh-4.5p1/openbsd-compat/port-linux.c 2007-01-16 21:40:13.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
@@ -33,12 +33,22 @@
|
|
Tomáš Mráz |
c2b35d |
#include "key.h"
|
|
Tomáš Mráz |
c2b35d |
#include "hostfile.h"
|
|
Tomáš Mráz |
c2b35d |
#include "auth.h"
|
|
Tomáš Mráz |
c2b35d |
+#include "xmalloc.h"
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
#include <selinux/selinux.h>
|
|
Tomáš Mráz |
c2b35d |
#include <selinux/flask.h>
|
|
Tomáš Mráz |
c2b35d |
+#include <selinux/context.h>
|
|
Tomáš Mráz |
c2b35d |
#include <selinux/get_context_list.h>
|
|
Tomáš Mráz |
c2b35d |
+#include <selinux/av_permissions.h>
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+#ifdef HAVE_LINUX_AUDIT
|
|
Tomáš Mráz |
c2b35d |
+#include <libaudit.h>
|
|
Tomáš Mráz |
c2b35d |
+#include <sys/select.h>
|
|
Tomáš Mráz |
c2b35d |
+#endif
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
extern Authctxt *the_authctxt;
|
|
Tomáš Mráz |
c2b35d |
+extern int inetd_flag;
|
|
Tomáš Mráz |
c2b35d |
+extern int rexeced_flag;
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
/* Wrapper around is_selinux_enabled() to log its return value once only */
|
|
Tomáš Mráz |
c2b35d |
static int
|
|
Tomáš Mráz |
c2b35d |
@@ -54,17 +64,107 @@
|
|
Tomáš Mráz |
c2b35d |
return (enabled);
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
+/* Send audit message */
|
|
Tomáš Mráz |
c2b35d |
+static int
|
|
Tomáš Mráz |
c2b35d |
+send_audit_message(int success, security_context_t default_context,
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t selected_context)
|
|
Tomáš Mráz |
c2b35d |
+{
|
|
Tomáš Mráz |
c2b35d |
+ int rc=0;
|
|
Tomáš Mráz |
c2b35d |
+#ifdef HAVE_LINUX_AUDIT
|
|
Tomáš Mráz |
c2b35d |
+ char *msg = NULL;
|
|
Tomáš Mráz |
c2b35d |
+ int audit_fd = audit_open();
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t default_raw=NULL;
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t selected_raw=NULL;
|
|
Tomáš Mráz |
c2b35d |
+ rc = -1;
|
|
Tomáš Mráz |
c2b35d |
+ if (audit_fd < 0) {
|
|
Tomáš Mráz |
c2b35d |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
Tomáš Mráz |
c2b35d |
+ errno == EAFNOSUPPORT)
|
|
Tomáš Mráz |
c2b35d |
+ return 0; /* No audit support in kernel */
|
|
Tomáš Mráz |
c2b35d |
+ error("Error connecting to audit system.");
|
|
Tomáš Mráz |
c2b35d |
+ return rc;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ if (selinux_trans_to_raw_context(default_context, &default_raw) < 0) {
|
|
Tomáš Mráz |
c2b35d |
+ error("Error translating default context.");
|
|
Tomáš Mráz |
c2b35d |
+ goto out;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ if (selinux_trans_to_raw_context(selected_context, &selected_raw) < 0) {
|
|
Tomáš Mráz |
c2b35d |
+ error("Error translating selected context.");
|
|
Tomáš Mráz |
c2b35d |
+ goto out;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ if (asprintf(&msg, "sshd: default-context=%s selected-context=%s",
|
|
Tomáš Mráz |
c2b35d |
+ default_context ? default_raw : "?",
|
|
Tomáš Mráz |
c2b35d |
+ selected_context ? selected_raw : "?") < 0) {
|
|
Tomáš Mráz |
c2b35d |
+ error("Error allocating memory.");
|
|
Tomáš Mráz |
c2b35d |
+ goto out;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ if (audit_log_user_message(audit_fd, AUDIT_USER_ROLE_CHANGE,
|
|
Tomáš Mráz |
c2b35d |
+ msg, NULL, NULL, NULL, success) <= 0) {
|
|
Tomáš Mráz |
c2b35d |
+ error("Error sending audit message.");
|
|
Tomáš Mráz |
c2b35d |
+ goto out;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ rc = 0;
|
|
Tomáš Mráz |
c2b35d |
+ out:
|
|
Tomáš Mráz |
c2b35d |
+ free(msg);
|
|
Tomáš Mráz |
c2b35d |
+ freecon(default_raw);
|
|
Tomáš Mráz |
c2b35d |
+ freecon(selected_raw);
|
|
Tomáš Mráz |
c2b35d |
+ close(audit_fd);
|
|
Tomáš Mráz |
c2b35d |
+#endif
|
|
Tomáš Mráz |
c2b35d |
+ return rc;
|
|
Tomáš Mráz |
c2b35d |
+}
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+static int
|
|
Tomáš Mráz |
c2b35d |
+mls_range_allowed(security_context_t src, security_context_t dst)
|
|
Tomáš Mráz |
c2b35d |
+{
|
|
Tomáš Mráz |
c2b35d |
+ struct av_decision avd;
|
|
Tomáš Mráz |
c2b35d |
+ int retval;
|
|
Tomáš Mráz |
c2b35d |
+ unsigned int bit = CONTEXT__CONTAINS;
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ retval = security_compute_av(src, dst, SECCLASS_CONTEXT, bit, &avd);
|
|
Tomáš Mráz |
c2b35d |
+ if (retval || ((bit & avd.allowed) != bit))
|
|
Tomáš Mráz |
c2b35d |
+ return 0;
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ return 1;
|
|
Tomáš Mráz |
c2b35d |
+}
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+static int
|
|
Tomáš Mráz |
c2b35d |
+get_user_context(const char *sename, const char *role, const char *lvl,
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t *sc) {
|
|
Tomáš Mráz |
c2b35d |
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Tomáš Mráz |
c2b35d |
+ if (role != NULL && role[0])
|
|
Tomáš Mráz |
c2b35d |
+ return get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
+ else
|
|
Tomáš Mráz |
c2b35d |
+ return get_default_context_with_level(sename, lvl, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
+#else
|
|
Tomáš Mráz |
c2b35d |
+ if (role != NULL && role[0])
|
|
Tomáš Mráz |
c2b35d |
+ return get_default_context_with_role(sename, role, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
+ else
|
|
Tomáš Mráz |
c2b35d |
+ return get_default_context(sename, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
+#endif
|
|
Tomáš Mráz |
c2b35d |
+}
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
/* Return the default security context for the given username */
|
|
Tomáš Mráz |
c2b35d |
static security_context_t
|
|
Tomáš Mráz |
c2b35d |
ssh_selinux_getctxbyname(char *pwname)
|
|
Tomáš Mráz |
c2b35d |
{
|
|
Tomáš Mráz |
c2b35d |
- security_context_t sc = NULL;
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t usersc = NULL;
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t defsc = NULL;
|
|
Tomáš Mráz |
c2b35d |
char *sename, *lvl;
|
|
Tomáš Mráz |
c2b35d |
+ const char *reqlvl;
|
|
Tomáš Mráz |
c2b35d |
char *role = NULL;
|
|
Tomáš Mráz |
c2b35d |
int r = 0;
|
|
Tomáš Mráz |
c2b35d |
+ context_t con = NULL;
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ if (the_authctxt) {
|
|
Tomáš Mráz |
c2b35d |
+ if (the_authctxt->role != NULL) {
|
|
Tomáš Mráz |
c2b35d |
+ char *slash;
|
|
Tomáš Mráz |
c2b35d |
+ role = xstrdup(the_authctxt->role);
|
|
Tomáš Mráz |
c2b35d |
+ if ((slash = strchr(role, '/')) != NULL) {
|
|
Tomáš Mráz |
c2b35d |
+ *slash = '\0';
|
|
Tomáš Mráz |
c2b35d |
+ reqlvl = slash + 1;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
- if (the_authctxt)
|
|
Tomáš Mráz |
c2b35d |
- role=the_authctxt->role;
|
|
Tomáš Mráz |
c2b35d |
#ifdef HAVE_GETSEUSERBYNAME
|
|
Tomáš Mráz |
c2b35d |
if (r=getseuserbyname(pwname, &sename, &lvl) != 0) {
|
|
Tomáš Mráz |
c2b35d |
sename = NULL;
|
|
Tomáš Mráz |
c2b35d |
@@ -72,23 +172,49 @@
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
#else
|
|
Tomáš Mráz |
c2b35d |
sename = pwname;
|
|
Tomáš Mráz |
c2b35d |
- lvl = NULL;
|
|
Tomáš Mráz |
c2b35d |
+ lvl = "";
|
|
Tomáš Mráz |
c2b35d |
#endif
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
if (r == 0) {
|
|
Tomáš Mráz |
c2b35d |
-#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Tomáš Mráz |
c2b35d |
- if (role != NULL && role[0])
|
|
Tomáš Mráz |
c2b35d |
- r = get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
- else
|
|
Tomáš Mráz |
c2b35d |
- r = get_default_context_with_level(sename, lvl, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
-#else
|
|
Tomáš Mráz |
c2b35d |
- if (role != NULL && role[0])
|
|
Tomáš Mráz |
c2b35d |
- r = get_default_context_with_role(sename, role, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
- else
|
|
Tomáš Mráz |
c2b35d |
- r = get_default_context(sename, NULL, &sc);
|
|
Tomáš Mráz |
c2b35d |
-#endif
|
|
Tomáš Mráz |
c2b35d |
+ r = get_user_context(sename, role, lvl, &defsc);
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
+ if (r == 0) {
|
|
Tomáš Mráz |
c2b35d |
+ /* If launched from xinetd, we must use current level */
|
|
Tomáš Mráz |
c2b35d |
+ if (inetd_flag && !rexeced_flag) {
|
|
Tomáš Mráz |
c2b35d |
+ security_context_t sshdsc=NULL;
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ if (getcon(&sshdsc) < 0)
|
|
Tomáš Mráz |
c2b35d |
+ fatal("failed to allocate security context");
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ if ((con=context_new(sshdsc)) == NULL)
|
|
Tomáš Mráz |
c2b35d |
+ fatal("failed to allocate selinux context");
|
|
Tomáš Mráz |
c2b35d |
+ reqlvl = context_range_get(con);
|
|
Tomáš Mráz |
c2b35d |
+ freecon(sshdsc);
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ debug("%s: current connection level '%s'", __func__, reqlvl);
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ if (reqlvl != NULL && reqlvl[0]) {
|
|
Tomáš Mráz |
c2b35d |
+ r = get_user_context(sename, role, reqlvl, &usersc);
|
|
Tomáš Mráz |
c2b35d |
+
|
|
Tomáš Mráz |
c2b35d |
+ if (r == 0) {
|
|
Tomáš Mráz |
c2b35d |
+ if (mls_range_allowed(defsc, usersc)) {
|
|
Tomáš Mráz |
c2b35d |
+ send_audit_message(1, defsc, usersc);
|
|
Tomáš Mráz |
c2b35d |
+ logit("permit MLS level %s (user range %s)", reqlvl, lvl);
|
|
Tomáš Mráz |
c2b35d |
+ } else {
|
|
Tomáš Mráz |
c2b35d |
+ send_audit_message(0, defsc, usersc);
|
|
Tomáš Mráz |
c2b35d |
+ if (security_getenforce() > 0)
|
|
Tomáš Mráz |
c2b35d |
+ fatal("deny MLS level %s (user range %s)", reqlvl, lvl);
|
|
Tomáš Mráz |
c2b35d |
+ else
|
|
Tomáš Mráz |
c2b35d |
+ error("deny MLS level %s (user range %s). Continuing in permissive mode", reqlvl, lvl);
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ freecon(defsc);
|
|
Tomáš Mráz |
c2b35d |
+ } else {
|
|
Tomáš Mráz |
c2b35d |
+ usersc = defsc;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
if (r != 0) {
|
|
Tomáš Mráz |
c2b35d |
switch (security_getenforce()) {
|
|
Tomáš Mráz |
c2b35d |
case -1:
|
|
Tomáš Mráz |
c2b35d |
@@ -110,6 +236,10 @@
|
|
Tomáš Mráz |
c2b35d |
if (lvl != NULL)
|
|
Tomáš Mráz |
c2b35d |
xfree(lvl);
|
|
Tomáš Mráz |
c2b35d |
#endif
|
|
Tomáš Mráz |
c2b35d |
+ if (role != NULL)
|
|
Tomáš Mráz |
c2b35d |
+ xfree(role);
|
|
Tomáš Mráz |
c2b35d |
+ if (con)
|
|
Tomáš Mráz |
c2b35d |
+ context_free(con);
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
return (sc);
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
@@ -157,7 +287,10 @@
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
debug3("%s: setting TTY context on %s", __func__, tty);
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
- user_ctx = ssh_selinux_getctxbyname(pwname);
|
|
Tomáš Mráz |
c2b35d |
+ if (getexeccon(&user_context) < 0) {
|
|
Tomáš Mráz |
c2b35d |
+ error("%s: getexeccon: %s", __func__, strerror(errno));
|
|
Tomáš Mráz |
c2b35d |
+ goto out;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
/* XXX: should these calls fatal() upon failure in enforcing mode? */
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
--- openssh-4.5p1/sshd.c.mls 2007-01-16 21:43:11.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
+++ openssh-4.5p1/sshd.c 2007-01-16 21:48:37.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
@@ -1833,6 +1833,9 @@
|
|
Tomáš Mráz |
c2b35d |
restore_uid();
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
#endif
|
|
Tomáš Mráz |
c2b35d |
+#ifdef WITH_SELINUX
|
|
Tomáš Mráz |
c2b35d |
+ ssh_selinux_setup_exec_context(authctxt->pw->pw_name);
|
|
Tomáš Mráz |
c2b35d |
+#endif
|
|
Tomáš Mráz |
c2b35d |
#ifdef USE_PAM
|
|
Tomáš Mráz |
c2b35d |
if (options.use_pam) {
|
|
Tomáš Mráz |
c2b35d |
do_pam_setcred(1);
|
|
Tomáš Mráz |
c2b35d |
--- openssh-4.5p1/misc.c.mls 2006-08-05 04:39:40.000000000 +0200
|
|
Tomáš Mráz |
c2b35d |
+++ openssh-4.5p1/misc.c 2007-01-16 21:56:40.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
@@ -418,6 +418,7 @@
|
|
Tomáš Mráz |
c2b35d |
colon(char *cp)
|
|
Tomáš Mráz |
c2b35d |
{
|
|
Tomáš Mráz |
c2b35d |
int flag = 0;
|
|
Tomáš Mráz |
c2b35d |
+ int start = 1;
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
if (*cp == ':') /* Leading colon is part of file name. */
|
|
Tomáš Mráz |
c2b35d |
return (0);
|
|
Tomáš Mráz |
c2b35d |
@@ -431,8 +432,13 @@
|
|
Tomáš Mráz |
c2b35d |
return (cp+1);
|
|
Tomáš Mráz |
c2b35d |
if (*cp == ':' && !flag)
|
|
Tomáš Mráz |
c2b35d |
return (cp);
|
|
Tomáš Mráz |
c2b35d |
- if (*cp == '/')
|
|
Tomáš Mráz |
c2b35d |
- return (0);
|
|
Tomáš Mráz |
c2b35d |
+ if (start) {
|
|
Tomáš Mráz |
c2b35d |
+ /* Slash on beginning or after dots only denotes file name. */
|
|
Tomáš Mráz |
c2b35d |
+ if (*cp == '/')
|
|
Tomáš Mráz |
c2b35d |
+ return (0);
|
|
Tomáš Mráz |
c2b35d |
+ if (*cp != '.')
|
|
Tomáš Mráz |
c2b35d |
+ start = 0;
|
|
Tomáš Mráz |
c2b35d |
+ }
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
return (0);
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
--- openssh-4.5p1/session.c.mls 2007-01-16 21:43:11.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
+++ openssh-4.5p1/session.c 2007-01-16 21:46:35.000000000 +0100
|
|
Tomáš Mráz |
c2b35d |
@@ -1347,10 +1347,6 @@
|
|
Tomáš Mráz |
c2b35d |
#endif
|
|
Tomáš Mráz |
c2b35d |
if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
|
|
Tomáš Mráz |
c2b35d |
fatal("Failed to set uids to %u.", (u_int) pw->pw_uid);
|
|
Tomáš Mráz |
c2b35d |
-
|
|
Tomáš Mráz |
c2b35d |
-#ifdef WITH_SELINUX
|
|
Tomáš Mráz |
c2b35d |
- ssh_selinux_setup_exec_context(pw->pw_name);
|
|
Tomáš Mráz |
c2b35d |
-#endif
|
|
Tomáš Mráz |
c2b35d |
}
|
|
Tomáš Mráz |
c2b35d |
|
|
Tomáš Mráz |
c2b35d |
static void
|