* [PATCH] pstore/ram: Fix bounds checks for mem_size, record_size, console_size and ftrace_size
@ 2012-12-12 1:49 Arve Hjønnevåg
2012-12-13 4:01 ` Anton Vorontsov
0 siblings, 1 reply; 2+ messages in thread
From: Arve Hjønnevåg @ 2012-12-12 1:49 UTC (permalink / raw)
To: linux-kernel
Cc: Arve Hjønnevåg, Anton Vorontsov, Colin Cross, Kees Cook,
Tony Luck
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: Arve Hjønnevåg <arve@android.com>
---
fs/pstore/ram.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 1a4f6da..eb3dbff 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -189,7 +189,7 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
struct pstore_info *psi)
{
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;
if (type == PSTORE_TYPE_CONSOLE) {
@@ -226,6 +226,11 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
if (part != 1)
return -ENOSPC;
+ if (!cxt->przs)
+ return -ENOSPC;
+
+ prz = cxt->przs[cxt->dump_write_cnt];
+
hlen = ramoops_write_kmsg_hdr(prz);
if (size + hlen > prz->buffer_size)
size = prz->buffer_size - hlen;
@@ -296,6 +301,11 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
if (!cxt->record_size)
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;
if (!cxt->max_dump_cnt)
return -ENOMEM;
@@ -333,8 +343,12 @@ static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
if (!sz)
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;
+ }
*prz = persistent_ram_new(*paddr, sz, sig, cxt->ecc_size);
if (IS_ERR(*prz)) {
--
1.7.7.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pstore/ram: Fix bounds checks for mem_size, record_size, console_size and ftrace_size
2012-12-12 1:49 [PATCH] pstore/ram: Fix bounds checks for mem_size, record_size, console_size and ftrace_size Arve Hjønnevåg
@ 2012-12-13 4:01 ` Anton Vorontsov
0 siblings, 0 replies; 2+ messages in thread
From: Anton Vorontsov @ 2012-12-13 4:01 UTC (permalink / raw)
To: Arve Hjønnevåg; +Cc: linux-kernel, Colin Cross, Kees Cook, Tony Luck
On Tue, Dec 11, 2012 at 05:49:24PM -0800, Arve Hjønnevåg wrote:
> 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: Arve Hjønnevåg <arve@android.com>
> ---
Applied, thanks a lot!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-12-13 4:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-12 1:49 [PATCH] pstore/ram: Fix bounds checks for mem_size, record_size, console_size and ftrace_size Arve Hjønnevåg
2012-12-13 4:01 ` Anton Vorontsov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.