tee: amdtee: fix race condition in amdtee_open_session
authorRijo Thomas <Rijo-john.Thomas@amd.com>
Tue, 28 Feb 2023 09:41:20 +0000 (15:11 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Mar 2023 10:49:29 +0000 (12:49 +0200)
commita63cce9393e4e7dbc5af82dc87e68cb321cb1a78
tree3cb13d4398497ed66d85759f866a23da53076e20
parent8a09fa7be62f5fc499e2713683f7e05a84712b1d
tee: amdtee: fix race condition in amdtee_open_session

commit f8502fba45bd30e1a6a354d9d898bc99d1a11e6d upstream.

There is a potential race condition in amdtee_open_session that may
lead to use-after-free. For instance, in amdtee_open_session() after
sess->sess_mask is set, and before setting:

    sess->session_info[i] = session_info;

if amdtee_close_session() closes this same session, then 'sess' data
structure will be released, causing kernel panic when 'sess' is
accessed within amdtee_open_session().

The solution is to set the bit sess->sess_mask as the last step in
amdtee_open_session().

Fixes: 757cc3e9ff1d ("tee: add AMD-TEE driver")
Cc: stable@vger.kernel.org
Signed-off-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
Acked-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tee/amdtee/core.c