Commit graph

70 commits

Author SHA1 Message Date
Zhen Kong
058a10e330 qseecom: fix kclient free issue in qseecom_remove
Remove kzfree() after kclient list iteration to avoid invalid
pointer deference.

Change-Id: I78922269e219fcb16d3cff05f8b168a75a3c05ae
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2018-09-24 11:35:44 -07:00
Monika Singh
ed7b89c970 ARM: dts: msm: Untrusted pointer dereference
To avoid access of variable after being freed, using
list_first_entry_safe function to iterate over list
of given type, safe against removal of list entry.

Change-Id: I70611fddf3e9b80b1affa3e5235be24eac0d0a58
Signed-off-by: Monika Singh <monising@codeaurora.org>
2018-06-18 22:20:55 -07:00
Zhen Kong
4aa1034bf7 qseecom: fix issues when processing blocked listener request
When processing blocked listener request, ptr_app's app_blocked
flag should be set to prevent it being unloaded at this time;
Besides, need to check unblock request's scm_call response result
to see if it is blocked again; and removed redundant codes.

Change-Id: I2d72a88e9e600d6b7e944ae978b9d89a7b6db242
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2018-04-06 12:42:51 -07:00
Zhen Kong
b3ba6ffa2c qseecom: block system signals when waiting for listener available
Make change to block system signals when qseecom is waiting for
a blocked listener becomes available. This will prevent qseecom
being waken up by power collapse and returning to kernel, which
may cause XPU violation as TA req/resp buffer is still XPU protected
at this time

Change-Id: Ie5ea16f11ad653937236de042afb1bb5710123e6
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2018-04-06 12:42:38 -07:00
Zhen Kong
0a2d725d48 qseecom: resend continue blocked listener request
When new cmd with session_id is not supported by TZ, resend
continue blocked listener request with legacy cmd using app_id.
Also set dummy app_id in qseecom_process_listener_from_smcinvoke
to support legacy cmd.

Change-Id: Icafc77cece23daff0f2ceb89c10e82a822eb582a
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-12-18 13:59:20 -08:00
Linux Build Service Account
02a73d4553 Merge "qseecom: support listener request from smcinvoke without reentrancy" 2017-12-16 00:56:46 -08:00
Zhen Kong
f20c33ce06 qseecom: support listener request from smcinvoke without reentrancy
Add support to process listener request from smcinvoke when
reentrancy is disabled.

Change-Id: I2ce030cf6d5104ca2dec1402634a05d425e6d474
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-12-15 15:26:57 -08:00
Zhen Kong
6348962fc5 qseecom: fix an issue when requested listener svc id does not exist
When listener svc id does not exist, the listener svc entry pointer
is actualy invalid, and should be set to NULL to avoid invalid pointer
deference on cache operation when sending listener resp to TZ.

Change-Id: I6af0c7405c9dc5dfe481396979023968a8324dd0
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-12-15 13:48:24 -08:00
Linux Build Service Account
501a8de7b6 Merge "qseecom: fix a race condition when TA is blocked" 2017-12-03 09:32:20 -08:00
Linux Build Service Account
96081867a4 Merge "qseecom: fix a common lib loading issue" 2017-12-03 09:32:19 -08:00
Zhen Kong
69fb586ddb qseecom: fix a race condition when TA is blocked
When the thread processing blocked TA wakes up when listener
becames available, the listener may be unavailable again before
this thread grabs the global mutex, so make change to add a
while loop to check if listener available after wake up and hold
mutex.

Change-Id: Ib386faca7a44325142da1dc54e19a99f3173ec86
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-12-02 08:25:16 -08:00
Zhen Kong
6fadad98bf qseecom: fix a common lib loading issue
cmnlib_ion_handle is only used within qseecom_load_commonlib_image()
and is not a shared resource, so change it to a local variable and
avoid potential reuse or free by another thread in case of reentrancy.

Change-Id: I9e1f25cd024a19a7379b7409bdc6521bcd8bcae5
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-12-02 08:17:10 -08:00
Zhen Kong
db3336d536 qseecom: fix an app unloading issue when the app is blocked
Reset app_crash flag to make sure app entry is not freed when
there is another client still being blocked on the same app.

Change-Id: I25d236abc97e60fe8a4abbbc8c086291c764a9c1
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-12-02 08:02:10 -08:00
Zhen Kong
ec74a9da86 qseecom: check return value of __qseecom_process_reentrancy
make change to check return value of __qseecom_process_reentrancy,
and modify error processing.

