Blame SOURCES/0012-sudo-always-use-srv_opts-from-id-context.patch

9f2ebf
From 7738a74e6878536e155d9d589e7ec727c135f5a0 Mon Sep 17 00:00:00 2001
5e7617
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
5e7617
Date: Thu, 19 Oct 2017 10:39:21 +0200
9f2ebf
Subject: [PATCH 12/21] sudo: always use srv_opts from id context
5e7617
5e7617
Prior this patch, we remember id_ctx->srv_opts in sudo request to switch
5e7617
the latest usn values. This works fine most of the time but it may cause
5e7617
a crash.
5e7617
5e7617
If we have two concurrent sudo refresh and one of these fails, it causes
5e7617
failover to try the next server and possibly replacing the old srv_opts
5e7617
with new one and it causes an access after free in the other refresh.
5e7617
5e7617
Resolves:
5e7617
https://pagure.io/SSSD/sssd/issue/3562
5e7617
5e7617
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
5e7617
(cherry picked from commit 2ee201dcf6bbe52abbbed3c2fc4c35ca2e0c8a43)
5e7617
---
5e7617
 src/providers/ldap/sdap_async_sudo.c | 7 +------
5e7617
 1 file changed, 1 insertion(+), 6 deletions(-)
5e7617
5e7617
diff --git a/src/providers/ldap/sdap_async_sudo.c b/src/providers/ldap/sdap_async_sudo.c
5e7617
index 3c69837fda313b2645c3a8497252670312f600ea..88a387422d5c9ae86cea583bb38dadf90cba37f3 100644
5e7617
--- a/src/providers/ldap/sdap_async_sudo.c
5e7617
+++ b/src/providers/ldap/sdap_async_sudo.c
5e7617
@@ -279,7 +279,6 @@ done:
5e7617
 struct sdap_sudo_refresh_state {
5e7617
     struct sdap_sudo_ctx *sudo_ctx;
5e7617
     struct tevent_context *ev;
5e7617
-    struct sdap_server_opts *srv_opts;
5e7617
     struct sdap_options *opts;
5e7617
     struct sdap_id_op *sdap_op;
5e7617
     struct sysdb_ctx *sysdb;
5e7617
@@ -405,9 +404,6 @@ static void sdap_sudo_refresh_connect_done(struct tevent_req *subreq)
5e7617
 
5e7617
     DEBUG(SSSDBG_TRACE_FUNC, "SUDO LDAP connection successful\n");
5e7617
 
5e7617
-    /* Obtain srv_opts here in case of first connection. */
5e7617
-    state->srv_opts = state->sudo_ctx->id_ctx->srv_opts;
5e7617
-
5e7617
     /* Renew host information if needed. */
5e7617
     if (state->sudo_ctx->run_hostinfo) {
5e7617
         subreq = sdap_sudo_get_hostinfo_send(state, state->opts,
5e7617
@@ -586,7 +582,6 @@ static void sdap_sudo_refresh_done(struct tevent_req *subreq)
5e7617
         goto done;
5e7617
     }
5e7617
 
5e7617
-
5e7617
     /* start transaction */
5e7617
     ret = sysdb_transaction_start(state->sysdb);
5e7617
     if (ret != EOK) {
5e7617
@@ -621,7 +616,7 @@ static void sdap_sudo_refresh_done(struct tevent_req *subreq)
5e7617
     /* remember new usn */
5e7617
     ret = sysdb_get_highest_usn(state, rules, rules_count, &usn;;
5e7617
     if (ret == EOK) {
5e7617
-        sdap_sudo_set_usn(state->srv_opts, usn);
5e7617
+        sdap_sudo_set_usn(state->sudo_ctx->id_ctx->srv_opts, usn);
5e7617
     } else {
5e7617
         DEBUG(SSSDBG_MINOR_FAILURE, "Unable to get highest USN [%d]: %s\n",
5e7617
               ret, sss_strerror(ret));
5e7617
-- 
9f2ebf
2.13.5
5e7617