Merge "memshare: Add guard bytes to avoid access issues"

This commit is contained in:
Linux Build Service Account 2017-05-10 23:03:41 -07:00 committed by Gerrit - the friendly Code Review server
commit b2754d1d5b
2 changed files with 11 additions and 3 deletions

View file

@ -498,6 +498,7 @@ static int handle_alloc_generic_req(void *req_h, void *req, void *conn_h)
struct mem_alloc_generic_resp_msg_v01 *alloc_resp; struct mem_alloc_generic_resp_msg_v01 *alloc_resp;
int rc, resp = 0; int rc, resp = 0;
int client_id; int client_id;
uint32_t size = 0;
alloc_req = (struct mem_alloc_generic_req_msg_v01 *)req; alloc_req = (struct mem_alloc_generic_req_msg_v01 *)req;
pr_debug("memshare: alloc request client id: %d proc _id: %d\n", pr_debug("memshare: alloc request client id: %d proc _id: %d\n",
@ -528,7 +529,11 @@ static int handle_alloc_generic_req(void *req_h, void *req, void *conn_h)
__func__, memblock[client_id].client_id, __func__, memblock[client_id].client_id,
memblock[client_id].free_memory); memblock[client_id].free_memory);
if (!memblock[client_id].alloted) { if (!memblock[client_id].alloted) {
rc = memshare_alloc(memsh_drv->dev, alloc_req->num_bytes, if (alloc_req->client_id == 1 && alloc_req->num_bytes > 0)
size = alloc_req->num_bytes + MEMSHARE_GUARD_BYTES;
else
size = alloc_req->num_bytes;
rc = memshare_alloc(memsh_drv->dev, size,
&memblock[client_id]); &memblock[client_id]);
if (rc) { if (rc) {
pr_err("In %s,Unable to allocate memory for requested client\n", pr_err("In %s,Unable to allocate memory for requested client\n",
@ -963,8 +968,10 @@ static int memshare_child_probe(struct platform_device *pdev)
* Memshare allocation for guaranteed clients * Memshare allocation for guaranteed clients
*/ */
if (memblock[num_clients].guarantee) { if (memblock[num_clients].guarantee) {
if (client_id == 1 && size > 0)
size += MEMSHARE_GUARD_BYTES;
rc = memshare_alloc(memsh_child->dev, rc = memshare_alloc(memsh_child->dev,
memblock[num_clients].size, size,
&memblock[num_clients]); &memblock[num_clients]);
if (rc) { if (rc) {
pr_err("In %s, Unable to allocate memory for guaranteed clients, rc: %d\n", pr_err("In %s, Unable to allocate memory for guaranteed clients, rc: %d\n",

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. /* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 and
@ -24,6 +24,7 @@
#define GPS 0 #define GPS 0
#define CHECK 0 #define CHECK 0
#define FREE 1 #define FREE 1
#define MEMSHARE_GUARD_BYTES (4*1024)
struct mem_blocks { struct mem_blocks {
/* Client Id information */ /* Client Id information */