|
|
ecf709 |
From 944295de4cf4eeba75d4f6bd476a4f59743e1813 Mon Sep 17 00:00:00 2001
|
|
|
ecf709 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
ecf709 |
Date: Thu, 5 Oct 2017 11:07:38 +0200
|
|
|
ecf709 |
Subject: [PATCH 197/197] sysdb: sanitize search filter input
|
|
|
ecf709 |
MIME-Version: 1.0
|
|
|
ecf709 |
Content-Type: text/plain; charset=UTF-8
|
|
|
ecf709 |
Content-Transfer-Encoding: 8bit
|
|
|
ecf709 |
|
|
|
ecf709 |
This patch sanitizes the input for sysdb searches by UPN/email, SID and
|
|
|
ecf709 |
UUID.
|
|
|
ecf709 |
|
|
|
ecf709 |
This security issue was assigned CVE-2017-12173
|
|
|
ecf709 |
|
|
|
ecf709 |
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
|
|
|
ecf709 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
ecf709 |
(cherry picked from commit 1f2662c8f97c9c0fa250055d4b6750abfc6d0835)
|
|
|
ecf709 |
---
|
|
|
ecf709 |
src/db/sysdb_ops.c | 43 +++++++++++++++++++++++++++++++++++--------
|
|
|
ecf709 |
src/tests/sysdb-tests.c | 7 +++++++
|
|
|
ecf709 |
2 files changed, 42 insertions(+), 8 deletions(-)
|
|
|
ecf709 |
|
|
|
ecf709 |
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
|
|
|
ecf709 |
index 7ca6575ce75dab7805236c9f48dbf28a2f3946d2..408af9f389edbe0aff0fb8b96f49f0c4463a620a 100644
|
|
|
ecf709 |
--- a/src/db/sysdb_ops.c
|
|
|
ecf709 |
+++ b/src/db/sysdb_ops.c
|
|
|
ecf709 |
@@ -601,6 +601,7 @@ int sysdb_search_user_by_upn_res(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
int ret;
|
|
|
ecf709 |
const char *def_attrs[] = { SYSDB_NAME, SYSDB_UPN, SYSDB_CANONICAL_UPN,
|
|
|
ecf709 |
SYSDB_USER_EMAIL, NULL };
|
|
|
ecf709 |
+ char *sanitized;
|
|
|
ecf709 |
|
|
|
ecf709 |
tmp_ctx = talloc_new(NULL);
|
|
|
ecf709 |
if (tmp_ctx == NULL) {
|
|
|
ecf709 |
@@ -608,6 +609,12 @@ int sysdb_search_user_by_upn_res(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
+ ret = sss_filter_sanitize(tmp_ctx, upn, &sanitized);
|
|
|
ecf709 |
+ if (ret != EOK) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
|
|
|
ecf709 |
+ goto done;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+
|
|
|
ecf709 |
if (domain_scope == true) {
|
|
|
ecf709 |
base_dn = sysdb_user_base_dn(tmp_ctx, domain);
|
|
|
ecf709 |
} else {
|
|
|
ecf709 |
@@ -620,7 +627,7 @@ int sysdb_search_user_by_upn_res(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
|
|
|
ecf709 |
ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
|
|
|
ecf709 |
base_dn, LDB_SCOPE_SUBTREE, attrs ? attrs : def_attrs,
|
|
|
ecf709 |
- SYSDB_PWUPN_FILTER, upn, upn, upn);
|
|
|
ecf709 |
+ SYSDB_PWUPN_FILTER, sanitized, sanitized, sanitized);
|
|
|
ecf709 |
if (ret != EOK) {
|
|
|
ecf709 |
ret = sysdb_error_to_errno(ret);
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
@@ -4757,17 +4764,31 @@ static errno_t sysdb_search_object_by_str_attr(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
bool expect_only_one_result,
|
|
|
ecf709 |
struct ldb_result **_res)
|
|
|
ecf709 |
{
|
|
|
ecf709 |
- char *filter;
|
|
|
ecf709 |
+ char *filter = NULL;
|
|
|
ecf709 |
errno_t ret;
|
|
|
ecf709 |
+ char *sanitized = NULL;
|
|
|
ecf709 |
|
|
|
ecf709 |
- filter = talloc_asprintf(NULL, filter_tmpl, str);
|
|
|
ecf709 |
+ if (str == NULL) {
|
|
|
ecf709 |
+ return EINVAL;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ ret = sss_filter_sanitize(NULL, str, &sanitized);
|
|
|
ecf709 |
+ if (ret != EOK || sanitized == NULL) {
|
|
|
ecf709 |
+ DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
|
|
|
ecf709 |
+ goto done;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ filter = talloc_asprintf(NULL, filter_tmpl, sanitized);
|
|
|
ecf709 |
if (filter == NULL) {
|
|
|
ecf709 |
- return ENOMEM;
|
|
|
ecf709 |
+ ret = ENOMEM;
|
|
|
ecf709 |
+ goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
ret = sysdb_search_object_attr(mem_ctx, domain, filter, attrs,
|
|
|
ecf709 |
expect_only_one_result, _res);
|
|
|
ecf709 |
|
|
|
ecf709 |
+done:
|
|
|
ecf709 |
+ talloc_free(sanitized);
|
|
|
ecf709 |
talloc_free(filter);
|
|
|
ecf709 |
return ret;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
@@ -4856,7 +4877,8 @@ errno_t sysdb_search_object_by_cert(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
struct ldb_result **res)
|
|
|
ecf709 |
{
|
|
|
ecf709 |
int ret;
|
|
|
ecf709 |
- char *user_filter;
|
|
|
ecf709 |
+ char *user_filter = NULL;
|
|
|
ecf709 |
+ char *filter = NULL;
|
|
|
ecf709 |
|
|
|
ecf709 |
ret = sss_cert_derb64_to_ldap_filter(mem_ctx, cert, SYSDB_USER_MAPPED_CERT,
|
|
|
ecf709 |
NULL, NULL, &user_filter);
|
|
|
ecf709 |
@@ -4865,10 +4887,15 @@ errno_t sysdb_search_object_by_cert(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
return ret;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
- ret = sysdb_search_object_by_str_attr(mem_ctx, domain,
|
|
|
ecf709 |
- SYSDB_USER_CERT_FILTER,
|
|
|
ecf709 |
- user_filter, attrs, false, res);
|
|
|
ecf709 |
+ filter = talloc_asprintf(NULL, SYSDB_USER_CERT_FILTER, user_filter);
|
|
|
ecf709 |
talloc_free(user_filter);
|
|
|
ecf709 |
+ if (filter == NULL) {
|
|
|
ecf709 |
+ return ENOMEM;
|
|
|
ecf709 |
+ }
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ ret = sysdb_search_object_attr(mem_ctx, domain, filter, attrs, false, res);
|
|
|
ecf709 |
+
|
|
|
ecf709 |
+ talloc_free(filter);
|
|
|
ecf709 |
|
|
|
ecf709 |
return ret;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
|
|
|
ecf709 |
index 6ec82ce4ca5c4f918bc9f3144c21f33b270ea47e..588eb9ef02033ec061b4187964fe562da84e86c8 100644
|
|
|
ecf709 |
--- a/src/tests/sysdb-tests.c
|
|
|
ecf709 |
+++ b/src/tests/sysdb-tests.c
|
|
|
ecf709 |
@@ -6444,6 +6444,13 @@ START_TEST(test_upn_basic)
|
|
|
ecf709 |
fail_unless(strcmp(str, UPN_PRINC) == 0,
|
|
|
ecf709 |
"Expected [%s], got [%s].", UPN_PRINC, str);
|
|
|
ecf709 |
|
|
|
ecf709 |
+ /* check if input is sanitized */
|
|
|
ecf709 |
+ ret = sysdb_search_user_by_upn(test_ctx, test_ctx->domain, false,
|
|
|
ecf709 |
+ "abc@def.ghi)(name="UPN_USER_NAME")(abc=xyz",
|
|
|
ecf709 |
+ NULL, &msg;;
|
|
|
ecf709 |
+ fail_unless(ret == ENOENT,
|
|
|
ecf709 |
+ "sysdb_search_user_by_upn failed with un-sanitized input.");
|
|
|
ecf709 |
+
|
|
|
ecf709 |
talloc_free(test_ctx);
|
|
|
ecf709 |
}
|
|
|
ecf709 |
END_TEST
|
|
|
ecf709 |
--
|
|
|
ecf709 |
2.13.5
|
|
|
ecf709 |
|