| 9132 | */ |
| 9133 | |
| 9134 | static uint |
| 9135 | kill_one_thread(THD *thd, my_thread_id id, killed_state kill_signal, killed_type type |
| 9136 | #ifdef WITH_WSREP |
| 9137 | , bool &wsrep_high_priority |
| 9138 | #endif |
| 9139 | ) |
| 9140 | { |
| 9141 | THD *tmp; |
| 9142 | uint error= (type == KILL_TYPE_QUERY ? ER_NO_SUCH_QUERY : ER_NO_SUCH_THREAD); |
| 9143 | DBUG_ENTER("kill_one_thread"); |
| 9144 | DBUG_PRINT("enter", ("id: %lld signal: %d", (long long) id, kill_signal)); |
| 9145 | tmp= find_thread_by_id(id, type == KILL_TYPE_QUERY); |
| 9146 | if (!tmp) |
| 9147 | DBUG_RETURN(error); |
| 9148 | DEBUG_SYNC(thd, "found_killee"); |
| 9149 | if (tmp->get_command() != COM_DAEMON) |
| 9150 | { |
| 9151 | /* |
| 9152 | If we're SUPER, we can KILL anything, including system-threads. |
| 9153 | No further checks. |
| 9154 | |
| 9155 | KILLer: thd->security_ctx->user could in theory be NULL while |
| 9156 | we're still in "unauthenticated" state. This is a theoretical |
| 9157 | case (the code suggests this could happen, so we play it safe). |
| 9158 | |
| 9159 | KILLee: tmp->security_ctx->user will be NULL for system threads. |
| 9160 | We need to check so Jane Random User doesn't crash the server |
| 9161 | when trying to kill a) system threads or b) unauthenticated users' |
| 9162 | threads (Bug#43748). |
| 9163 | |
| 9164 | If user of both killer and killee are non-NULL, proceed with |
| 9165 | slayage if both are string-equal. |
| 9166 | |
| 9167 | It's ok to also kill DELAYED threads with KILL_CONNECTION instead of |
| 9168 | KILL_SYSTEM_THREAD; The difference is that KILL_CONNECTION may be |
| 9169 | faster and do a harder kill than KILL_SYSTEM_THREAD; |
| 9170 | */ |
| 9171 | |
| 9172 | mysql_mutex_lock(&tmp->LOCK_thd_data); // Lock from concurrent usage |
| 9173 | |
| 9174 | if ((thd->security_ctx->master_access & PRIV_KILL_OTHER_USER_PROCESS) || |
| 9175 | thd->security_ctx->user_matches(tmp->security_ctx)) |
| 9176 | { |
| 9177 | #ifdef WITH_WSREP |
| 9178 | if (wsrep_thd_is_BF(tmp, false) || tmp->wsrep_applier) |
| 9179 | { |
| 9180 | error= ER_KILL_DENIED_ERROR; |
| 9181 | wsrep_high_priority= true; |
| 9182 | push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, |
| 9183 | ER_KILL_DENIED_ERROR, |
| 9184 | "Thread %lld is %s and cannot be killed", |
| 9185 | tmp->thread_id, |
| 9186 | (tmp->wsrep_applier ? "wsrep applier" : "high priority")); |
| 9187 | } |
| 9188 | else |
| 9189 | { |
| 9190 | if (WSREP(tmp)) |
| 9191 | { |
no test coverage detected