Change-Id: I6a37de79f6c6b4245b9654ea9724b51e62b8e7a2
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-09-25 12:50:47 -07:00
Linux Build Service Account
a9009e8dd5 Merge "qcom: scm: update function return value and input parameter type" 2017-08-03 10:07:53 -07:00
Amit Blay
3d4f53fccc misc: qseecom: Support qseecom deferred probing
During qseecom driver probing, the ION driver is invoked.
This commit supports the case where the ION driver still hasn't
probed. In that case, the qseecom probing will be deferred, and
retried at a later stage.

Change-Id: Ic780e8fa1d48a9f5b8b98773c034b280475f5fd0
Signed-off-by: Amit Blay <ablay@codeaurora.org>
2017-07-25 00:42:09 -07:00
Mohammed Khajapasha
18ae33111d qcom: scm: update function return value and input parameter type
Update the function return value and input scm_ret variable
type for restore secure configuration in scm_restore_sec_cfg() fn.
Adding scm_ret input variable for scm_get_feat_version() fn.  

Change-Id: Ideef914ded8dfdb4c780fd27d7273986eeb41f5c
Signed-off-by: Mohammed Khajapasha <mkhaja@codeaurora.org>
2017-07-19 14:22:44 +05:30
Zhen Kong
7293d203cf qseecom: update on smcinvoke-aware listeners operations
With the introduction of MinkIPC for TA-to-TA communication,
if a request for blocking a TA (on a busy listener) is received
by qseecom, it may not be originated from the last TA to which
a command (or unblock response) was sent to. So, make change
to use a session_id instead of app_id to uniquely identify this
blocked request and a new cmd ID to support this smcinvoke-aware
listener operation.

Change-Id: I362e9acfa52c055b5759c210bb881da40f4e0776
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-07-17 13:40:31 -07:00
Zhen Kong
70ca7ca60d qseecom: use strnlen in qseecom_start_app
The appname received by qseecom_start_app() can be non-null terminated
string beyond the max size check. Change strlen to strnlen.

CRs-fixed: 2062061
Change-Id: I845d244336b5c81cedb2153d1303585f16819d58
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-06-20 16:16:26 -07:00
Brahmaji K
ed85b5e79f qseecom: Fix accessing userspace memory in kernel space
Use put_user API to write the data from kernel space to
userspace to avoid accessing userspace memory directly
in kernel space.

Change-Id: I649fe2597e80ccad50cf16b355e220734810e94c
Signed-off-by: Brahmaji K <bkomma@codeaurora.org>
2017-06-12 04:01:36 -07:00
Zhen Kong
465314f803 qseecom: fix listener unregistration issue
When listener unregister thread wakes up due to some system signals,
but not because ioctl_cnt <=1, it should return directly, instead of
continuing to remove listener list entry, which will lead kernel panic
when another listener receive thread accesses this freed entry.

Change-Id: I6ff97c56867d008232d7c50b22b372b0856c8dff
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-06-01 16:04:19 -07:00
Zhen Kong
c5d33082ab qseecom: add bus scaling support for GP operations
When a GP application is loaded and the crypto engine is accessed,
a NOC error will happen if CE clock is not enabled. Thus, add bus
scaling support for GP operations.

Change-Id: I59d63be9e08b2c135edc6ec224ec1a355434e1ec
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-05-11 14:54:54 -07:00
Brahmaji K
95f0e29530 qseecom: Initialize the hlos_ce_hw_instance array
Initialize the hlos_ce_hw_instance[] array otherwise
this can lead to assigning qseecom.ce_drv.instance
with garbage value in failure cases.

Change-Id: I5b8fb574468a6a09fcd0f7f1dc7caf11f31374a7
Signed-off-by: Brahmaji K <bkomma@codeaurora.org>
2017-05-08 11:56:00 +05:30
Zhen Kong
9f290f6e79 qseecom: check img_len and mdt_len against ion buf len
Variable "load_img_req.img_len" and "load_img_req.mdt_len" are
from user land, so check their values against ion buf length
to avoid buffer overread on QSEE side.

Change-Id: I9e8bfe32d3b0cd5b441ad724543c56467fa5e4da
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-03-21 09:55:54 -07:00
Zhen Kong
c83a067a9a qseecom: return app_id correctly when looking up and loading app
When __qseecom_check_app_exsits() and __qseecom_load_fw() get app_id
from TZ, they save it to function's return value then return back.
But "app_id" is of type uint32, "ret" is int32, this will return
incorrect app_id to the caller if app_id is larger than 0x7FFFFFFF.
Thus make change to return app_id correctly.

Change-Id: I2ef98d64490c480d5416ee24ec6ca9aca9c8ca8a
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-03-07 15:29:38 -08:00
Zhen Kong
364643660e qseecom: add mutex around qseecom_set_client_mem_param
Add mutex around qseecom_set_client_mem_param to prevent an
ioctl thread modifying and corrupting data which is being
processed by another ioctl in the other thread

Change-Id: I0cfb8afab4001c2913be693dfe44c761b9568893
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-02-27 13:45:03 -08:00
Linux Build Service Account
66bdfb7e6d Merge "qseecom: add new SCM ID to register listener when smcinvoke is supported" 2017-02-15 17:01:15 -08:00
Zhen Kong
3f3f20e347 qseecom: add new SCM ID to register listener when smcinvoke is supported
Add new SCM ID to register listener when smcinvoke is supported. Then
TZ, depending on how the listener has been registered, will either
behave in the old way (i.e. rsp[1]=QSEE_LISTENER_ID), or the new way
(rsp[1]=app_id) when smcinvoke is supported. And qseecom will first
to register listener with new SCM ID, if failed, then fallback to
use old ID.

Change-Id: Ia27055db6ec8f26705669ee913919b29461121ca
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-02-14 15:32:19 -08:00
Zhen Kong
3f13257ff6 qseecom: add additonal reentrancy check before scm call
scm call of send data will fail with EBUSY if there are more than one
TAs requesting listener services, add additional checks before scm call
and wait until no more than one listener request in the system.

Change-Id: Ic891e687062dc52f02639605f3bac0e1c4540a6f
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-02-03 18:08:22 -08:00
Linux Build Service Account
9b0b7adacb Merge "qseecom: release memory when failed to get fw size" 2017-01-21 05:01:22 -08:00
Zhen Kong
d250be844b qseecom: release memory when failed to get fw size
release app list entry when __qseecom_get_fw_size() returns error.

Change-Id: I82406c39a2def87395811f442f39b57201766091
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-01-20 12:24:30 -08:00
Linux Build Service Account
9e318a7a45 Merge "qseecom: improve input validatation for qseecom_send_service_cmd" 2017-01-13 17:02:53 -08:00
Zhen Kong
b108c651ca qseecom: improve input validatation for qseecom_send_service_cmd
Make change to improve input validation on request and response
buffers' address and length for qseecom_send_service_cmd.

Change-Id: I047e3264333d767541e43b7dadd1727232fd48ef
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-01-12 17:18:24 -08:00
Zhen Kong
0963c07e9f qseecom: fix potential memory leak in __qseecom_update_cmd_buf_64
__qseecom_update_cmd_buf_64() called __qseecom_allocate_sg_list_buffer()
to allocate memory from within a for loop. Should it fail on any other
than the first time through the loop, the prior allocations will not be
deallocated, make change to deallocate memory in this error case.

Change-Id: I8cb71a3b141249d8266aec4890632f200d147405
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2017-01-10 13:14:10 -08:00
AnilKumar Chimata
ecbe2e6f80 qseecom: Rename clock handle names
Rename clock handles as per de-initialization sequence,
which is required to avoid the dangling pointers.

Change-Id: I9e0715e2a47f318acc414605ce8e624c432d6665
Signed-off-by: AnilKumar Chimata <anilc@codeaurora.org>
2017-01-05 15:27:00 +05:30
Linux Build Service Account
9a312e1092 Merge "qseecom: support listener request for smcinvoke" 2016-12-23 03:55:32 -08:00
Zhen Kong
c9153d1ae8 qseecom: support listener request for smcinvoke
Add a new kernel API to support listener service for smcinvoke.

Change-Id: Ifeed957b99d2becd986629f60e145d6fdb717244
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-12-22 17:54:34 -08:00
Brahmaji K
6b7232dc91 msm-3.18: drivers : added validation of input/output buffer sizes
This change fixes issues reagrding the ioctl
QSEECOM_IOCTL_MDTP_CIPHER_DIP_REQ uncovered by fuzzy tests.
Modified handler of above ioctl, not to allow input/output
buffer sizes greater than a fixed defined size.

