Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f1f6773 authored by Gaurav Kohli's avatar Gaurav Kohli Committed by Gerrit - the friendly Code Review server
Browse files

soc: qcom: pil: Clear elf region on authentication failure



In existing implementation elf region was being cleared before memory
access to firmware region assigned to HLOS. Avoid this by using
separate function which will be called only when HLOS is the owner.

Change-Id: I8bb22e4dbe3e1f898678d0c0f6e60268b88fc150
Signed-off-by: default avatarGaurav Kohli <gkohli@codeaurora.org>
Signed-off-by: default avatarSrinivasarao P <spathi@codeaurora.org>
parent 48712d92
Loading
Loading
Loading
Loading
+32 −8
Original line number Diff line number Diff line
/* Copyright (c) 2010-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -579,6 +579,13 @@ static int pil_init_mmap(struct pil_desc *desc, const struct pil_mdt *mdt)
	return pil_init_entry_addr(priv, mdt);
}

struct pil_map_fw_info {
	void *region;
	struct dma_attrs attrs;
	phys_addr_t base_addr;
	struct device *dev;
};

static void pil_release_mmap(struct pil_desc *desc)
{
	struct pil_priv *priv = desc->priv;
@@ -597,15 +604,31 @@ static void pil_release_mmap(struct pil_desc *desc)
	}
}

#define IOMAP_SIZE SZ_1M
static void pil_clear_segment(struct pil_desc *desc)
{
	struct pil_priv *priv = desc->priv;
	u8 __iomem *buf;

struct pil_map_fw_info {
	void *region;
	struct dma_attrs attrs;
	phys_addr_t base_addr;
	struct device *dev;
	struct pil_map_fw_info map_fw_info = {
		.attrs = desc->attrs,
		.region = priv->region,
		.base_addr = priv->region_start,
		.dev = desc->dev,
	};

	void *map_data = desc->map_data ? desc->map_data : &map_fw_info;

	/* Clear memory so that unauthorized ELF code is not left behind */
	buf = desc->map_fw_mem(priv->region_start, (priv->region_end -
					priv->region_start), map_data);
	pil_memset_io(buf, 0, (priv->region_end - priv->region_start));
	desc->unmap_fw_mem(buf, (priv->region_end - priv->region_start),
								map_data);

}

#define IOMAP_SIZE SZ_1M

static void *map_fw_mem(phys_addr_t paddr, size_t size, void *data)
{
	struct pil_map_fw_info *info = data;
@@ -890,6 +913,7 @@ out:
					&desc->attrs);
			priv->region = NULL;
		}
		pil_clear_segment(desc);
		pil_release_mmap(desc);
	}
	return ret;