pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz
PATCH 1/2 pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz
These two patches are applied on top of patches:
https://lkml.org/lkml/2014/3/3/368
It has been added in -mm tree. Below is the first patch, and i will send the second by replying this one.
From: Liu ShuoX <[email protected]>
ramoops_get_next_prz get the prz according the paramters. If it get a uninitialized prz, access its members by following persistent_ram_old_size(prz) will cause a NULL pointer crash.
Ex: if ftrace_size is 0, fprz will be NULL.
Fix it by return NULL in advance.
--- fs/pstore/ram.c | 2 ++ 1 file changed, 2 insertions(+)
fs/pstore/ram.c +2 -0
@@ -119,6 +119,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,return NULL ; prz = przs[i]; +if (!prz) +return NULL ;/* Update old/shadowed buffer. */ if (update)
Signature · 1 line
1.8.3.2
PATCH 2/2 pstore: correct the max_dump_cnt clearing of ramoops
From: Liu ShuoX <[email protected]>
In case that ramoops_init_przs failed, max_dump_cnt won't be reset to zero in error handle path.
--- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pstore/ram.c +2 -2
@@ -326,6 +326,7 @@ static void ramoops_free_przs(struct ramoops_context *cxt)for (i =0 ; !IS_ERR_OR_NULL (cxt->przs[i]); i++)persistent_ram_free (cxt->przs[i]);kfree (cxt->przs); + cxt->max_dump_cnt =0 ; } static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
@@ -350,7 +351,7 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt, GFP_KERNEL);if (!cxt->przs) {dev_err (dev,"failed to initialize a prz array for dumps\n" ); -return -ENOMEM ; + goto fail_prz; }for (i =0 ; i < cxt->max_dump_cnt; i++) {
@@ -508,7 +509,6 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; - cxt->max_dump_cnt =0 ; fail_cnt:kfree (cxt->fprz); fail_init_fprz:
Signature · 1 line
1.8.3.2
Re: [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops
Quoted 24 lines · Liu ShuoX
From: Liu ShuoX <[email protected]>
In case that
ramoops_init_przsfailed,max_dump_cntwon't be reset to zero in error handle path.Signed-off-by Liu ShuoX <[email protected]>--- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/pstore/ram.c +1
-0@@ -326,6 +326,7 @@ static void ramoops_free_przs(struct ramoops_context *cxt)for (i =0 ; !IS_ERR_OR_NULL (cxt->przs[i]); i++)persistent_ram_free (cxt->przs[i]);kfree (cxt->przs); + cxt->max_dump_cnt =0 ; } static int ramoops_init_przs(struct device *dev, struct ramoops_context*cxt,
fs/pstore/ram.c static int ramoops_init_przs(struct device *dev, struct · line 356
Quoted 7 lines
fs/pstore/ram.c +1
-1@@ -350,7 +351,7 @@ static int ramoops_init_przs(struct device *dev, structramoops_context *cxt, GFP_KERNEL);if (!cxt->przs) {dev_err (dev,"failed to initialize a prz array for dumps\n"); -return -ENOMEM ; + goto fail_prz;
This will have no effect. If cxt->przs == NULL, ramoops_free_przs will immediately exit too, not hitting your max_dump_cnt = 0 change. Perhaps move the =0 in that function to the top before the check and return?
Quoted 11 lines
fs/pstore/ram.c +0
-0}for (i = 0; i < cxt->max_dump_cnt; i++) {fs/pstore/ram.c +0
-2@@ -508,7 +509,6 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; - cxt->max_dump_cnt =0 ; fail_cnt:kfree (cxt->fprz); fail_init_fprz: --
Quoted 2 lines
1.8.3.2
Otherwise, yes, once fixed, this clean-up looks good -- it keeps the variable initialization and cleanup all in ramoops_init_przs() which is how it should be.
Thanks!
-Kees
Signature · 2 lines
Kees Cook Chrome OS Security
Re: [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops
Quoted 29 lines · Kees Cook
Quoted 28 lines · Liu ShuoX
From: Liu ShuoX <[email protected]>
In case that
ramoops_init_przsfailed,max_dump_cntwon't be reset to zero in error handle path.Signed-off-by Liu ShuoX <[email protected]>--- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/pstore/ram.c +1
-0@@ -326,6 +326,7 @@ static void ramoops_free_przs(struct ramoops_context *cxt)for (i =0 ; !IS_ERR_OR_NULL (cxt->przs[i]); i++)persistent_ram_free (cxt->przs[i]);kfree (cxt->przs); + cxt->max_dump_cnt =0 ; } static int ramoops_init_przs(struct device *dev, struct ramoops_context*cxt,
fs/pstore/ram.c +0
-0@@ -350,7 +351,7 @@ static int ramoops_init_przs(struct device *dev, structramoops_context *cxt, GFP_KERNEL);if (!cxt->przs) { dev_err(dev, "failed to initialize a prz array for
Quoted 8 lines
fs/pstore/ram.c static int ramoops_init_przs(struct device *dev, struct · line 356
Quoted 3 lines
fs/pstore/ram.c +1
-1dumps\n"); - return -ENOMEM ; + goto fail_prz;This will have no effect. If
cxt->przs== NULL,ramoops_free_przswill immediately exit too, not hitting yourmax_dump_cnt= 0 change. Perhaps move the =0 in that function to the top before the check and return?
Yes, you are right. Below has the latest patch which move the =0 to the top of that function, just as you mentioned. Thanks.
Quoted 19 lines
Quoted 12 lines
fs/pstore/ram.c +0
-0}for (i = 0; i < cxt->max_dump_cnt; i++) {fs/pstore/ram.c +0
-2@@ -508,7 +509,6 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; - cxt->max_dump_cnt =0 ; fail_cnt:kfree (cxt->fprz); fail_init_fprz: --Quoted 2 lines
1.8.3.2
Otherwise, yes, once fixed, this clean-up looks good -- it keeps the variable initialization and cleanup all in
ramoops_init_przs()which is how it should be.
Quoted 3 lines
Thanks!
-Kees
-----
From: Liu ShuoX <[email protected]>
In case that ramoops_init_przs failed, max_dump_cnt won't be reset to zero in error handle path.
--- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pstore/ram.c +2 -2
@@ -320,6 +320,7 @@ static void ramoops_free_przs(struct ramoops_context *cxt) {int i; + cxt->max_dump_cnt =0 ;if (!cxt->przs)return ;
@@ -350,7 +351,7 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt, GFP_KERNEL);if (!cxt->przs) {dev_err (dev,"failed to initialize a prz array for dumps\n" ); -return -ENOMEM ; + goto fail_prz; }for (i =0 ; i < cxt->max_dump_cnt; i++) {
@@ -508,7 +509,6 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; - cxt->max_dump_cnt =0 ; fail_cnt:kfree (cxt->fprz); fail_init_fprz:
Signature · 1 line
1.8.3.2
Kees Cook
Acked-byRe: [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops
Quoted 72 lines · Liu ShuoX
Quoted 33 lines · Kees Cook
Quoted 31 lines · Liu ShuoX
From: Liu ShuoX <[email protected]>
In case that
ramoops_init_przsfailed,max_dump_cntwon't be reset to zero in error handle path.Signed-off-by Liu ShuoX <[email protected]>--- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/pstore/ram.c +1
-0@@ -326,6 +326,7 @@ static void ramoops_free_przs(struct ramoops_context *cxt)for (i =0 ; !IS_ERR_OR_NULL (cxt->przs[i]); i++)persistent_ram_free (cxt->przs[i]);kfree (cxt->przs); + cxt->max_dump_cnt =0 ; } static int ramoops_init_przs(struct device *dev, struct ramoops_context*cxt,
fs/pstore/ram.c +0
-0@@ -350,7 +351,7 @@ static int ramoops_init_przs(struct device *dev,struct
ramoops_context*cxt,GFP_KERNEL); if (!cxt->przs) { dev_err(dev, "failed to initialize a prz array fordumps\n");
Quoted 8 lines
fs/pstore/ram.c static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt, · line 354
Quoted 2 lines
fs/pstore/ram.c +1
-1-return -ENOMEM ; + goto fail_prz;This will have no effect. If
cxt->przs== NULL,ramoops_free_przswill immediately exit too, not hitting yourmax_dump_cnt= 0 change. Perhaps move the =0 in that function to the top before the check and return?Yes, you are right. Below has the latest patch which move the =0 to the top of that function, just as you mentioned. Thanks.
Quoted 19 lines
Quoted 12 lines
} for (i = 0; i < cxt->max_dump_cnt; i++) {fs/pstore/ram.c +0
-2@@ -508,7 +509,6 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; - cxt->max_dump_cnt =0 ; fail_cnt:kfree (cxt->fprz); fail_init_fprz: --Quoted 2 lines
1.8.3.2
Otherwise, yes, once fixed, this clean-up looks good -- it keeps the variable initialization and cleanup all in
ramoops_init_przs()which is how it should be.Quoted 3 lines
Thanks!
-Kees
-----
Quoted 6 lines
From: Liu ShuoX <[email protected]>
In case that
ramoops_init_przsfailed,max_dump_cntwon't be reset to zero in error handle path.Signed-off-by Liu ShuoX <[email protected]>
Thanks! Looks right now.
-Kees
Quoted 38 lines
--- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/pstore/ram.c +0
-0@@ -320,6 +320,7 @@ static void ramoops_free_przs(struct ramoops_context *cxt) {int i; + cxt->max_dump_cnt =0 ;if (!cxt->przs)return ; @@ -350,7 +351,7 @@ static int ramoops_init_przs(struct device *dev, struct
ramoops_context*cxt,GFP_KERNEL); if (!cxt->przs) { dev_err(dev, "failed to initialize a prz array fordumps\n");
fs/pstore/ram.c +1
-3-return -ENOMEM ; + goto fail_prz; }for (i =0 ; i < cxt->max_dump_cnt; i++) {@@ -508,7 +509,6 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; - cxt->max_dump_cnt =0 ; fail_cnt:kfree (cxt->fprz); fail_init_fprz: --1.8.3.2
Signature · 2 lines
Kees Cook Chrome OS Security
Quoted 13 lines · Liu ShuoX
These two patches are applied on top of patches:
https://lkml.org/lkml/2014/3/3/368
It has been added in -mm tree. Below is the first patch, and i will send the second by replying this one.From: Liu ShuoX <[email protected]>
ramoops_get_next_przget the prz according the paramters. If it get a uninitialized prz, access its members by followingpersistent_ram_old_size(prz)
will cause a NULL pointer crash.
Ex: ifftrace_sizeis 0, fprz will be NULL.
Quoted 3 lines
Fix it by return NULL in advance.
Signed-off-by Liu ShuoX <[email protected]>
Thanks!
-Kees
Quoted 18 lines
--- fs/pstore/ram.c | 2 ++ 1 file changed, 2 insertions(+)fs/pstore/ram.c +2
-1@@ -119,6 +119,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, return NULL; prz = przs[i]; +if (!prz) +return NULL ;/* Update old/shadowed buffer. */ if (update) --1.8.3.2
Signature · 2 lines
Kees Cook Chrome OS Security