|
Jan F |
003cb0 |
diff -up openssh-5.8p1/misc.c.mls openssh-5.8p1/misc.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/misc.c.mls 2011-01-13 02:21:36.000000000 +0100
|
|
Jan F |
003cb0 |
+++ openssh-5.8p1/misc.c 2011-02-12 15:05:06.000000000 +0100
|
|
Jan F |
003cb0 |
@@ -427,6 +427,7 @@ char *
|
|
Jan F. Chadima |
82bc82 |
colon(char *cp)
|
|
Jan F. Chadima |
82bc82 |
{
|
|
Jan F. Chadima |
82bc82 |
int flag = 0;
|
|
Jan F. Chadima |
82bc82 |
+ int start = 1;
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
if (*cp == ':') /* Leading colon is part of file name. */
|
|
Jan F. Chadima |
1b8a26 |
return NULL;
|
|
Jan F |
003cb0 |
@@ -442,6 +443,13 @@ colon(char *cp)
|
|
Jan F. Chadima |
82bc82 |
return (cp);
|
|
Jan F. Chadima |
1b8a26 |
if (*cp == '/')
|
|
Jan F. Chadima |
1b8a26 |
return NULL;
|
|
Jan F. Chadima |
82bc82 |
+ if (start) {
|
|
Jan F. Chadima |
82bc82 |
+ /* Slash on beginning or after dots only denotes file name. */
|
|
Jan F. Chadima |
82bc82 |
+ if (*cp == '/')
|
|
Jan F. Chadima |
82bc82 |
+ return (0);
|
|
Jan F. Chadima |
82bc82 |
+ if (*cp != '.')
|
|
Jan F. Chadima |
82bc82 |
+ start = 0;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
1b8a26 |
return NULL;
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/openbsd-compat/port-linux.c.mls openssh-5.8p1/openbsd-compat/port-linux.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/openbsd-compat/port-linux.c.mls 2011-02-12 15:05:06.000000000 +0100
|
|
Jan F |
003cb0 |
+++ openssh-5.8p1/openbsd-compat/port-linux.c 2011-02-12 15:09:23.000000000 +0100
|
|
Jan F |
003cb0 |
@@ -40,13 +40,164 @@
|
|
Jan F. Chadima |
82bc82 |
#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
82bc82 |
#include <selinux/selinux.h>
|
|
Jan F. Chadima |
82bc82 |
#include <selinux/flask.h>
|
|
Jan F. Chadima |
82bc82 |
+#include <selinux/context.h>
|
|
Jan F. Chadima |
82bc82 |
#include <selinux/get_context_list.h>
|
|
Jan F. Chadima |
82bc82 |
+#include <selinux/get_default_type.h>
|
|
Jan F. Chadima |
82bc82 |
+#include <selinux/av_permissions.h>
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+#ifdef HAVE_LINUX_AUDIT
|
|
Jan F. Chadima |
82bc82 |
+#include <libaudit.h>
|
|
Jan F. Chadima |
82bc82 |
+#include <unistd.h>
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F |
003cb0 |
extern ServerOptions options;
|
|
Jan F. Chadima |
82bc82 |
extern Authctxt *the_authctxt;
|
|
Jan F |
003cb0 |
extern int inetd_flag;
|
|
Jan F |
003cb0 |
extern int rexeced_flag;
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
+/* Send audit message */
|
|
Jan F. Chadima |
82bc82 |
+static int
|
|
Jan F. Chadima |
82bc82 |
+send_audit_message(int success, security_context_t default_context,
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t selected_context)
|
|
Jan F. Chadima |
82bc82 |
+{
|
|
Jan F. Chadima |
82bc82 |
+ int rc=0;
|
|
Jan F. Chadima |
82bc82 |
+#ifdef HAVE_LINUX_AUDIT
|
|
Jan F. Chadima |
82bc82 |
+ char *msg = NULL;
|
|
Jan F. Chadima |
82bc82 |
+ int audit_fd = audit_open();
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t default_raw=NULL;
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t selected_raw=NULL;
|
|
Jan F. Chadima |
82bc82 |
+ rc = -1;
|
|
Jan F. Chadima |
82bc82 |
+ if (audit_fd < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ if (errno == EINVAL || errno == EPROTONOSUPPORT ||
|
|
Jan F |
003cb0 |
+ errno == EAFNOSUPPORT)
|
|
Jan F |
003cb0 |
+ return 0; /* No audit support in kernel */
|
|
Jan F. Chadima |
82bc82 |
+ error("Error connecting to audit system.");
|
|
Jan F. Chadima |
82bc82 |
+ return rc;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (selinux_trans_to_raw_context(default_context, &default_raw) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("Error translating default context.");
|
|
Jan F. Chadima |
82bc82 |
+ default_raw = NULL;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (selinux_trans_to_raw_context(selected_context, &selected_raw) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("Error translating selected context.");
|
|
Jan F. Chadima |
82bc82 |
+ selected_raw = NULL;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (asprintf(&msg, "sshd: default-context=%s selected-context=%s",
|
|
Jan F. Chadima |
82bc82 |
+ default_raw ? default_raw : (default_context ? default_context: "?"),
|
|
Jan F. Chadima |
82bc82 |
+ selected_context ? selected_raw : (selected_context ? selected_context :"?")) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("Error allocating memory.");
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (audit_log_user_message(audit_fd, AUDIT_USER_ROLE_CHANGE,
|
|
Jan F. Chadima |
82bc82 |
+ msg, NULL, NULL, NULL, success) <= 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("Error sending audit message.");
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ rc = 0;
|
|
Jan F. Chadima |
82bc82 |
+ out:
|
|
Jan F. Chadima |
82bc82 |
+ free(msg);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(default_raw);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(selected_raw);
|
|
Jan F. Chadima |
82bc82 |
+ close(audit_fd);
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
+ return rc;
|
|
Jan F. Chadima |
82bc82 |
+}
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+static int
|
|
Jan F. Chadima |
82bc82 |
+mls_range_allowed(security_context_t src, security_context_t dst)
|
|
Jan F. Chadima |
82bc82 |
+{
|
|
Jan F. Chadima |
82bc82 |
+ struct av_decision avd;
|
|
Jan F. Chadima |
82bc82 |
+ int retval;
|
|
Jan F. Chadima |
82bc82 |
+ unsigned int bit = CONTEXT__CONTAINS;
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ debug("%s: src:%s dst:%s", __func__, src, dst);
|
|
Jan F. Chadima |
82bc82 |
+ retval = security_compute_av(src, dst, SECCLASS_CONTEXT, bit, &avd);
|
|
Jan F. Chadima |
82bc82 |
+ if (retval || ((bit & avd.allowed) != bit))
|
|
Jan F. Chadima |
82bc82 |
+ return 0;
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ return 1;
|
|
Jan F. Chadima |
82bc82 |
+}
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+static int
|
|
Jan F. Chadima |
82bc82 |
+get_user_context(const char *sename, const char *role, const char *lvl,
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t *sc) {
|
|
Jan F. Chadima |
82bc82 |
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Jan F. Chadima |
82bc82 |
+ if (lvl == NULL || lvl[0] == '\0' || get_default_context_with_level(sename, lvl, NULL, sc) != 0) {
|
|
Jan F. Chadima |
82bc82 |
+ /* User may have requested a level completely outside of his
|
|
Jan F. Chadima |
82bc82 |
+ allowed range. We get a context just for auditing as the
|
|
Jan F. Chadima |
82bc82 |
+ range check below will certainly fail for default context. */
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
+ if (get_default_context(sename, NULL, sc) != 0) {
|
|
Jan F. Chadima |
82bc82 |
+ *sc = NULL;
|
|
Jan F. Chadima |
82bc82 |
+ return -1;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
+ if (role != NULL && role[0]) {
|
|
Jan F. Chadima |
82bc82 |
+ context_t con;
|
|
Jan F. Chadima |
82bc82 |
+ char *type=NULL;
|
|
Jan F. Chadima |
82bc82 |
+ if (get_default_type(role, &type) != 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("get_default_type: failed to get default type for '%s'",
|
|
Jan F. Chadima |
82bc82 |
+ role);
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ con = context_new(*sc);
|
|
Jan F. Chadima |
82bc82 |
+ if (!con) {
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ context_role_set(con, role);
|
|
Jan F. Chadima |
82bc82 |
+ context_type_set(con, type);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(*sc);
|
|
Jan F. Chadima |
82bc82 |
+ *sc = strdup(context_str(con));
|
|
Jan F. Chadima |
82bc82 |
+ context_free(con);
|
|
Jan F. Chadima |
82bc82 |
+ if (!*sc)
|
|
Jan F. Chadima |
82bc82 |
+ return -1;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Jan F. Chadima |
82bc82 |
+ if (lvl != NULL && lvl[0]) {
|
|
Jan F. Chadima |
82bc82 |
+ /* verify that the requested range is obtained */
|
|
Jan F. Chadima |
82bc82 |
+ context_t con;
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t obtained_raw;
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t requested_raw;
|
|
Jan F. Chadima |
82bc82 |
+ con = context_new(*sc);
|
|
Jan F. Chadima |
82bc82 |
+ if (!con) {
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ context_range_set(con, lvl);
|
|
Jan F. Chadima |
82bc82 |
+ if (selinux_trans_to_raw_context(*sc, &obtained_raw) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ context_free(con);
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (selinux_trans_to_raw_context(context_str(con), &requested_raw) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ freecon(obtained_raw);
|
|
Jan F. Chadima |
82bc82 |
+ context_free(con);
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ debug("get_user_context: obtained context '%s' requested context '%s'",
|
|
Jan F. Chadima |
82bc82 |
+ obtained_raw, requested_raw);
|
|
Jan F. Chadima |
82bc82 |
+ if (strcmp(obtained_raw, requested_raw)) {
|
|
Jan F. Chadima |
82bc82 |
+ /* set the context to the real requested one but fail */
|
|
Jan F. Chadima |
82bc82 |
+ freecon(requested_raw);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(obtained_raw);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(*sc);
|
|
Jan F. Chadima |
82bc82 |
+ *sc = strdup(context_str(con));
|
|
Jan F. Chadima |
82bc82 |
+ context_free(con);
|
|
Jan F. Chadima |
82bc82 |
+ return -1;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ freecon(requested_raw);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(obtained_raw);
|
|
Jan F. Chadima |
82bc82 |
+ context_free(con);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
+ return 0;
|
|
Jan F. Chadima |
82bc82 |
+ out:
|
|
Jan F |
003cb0 |
+ freecon(*sc);
|
|
Jan F |
003cb0 |
+ *sc = NULL;
|
|
Jan F |
003cb0 |
+ return -1;
|
|
Jan F. Chadima |
82bc82 |
+}
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F |
003cb0 |
static void
|
|
Jan F |
003cb0 |
ssh_selinux_get_role_level(char **role, const char **level)
|
|
Jan F |
003cb0 |
{
|
|
Jan F |
003cb0 |
@@ -65,14 +216,16 @@ ssh_selinux_get_role_level(char **role,
|
|
Jan F |
003cb0 |
}
|
|
Jan F |
003cb0 |
|
|
Jan F. Chadima |
82bc82 |
/* Return the default security context for the given username */
|
|
Jan F. Chadima |
82bc82 |
-static security_context_t
|
|
Jan F. Chadima |
82bc82 |
-ssh_selinux_getctxbyname(char *pwname)
|
|
Jan F. Chadima |
82bc82 |
+static int
|
|
Jan F. Chadima |
82bc82 |
+ssh_selinux_getctxbyname(char *pwname,
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t *default_sc, security_context_t *user_sc)
|
|
Jan F. Chadima |
82bc82 |
{
|
|
Jan F |
003cb0 |
security_context_t sc = NULL;
|
|
Jan F. Chadima |
82bc82 |
char *sename, *lvl;
|
|
Jan F |
003cb0 |
char *role;
|
|
Jan F |
003cb0 |
const char *reqlvl;
|
|
Jan F |
003cb0 |
int r = 0;
|
|
Jan F |
003cb0 |
+ context_t con;
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F |
003cb0 |
ssh_selinux_get_role_level(&role, &reqlvl);
|
|
Jan F. Chadima |
82bc82 |
#ifdef HAVE_GETSEUSERBYNAME
|
|
Jan F |
003cb0 |
@@ -82,38 +235,63 @@ ssh_selinux_getctxbyname(char *pwname)
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
#else
|
|
Jan F. Chadima |
82bc82 |
sename = pwname;
|
|
Jan F. Chadima |
82bc82 |
- lvl = NULL;
|
|
Jan F. Chadima |
82bc82 |
+ lvl = "";
|
|
Jan F. Chadima |
82bc82 |
#endif
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
if (r == 0) {
|
|
Jan F. Chadima |
82bc82 |
#ifdef HAVE_GET_DEFAULT_CONTEXT_WITH_LEVEL
|
|
Jan F. Chadima |
82bc82 |
- if (role != NULL && role[0])
|
|
Jan F. Chadima |
82bc82 |
- r = get_default_context_with_rolelevel(sename, role, lvl, NULL, &sc);
|
|
Jan F. Chadima |
82bc82 |
- else
|
|
Jan F. Chadima |
82bc82 |
- r = get_default_context_with_level(sename, lvl, NULL, &sc);
|
|
Jan F. Chadima |
82bc82 |
+ r = get_default_context_with_level(sename, lvl, NULL, default_sc);
|
|
Jan F. Chadima |
82bc82 |
#else
|
|
Jan F. Chadima |
82bc82 |
- if (role != NULL && role[0])
|
|
Jan F. Chadima |
82bc82 |
- r = get_default_context_with_role(sename, role, NULL, &sc);
|
|
Jan F. Chadima |
82bc82 |
- else
|
|
Jan F. Chadima |
82bc82 |
- r = get_default_context(sename, NULL, &sc);
|
|
Jan F. Chadima |
82bc82 |
+ r = get_default_context(sename, NULL, default_sc);
|
|
Jan F. Chadima |
82bc82 |
#endif
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
- if (r != 0) {
|
|
Jan F. Chadima |
82bc82 |
- switch (security_getenforce()) {
|
|
Jan F. Chadima |
82bc82 |
- case -1:
|
|
Jan F. Chadima |
82bc82 |
- fatal("%s: ssh_selinux_getctxbyname: "
|
|
Jan F. Chadima |
82bc82 |
- "security_getenforce() failed", __func__);
|
|
Jan F. Chadima |
82bc82 |
- case 0:
|
|
Jan F. Chadima |
82bc82 |
- error("%s: Failed to get default SELinux security "
|
|
Jan F. Chadima |
82bc82 |
- "context for %s", __func__, pwname);
|
|
Jan F. Chadima |
82bc82 |
- break;
|
|
Jan F. Chadima |
82bc82 |
- default:
|
|
Jan F. Chadima |
82bc82 |
- fatal("%s: Failed to get default SELinux security "
|
|
Jan F. Chadima |
82bc82 |
- "context for %s (in enforcing mode)",
|
|
Jan F. Chadima |
82bc82 |
- __func__, pwname);
|
|
Jan F. Chadima |
82bc82 |
+ if (r == 0) {
|
|
Jan F. Chadima |
82bc82 |
+ /* If launched from xinetd, we must use current level */
|
|
Jan F. Chadima |
82bc82 |
+ if (inetd_flag && !rexeced_flag) {
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t sshdsc=NULL;
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ if (getcon_raw(&sshdsc) < 0)
|
|
Jan F. Chadima |
82bc82 |
+ fatal("failed to allocate security context");
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ if ((con=context_new(sshdsc)) == NULL)
|
|
Jan F. Chadima |
82bc82 |
+ fatal("failed to allocate selinux context");
|
|
Jan F. Chadima |
82bc82 |
+ reqlvl = context_range_get(con);
|
|
Jan F. Chadima |
82bc82 |
+ freecon(sshdsc);
|
|
Jan F. Chadima |
82bc82 |
+ if (reqlvl !=NULL && lvl != NULL && strcmp(reqlvl, lvl) == 0)
|
|
Jan F. Chadima |
82bc82 |
+ /* we actually don't change level */
|
|
Jan F. Chadima |
82bc82 |
+ reqlvl = "";
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ debug("%s: current connection level '%s'", __func__, reqlvl);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ if ((reqlvl != NULL && reqlvl[0]) || (role != NULL && role[0])) {
|
|
Jan F. Chadima |
82bc82 |
+ r = get_user_context(sename, role, reqlvl, user_sc);
|
|
Jan F. Chadima |
82bc82 |
+
|
|
Jan F. Chadima |
82bc82 |
+ if (r == 0 && reqlvl != NULL && reqlvl[0]) {
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t default_level_sc = *default_sc;
|
|
Jan F. Chadima |
82bc82 |
+ if (role != NULL && role[0]) {
|
|
Jan F. Chadima |
82bc82 |
+ if (get_user_context(sename, role, lvl, &default_level_sc) < 0)
|
|
Jan F. Chadima |
82bc82 |
+ default_level_sc = *default_sc;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ /* verify that the requested range is contained in the user range */
|
|
Jan F. Chadima |
82bc82 |
+ if (mls_range_allowed(default_level_sc, *user_sc)) {
|
|
Jan F. Chadima |
82bc82 |
+ logit("permit MLS level %s (user range %s)", reqlvl, lvl);
|
|
Jan F. Chadima |
82bc82 |
+ } else {
|
|
Jan F. Chadima |
82bc82 |
+ r = -1;
|
|
Jan F. Chadima |
82bc82 |
+ error("deny MLS level %s (user range %s)", reqlvl, lvl);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (default_level_sc != *default_sc)
|
|
Jan F. Chadima |
82bc82 |
+ freecon(default_level_sc);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ } else {
|
|
Jan F. Chadima |
82bc82 |
+ *user_sc = *default_sc;
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
+ if (r != 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("%s: Failed to get default SELinux security "
|
|
Jan F. Chadima |
82bc82 |
+ "context for %s", __func__, pwname);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
#ifdef HAVE_GETSEUSERBYNAME
|
|
Jan F. Chadima |
82bc82 |
if (sename != NULL)
|
|
Jan F |
003cb0 |
@@ -121,8 +299,12 @@ ssh_selinux_getctxbyname(char *pwname)
|
|
Jan F. Chadima |
82bc82 |
if (lvl != NULL)
|
|
Jan F. Chadima |
82bc82 |
xfree(lvl);
|
|
Jan F. Chadima |
82bc82 |
#endif
|
|
Jan F |
003cb0 |
-
|
|
Jan F |
003cb0 |
- return (sc);
|
|
Jan F. Chadima |
82bc82 |
+ if (role != NULL)
|
|
Jan F. Chadima |
82bc82 |
+ xfree(role);
|
|
Jan F. Chadima |
82bc82 |
+ if (con)
|
|
Jan F. Chadima |
82bc82 |
+ context_free(con);
|
|
Jan F |
003cb0 |
+
|
|
Jan F. Chadima |
82bc82 |
+ return (r);
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F |
003cb0 |
/* Setup environment variables for pam_selinux */
|
|
Jan F |
003cb0 |
@@ -160,6 +342,8 @@ void
|
|
Jan F. Chadima |
82bc82 |
ssh_selinux_setup_exec_context(char *pwname)
|
|
Jan F. Chadima |
82bc82 |
{
|
|
Jan F |
003cb0 |
security_context_t user_ctx = NULL;
|
|
Jan F. Chadima |
82bc82 |
+ int r = 0;
|
|
Jan F. Chadima |
82bc82 |
+ security_context_t default_ctx = NULL;
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
if (!ssh_selinux_enabled())
|
|
Jan F |
003cb0 |
return;
|
|
Jan F |
003cb0 |
@@ -184,22 +368,45 @@ ssh_selinux_setup_exec_context(char *pwn
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
debug3("%s: setting execution context", __func__);
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
- user_ctx = ssh_selinux_getctxbyname(pwname);
|
|
Jan F. Chadima |
82bc82 |
- if (setexeccon(user_ctx) != 0) {
|
|
Jan F. Chadima |
82bc82 |
+ r = ssh_selinux_getctxbyname(pwname, &default_ctx, &user_ctx);
|
|
Jan F. Chadima |
82bc82 |
+ if (r >= 0) {
|
|
Jan F. Chadima |
82bc82 |
+ r = setexeccon(user_ctx);
|
|
Jan F. Chadima |
82bc82 |
+ if (r < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("%s: Failed to set SELinux execution context %s for %s",
|
|
Jan F. Chadima |
82bc82 |
+ __func__, user_ctx, pwname);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+#ifdef HAVE_SETKEYCREATECON
|
|
Jan F. Chadima |
82bc82 |
+ else if (setkeycreatecon(user_ctx) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("%s: Failed to set SELinux keyring creation context %s for %s",
|
|
Jan F. Chadima |
82bc82 |
+ __func__, user_ctx, pwname);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (user_ctx == NULL) {
|
|
Jan F. Chadima |
82bc82 |
+ user_ctx = default_ctx;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (r < 0 || user_ctx != default_ctx) {
|
|
Jan F. Chadima |
82bc82 |
+ /* audit just the case when user changed a role or there was
|
|
Jan F. Chadima |
82bc82 |
+ a failure */
|
|
Jan F. Chadima |
82bc82 |
+ send_audit_message(r >= 0, default_ctx, user_ctx);
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
+ if (r < 0) {
|
|
Jan F. Chadima |
82bc82 |
switch (security_getenforce()) {
|
|
Jan F. Chadima |
82bc82 |
case -1:
|
|
Jan F. Chadima |
82bc82 |
fatal("%s: security_getenforce() failed", __func__);
|
|
Jan F. Chadima |
82bc82 |
case 0:
|
|
Jan F. Chadima |
82bc82 |
- error("%s: Failed to set SELinux execution "
|
|
Jan F. Chadima |
82bc82 |
- "context for %s", __func__, pwname);
|
|
Jan F. Chadima |
82bc82 |
+ error("%s: SELinux failure. Continuing in permissive mode.",
|
|
Jan F. Chadima |
82bc82 |
+ __func__);
|
|
Jan F. Chadima |
82bc82 |
break;
|
|
Jan F. Chadima |
82bc82 |
default:
|
|
Jan F. Chadima |
82bc82 |
- fatal("%s: Failed to set SELinux execution context "
|
|
Jan F. Chadima |
82bc82 |
- "for %s (in enforcing mode)", __func__, pwname);
|
|
Jan F. Chadima |
82bc82 |
+ fatal("%s: SELinux failure. Aborting connection.",
|
|
Jan F. Chadima |
82bc82 |
+ __func__);
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
- if (user_ctx != NULL)
|
|
Jan F. Chadima |
82bc82 |
+ if (user_ctx != NULL && user_ctx != default_ctx)
|
|
Jan F. Chadima |
82bc82 |
freecon(user_ctx);
|
|
Jan F. Chadima |
82bc82 |
+ if (default_ctx != NULL)
|
|
Jan F. Chadima |
82bc82 |
+ freecon(default_ctx);
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
debug3("%s: done", __func__);
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F |
003cb0 |
@@ -217,7 +424,10 @@ ssh_selinux_setup_pty(char *pwname, cons
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
debug3("%s: setting TTY context on %s", __func__, tty);
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
- user_ctx = ssh_selinux_getctxbyname(pwname);
|
|
Jan F. Chadima |
82bc82 |
+ if (getexeccon(&user_ctx) < 0) {
|
|
Jan F. Chadima |
82bc82 |
+ error("%s: getexeccon: %s", __func__, strerror(errno));
|
|
Jan F. Chadima |
82bc82 |
+ goto out;
|
|
Jan F. Chadima |
82bc82 |
+ }
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F. Chadima |
82bc82 |
/* XXX: should these calls fatal() upon failure in enforcing mode? */
|
|
Jan F. Chadima |
82bc82 |
|
|
Jan F |
003cb0 |
diff -up openssh-5.8p1/sshd.c.mls openssh-5.8p1/sshd.c
|
|
Jan F |
003cb0 |
--- openssh-5.8p1/sshd.c.mls 2011-02-12 15:05:05.000000000 +0100
|
|
Jan F |
003cb0 |
+++ openssh-5.8p1/sshd.c 2011-02-12 15:05:06.000000000 +0100
|
|
Jan F |
003cb0 |
@@ -2011,6 +2011,9 @@ main(int ac, char **av)
|
|
Jan F. Chadima |
82bc82 |
restore_uid();
|
|
Jan F. Chadima |
82bc82 |
}
|
|
Jan F. Chadima |
82bc82 |
#endif
|
|
Jan F. Chadima |
82bc82 |
+#ifdef WITH_SELINUX
|
|
Jan F. Chadima |
82bc82 |
+ ssh_selinux_setup_exec_context(authctxt->pw->pw_name);
|
|
Jan F. Chadima |
82bc82 |
+#endif
|
|
Jan F. Chadima |
82bc82 |
#ifdef USE_PAM
|
|
Jan F. Chadima |
82bc82 |
if (options.use_pam) {
|
|
Jan F. Chadima |
82bc82 |
do_pam_setcred(1);
|