Commit c6289378 authored by Arve Hjønnevåg's avatar Arve Hjønnevåg Committed by Anton Vorontsov

pstore/ram: Fix bounds checks for mem_size, record_size, console_size and ftrace_size

The bounds check in ramoops_init_prz was incorrect and ramoops_init_przs
had no check. Additionally, ramoops_init_przs allows record_size to be 0,
but ramoops_pstore_write_buf would always crash in this case.
Signed-off-by: default avatarArve Hjønnevåg <arve@android.com>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
parent b042e474
...@@ -189,7 +189,7 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type, ...@@ -189,7 +189,7 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
struct pstore_info *psi) struct pstore_info *psi)
{ {
struct ramoops_context *cxt = psi->data; struct ramoops_context *cxt = psi->data;
struct persistent_ram_zone *prz = cxt->przs[cxt->dump_write_cnt]; struct persistent_ram_zone *prz;
size_t hlen; size_t hlen;
if (type == PSTORE_TYPE_CONSOLE) { if (type == PSTORE_TYPE_CONSOLE) {
...@@ -226,6 +226,11 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type, ...@@ -226,6 +226,11 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
if (part != 1) if (part != 1)
return -ENOSPC; return -ENOSPC;
if (!cxt->przs)
return -ENOSPC;
prz = cxt->przs[cxt->dump_write_cnt];
hlen = ramoops_write_kmsg_hdr(prz); hlen = ramoops_write_kmsg_hdr(prz);
if (size + hlen > prz->buffer_size) if (size + hlen > prz->buffer_size)
size = prz->buffer_size - hlen; size = prz->buffer_size - hlen;
...@@ -297,6 +302,11 @@ static int __devinit ramoops_init_przs(struct device *dev, ...@@ -297,6 +302,11 @@ static int __devinit ramoops_init_przs(struct device *dev,
if (!cxt->record_size) if (!cxt->record_size)
return 0; return 0;
if (*paddr + dump_mem_sz - cxt->phys_addr > cxt->size) {
dev_err(dev, "no room for dumps\n");
return -ENOMEM;
}
cxt->max_dump_cnt = dump_mem_sz / cxt->record_size; cxt->max_dump_cnt = dump_mem_sz / cxt->record_size;
if (!cxt->max_dump_cnt) if (!cxt->max_dump_cnt)
return -ENOMEM; return -ENOMEM;
...@@ -335,8 +345,12 @@ static int __devinit ramoops_init_prz(struct device *dev, ...@@ -335,8 +345,12 @@ static int __devinit ramoops_init_prz(struct device *dev,
if (!sz) if (!sz)
return 0; return 0;
if (*paddr + sz > *paddr + cxt->size) if (*paddr + sz - cxt->phys_addr > cxt->size) {
dev_err(dev, "no room for mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
sz, (unsigned long long)*paddr,
cxt->size, (unsigned long long)cxt->phys_addr);
return -ENOMEM; return -ENOMEM;
}
*prz = persistent_ram_new(*paddr, sz, sig, cxt->ecc_size); *prz = persistent_ram_new(*paddr, sz, sig, cxt->ecc_size);
if (IS_ERR(*prz)) { if (IS_ERR(*prz)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment