AMDTEE fix race condition in amdtee_open_session()

-----BEGIN PGP SIGNATURE-----
 
 iQJOBAABCgA4FiEEFV+gSSXZJY9ZyuB5LinzTIcAHJcFAmP+V3waHGplbnMud2lr
 bGFuZGVyQGxpbmFyby5vcmcACgkQLinzTIcAHJfm2Q//fvm7SE3yphSez9Q+HTk/
 ahGxSypDLZyTGSR+iiS0QPvSfDWQzvZnBcJeRxxwgfT8JJiK1VJmP9Jpn5X0lnyM
 8fLPR/GK7AzjxA+YQXF1HCyvoYYWCPb9SfaxLeSQDv1fL3yqh3AbKfUr7C7fU+zd
 0wMa/tWydEWpVNEx/D61/XB28HAtDWx4LZJl5mQQqkT7PA5EdwlpWNjmZFwAxNuA
 5ixitcpmykIDSEpPhgwcdKPcTewXtS2U08L6jAcE/SoPdhOqDm+6n0UElB4SBPQa
 g6bUhIq6CMeIYdiXZ6D9g9oTQX8AgLbI4iLogAIY0wuJ6MFFk3CLP0E76FXO3VkR
 HH8ZYV1jJsXC4YOvPUKHyKNY0PIlPPBTPrS+1EHJDDyU5+ERMLw4LeEdqicpNKta
 RCQ4bb5shx+aeXMFEmNLU5tsXhK9s4v3QPGWY+zYwNBmpKtRwiNOanJAUlOlB4RF
 FVGVHMr3xn6QWsocus0F72kO3uHfeFur/pcQwF0Jegz7ymjgskUws6MC+SGDGbJ9
 gDxW74UxaneMCr+xsCXEDYR0jm7iHjLFE5UU7qBvOx0hmMDzrvmPnav8cDXbe3O9
 jS+JiotIteLVSVg65qe2sZZtAn9ZuI5KfjX8rh/W/dlYHJVLeLEVEEQnObuUdyNy
 6Fm8gz1fe3+zjFA14x6JeF8=
 =y1W1
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEo6/YBQwIrVS28WGKmmx57+YAGNkFAmQUeYcACgkQmmx57+YA
 GNmlBg/9GZGQesElPBTwFk63/jJ9Y9Vd2WsTeCQUYull3keByTJlEZSVulZE0teo
 xY+nQ8e1YTxpCGqYrdTaTbmcbRcLhLS2HhUVLR1TzoGygiG5SYfoYwsu67L5oRYQ
 lQZU67sjYY4L1KrH6HnTqww2hPHpiiEhESYlp5shI4WtfCTn6QyJluC+ZSMHGLED
 MmVXbdoEOfxvefw4Nvy9thJ8cMWaM74nCGOgSWEHfNPHpcGEqVUEIy4MqTJCU+B1
 u2oDZN52LmvUgnHbgquGmuv14oFT9ZnjTF9ddyKrhxs2ts8LgEl/qYp+8AsmP2KM
 D/CkRikZCWPbhy8hRJGMp4d8INlBaH+k1fsQeRbljYCp5LHsVUXLQVFiRqR4+RdX
 WZhSgs768cJwJG0EDQwycOahbzUkdIqXfWmHhyS7b5RWGwULHl1thW+TT0o+O96v
 aZDUuaKj5/ylTmbyHKOMkpOQuYjlPm40YsdJNUxL5ZI8WBwa691L07UA2vcFcwrl
 jo2T3mBovAYxWMEysOQYez2lEsqtvUmpzfTKdcvDFgSSzSeGhftGbmJsJ/K00qmz
 wiPTfYLWNBBjAdYFZWr+nDiTHjUMA+/sdvUvl5823tGGUU35xNp81X1Q6tDJ+3ly
 p3RMF9wWa8TE0fwBrIjAwn/vIbYfJRA+3J8XcZl/DHW8xMASOB4=
 =tSWI
 -----END PGP SIGNATURE-----

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 <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2023-03-17 15:30:24 +01:00
Родитель fe15c26ee2 f8502fba45
Коммит 98dba5886b
1 изменённых файлов: 14 добавлений и 15 удалений

Просмотреть файл

@ -267,35 +267,34 @@ int amdtee_open_session(struct tee_context *ctx,
goto out;
}
/* Open session with loaded TA */
handle_open_session(arg, &session_info, param);
if (arg->ret != TEEC_SUCCESS) {
pr_err("open_session failed %d\n", arg->ret);
handle_unload_ta(ta_handle);
kref_put(&sess->refcount, destroy_session);
goto out;
}
/* Find an empty session index for the given TA */
spin_lock(&sess->lock);
i = find_first_zero_bit(sess->sess_mask, TEE_NUM_SESSIONS);
if (i < TEE_NUM_SESSIONS)
if (i < TEE_NUM_SESSIONS) {
sess->session_info[i] = session_info;
set_session_id(ta_handle, i, &arg->session);
set_bit(i, sess->sess_mask);
}
spin_unlock(&sess->lock);
if (i >= TEE_NUM_SESSIONS) {
pr_err("reached maximum session count %d\n", TEE_NUM_SESSIONS);
handle_close_session(ta_handle, session_info);
handle_unload_ta(ta_handle);
kref_put(&sess->refcount, destroy_session);
rc = -ENOMEM;
goto out;
}
/* Open session with loaded TA */
handle_open_session(arg, &session_info, param);
if (arg->ret != TEEC_SUCCESS) {
pr_err("open_session failed %d\n", arg->ret);
spin_lock(&sess->lock);
clear_bit(i, sess->sess_mask);
spin_unlock(&sess->lock);
handle_unload_ta(ta_handle);
kref_put(&sess->refcount, destroy_session);
goto out;
}
sess->session_info[i] = session_info;
set_session_id(ta_handle, i, &arg->session);
out:
free_pages((u64)ta, get_order(ta_size));
return rc;