Change-Id: I69f94a29d939341564f6f3ebfda48fceaa934542
Signed-off-by: Brahmaji K <bkomma@codeaurora.org>
2016-12-19 22:25:39 -08:00
Andrey Markovytch
309430921f qseecom: add configurable encryption key size
ICE crypto engine key size can now be configured using dtsi flag.
This is required to facilitate usage of common TZ image with variable
key sizes and also provides flexibility in handling different key sizes
requirement in future. This flag is parsed in driver and depending upon
the value HLOS decides on key size to be passed to TZ.

Change-Id: If40f83a943e5ae8333d171c21823a16816d7ddd4
Signed-off-by: Neeraj Soni <neersoni@codeaurora.org>
Signed-off-by: Andrey Markovytch <andreym@codeaurora.org>
2016-12-13 06:18:03 -08:00
Zhen Kong
ca828152be qseecom: fix incomplete error handling for several functions
Perform a complete or adequate check of return codes for several
functions, including __qseecom_enable_clk, ion_do_cache_op and
ion_sg_table(), used by qseecom.

Change-Id: Ib1682bdc6d3034a22586af62a3d8986c54d369d5
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-11-28 12:32:06 -08:00
Zhen Kong
268b994d27 qseecom: improve error checks in qseecom_probe()
Make change in qseecom_probe() to improve the error return value
checks on some subfunctions, and free memory allocated within
qseecom_retrieve_ce_data.

CRs-fixed: 1075082
Change-Id: I971e555ec8d02ccf4382e83132a696b065a8ff12
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-11-16 10:21:28 -08:00
Linux Build Service Account
26ef63d686 Merge "qseecom: remove entry from qseecom_registered_app_list" 2016-11-10 15:14:23 -08:00
Zhen Kong
420d51e073 qseecom: remove entry from qseecom_registered_app_list
In an error handling case, the QSEECOM_IOCTL_LOAD_APP_REQ ioctl
freed the entry for new TA, but didn't removed it from
qseecom_registered_app_list. Make change to remove it.

Change-Id: Id681fbf3c923027d3db875d506cbe3f971919a8d
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-11-04 17:45:05 -07:00
Zhen Kong
49da28a571 qseecom: whitelist support for kernel client and listener
-- Add whitelist support for listener to send modified resp to TZ;
-- support whitelist for kernel client;
-- Change the method to check whitelist feature.

Change-Id: I0030b0008d6224cda3fdc1f80308a7e9bcfe4405
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-11-03 10:14:36 -07:00
Zhen Kong
8af0e6f36a qseecom: check error return value of ion_map_kernel
ion_map_kernel() is called without checking for or acting upon the
possible error conditions this function may return, make change to
check its error return value.

CRs-fixed: 1081637
Change-Id: I0a34f0bbc9f2049b826777a31e14d2cf62cdc211
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-10-28 10:31:02 -07:00
Zhen Kong
ecd28536e3 qseecom: check buffer size when loading firmware images
Make change in __qseecom_load_fw() and qseecom_load_commonlib_image()
to check buffer size before copying img to buffer.

CRs-fixed: 1080290
Change-Id: I0f48666ac948a9571e249598ae7cc19df9036b1d
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-10-26 15:58:38 -07:00
Zhen Kong
12f9041489 qseecom: Change whitelist_support flag to false if TZ failed to check
The whitelist status is set default as true though TZ failed to check,
which in turn causing the send_command fail by passing whitelist commnd id.
So updating the support status flag to false when TZ fails to check.

Change-Id: I78a7600506b4d2457bb1c38f8a39888a9cf9467c
Signed-off-by: Mallikarjuna Reddy Amireddy <mamire@codeaurora.org>
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-09-15 10:49:14 -07:00
Linux Build Service Account
9b82a4c589 Merge "qseecom: allocate sglistinfo buffer for kernel clients" 2016-09-13 05:43:56 -07:00
Linux Build Service Account
90d089418c Merge "qseecom: improve listener resp processing if app is blocked" 2016-09-02 13:52:32 -07:00
Zhen Kong
bde23716c3 qseecom: allocate sglistinfo buffer for kernel clients
To support whitelist feature, sglistinfo table should also
be allocated from qseecom kernel APIs used by kernel client.
Besides, initialize sg in __qseecom_update_cmd_buf_64 to
address a static analysis warning.

Change-Id: I1f1967fd9e95444cca728f09e3e8f4914b2abb95
Signed-off-by: Zhen Kong <zkong@codeaurora.org>
2016-09-02 09:40:05 -07:00