mdt_loader: check for overflow before allocating memory

Memory allocation is happening without checking the overflow.
This could lead to an unexpected results. Check for overflow
before allocating memory.

Change-Id: Icb513ebd8030976e3f0970e9542596f9c5917843
Signed-off-by: Murali Nalajala <quic_mnalajal@quicinc.com>
This commit is contained in:
Murali Nalajala 2022-09-07 17:38:11 -07:00 • committed by Michael Bestas
commit 5886f0dace
No known key found for this signature in database
GPG key ID: CC95044519BE6669

View file

@ -107,6 +107,10 @@ void *qcom_mdt_read_metadata(const struct firmware *fw, size_t *data_len)
ehdr_size = phdrs[0].p_filesz;
hash_size = phdrs[1].p_filesz;
/* Overflow check */
if (ehdr_size > SIZE_MAX - hash_size)
return ERR_PTR(-ENOMEM);
data = kmalloc(ehdr_size + hash_size, GFP_KERNEL);
if (!data)
return ERR_PTR(-ENOMEM);