Skip to content

Commit 98dba58

Browse files
committed
Merge tag 'amdtee-fix-for-v6.3' of https://git.linaro.org/people/jens.wiklander/linux-tee into soc-fixes
AMDTEE fix race condition in amdtee_open_session() * tag 'amdtee-fix-for-v6.3' of https://git.linaro.org/people/jens.wiklander/linux-tee: tee: amdtee: fix race condition in amdtee_open_session Link: https://lore.kernel.org/r/Y/5ZGX0lSTnZz27E@rayden Signed-off-by: Arnd Bergmann <[email protected]>
2 parents fe15c26 + f8502fb commit 98dba58

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

drivers/tee/amdtee/core.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,35 +267,34 @@ int amdtee_open_session(struct tee_context *ctx,
267267
goto out;
268268
}
269269

270+
/* Open session with loaded TA */
271+
handle_open_session(arg, &session_info, param);
272+
if (arg->ret != TEEC_SUCCESS) {
273+
pr_err("open_session failed %d\n", arg->ret);
274+
handle_unload_ta(ta_handle);
275+
kref_put(&sess->refcount, destroy_session);
276+
goto out;
277+
}
278+
270279
/* Find an empty session index for the given TA */
271280
spin_lock(&sess->lock);
272281
i = find_first_zero_bit(sess->sess_mask, TEE_NUM_SESSIONS);
273-
if (i < TEE_NUM_SESSIONS)
282+
if (i < TEE_NUM_SESSIONS) {
283+
sess->session_info[i] = session_info;
284+
set_session_id(ta_handle, i, &arg->session);
274285
set_bit(i, sess->sess_mask);
286+
}
275287
spin_unlock(&sess->lock);
276288

277289
if (i >= TEE_NUM_SESSIONS) {
278290
pr_err("reached maximum session count %d\n", TEE_NUM_SESSIONS);
291+
handle_close_session(ta_handle, session_info);
279292
handle_unload_ta(ta_handle);
280293
kref_put(&sess->refcount, destroy_session);
281294
rc = -ENOMEM;
282295
goto out;
283296
}
284297

285-
/* Open session with loaded TA */
286-
handle_open_session(arg, &session_info, param);
287-
if (arg->ret != TEEC_SUCCESS) {
288-
pr_err("open_session failed %d\n", arg->ret);
289-
spin_lock(&sess->lock);
290-
clear_bit(i, sess->sess_mask);
291-
spin_unlock(&sess->lock);
292-
handle_unload_ta(ta_handle);
293-
kref_put(&sess->refcount, destroy_session);
294-
goto out;
295-
}
296-
297-
sess->session_info[i] = session_info;
298-
set_session_id(ta_handle, i, &arg->session);
299298
out:
300299
free_pages((u64)ta, get_order(ta_size));
301300
return rc;

0 commit comments

Comments
 (0)