* [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz @ 2014-03-11 6:15 Liu ShuoX 2014-03-11 6:17 ` [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops Liu ShuoX 2014-03-11 20:30 ` [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz Kees Cook 0 siblings, 2 replies; 6+ messages in thread From: Liu ShuoX @ 2014-03-11 6:15 UTC (permalink / raw) To: linux-kernel; +Cc: anton, ccross, keescook, tony.luck, yanmin_zhang 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 <shuox.liu@intel.com> 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. Signed-off-by: Liu ShuoX <shuox.liu@intel.com> --- fs/pstore/ram.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 1daed28..6f96d8c 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops 2014-03-11 6:15 [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz Liu ShuoX @ 2014-03-11 6:17 ` Liu ShuoX 2014-03-11 20:37 ` Kees Cook 2014-03-11 20:30 ` [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz Kees Cook 1 sibling, 1 reply; 6+ messages in thread From: Liu ShuoX @ 2014-03-11 6:17 UTC (permalink / raw) To: linux-kernel; +Cc: anton, ccross, keescook, tony.luck, yanmin_zhang From: Liu ShuoX <shuox.liu@intel.com> In case that ramoops_init_przs failed, max_dump_cnt won't be reset to zero in error handle path. Signed-off-by: Liu ShuoX <shuox.liu@intel.com> --- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 6f96d8c..522e530 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -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: -- 1.8.3.2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops 2014-03-11 6:17 ` [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops Liu ShuoX @ 2014-03-11 20:37 ` Kees Cook 2014-03-12 9:48 ` Liu ShuoX 0 siblings, 1 reply; 6+ messages in thread From: Kees Cook @ 2014-03-11 20:37 UTC (permalink / raw) To: Liu ShuoX; +Cc: LKML, Anton Vorontsov, Colin Cross, Tony Luck, yanmin_zhang On Mon, Mar 10, 2014 at 11:17 PM, Liu ShuoX <shuox.liu@intel.com> wrote: > From: Liu ShuoX <shuox.liu@intel.com> > > In case that ramoops_init_przs failed, max_dump_cnt won't be reset to > zero in error handle path. > > Signed-off-by: Liu ShuoX <shuox.liu@intel.com> > --- > fs/pstore/ram.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c > index 6f96d8c..522e530 100644 > --- a/fs/pstore/ram.c > +++ b/fs/pstore/ram.c > @@ -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; 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? > } > 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 > 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 -- Kees Cook Chrome OS Security ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops 2014-03-11 20:37 ` Kees Cook @ 2014-03-12 9:48 ` Liu ShuoX 2014-03-12 14:55 ` Kees Cook 0 siblings, 1 reply; 6+ messages in thread From: Liu ShuoX @ 2014-03-12 9:48 UTC (permalink / raw) To: Kees Cook; +Cc: LKML, Anton Vorontsov, Colin Cross, Tony Luck, yanmin_zhang On Tue 11.Mar'14 at 13:37:23 -0700, Kees Cook wrote: >On Mon, Mar 10, 2014 at 11:17 PM, Liu ShuoX <shuox.liu@intel.com> wrote: >> From: Liu ShuoX <shuox.liu@intel.com> >> >> In case that ramoops_init_przs failed, max_dump_cnt won't be reset to >> zero in error handle path. >> >> Signed-off-by: Liu ShuoX <shuox.liu@intel.com> >> --- >> fs/pstore/ram.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c >> index 6f96d8c..522e530 100644 >> --- a/fs/pstore/ram.c >> +++ b/fs/pstore/ram.c >> @@ -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; > >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? Yes, you are right. Below has the latest patch which move the =0 to the top of that function, just as you mentioned. Thanks. > >> } >> 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 >> > >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 ----- From: Liu ShuoX <shuox.liu@intel.com> In case that ramoops_init_przs failed, max_dump_cnt won't be reset to zero in error handle path. Signed-off-by: Liu ShuoX <shuox.liu@intel.com> --- fs/pstore/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 6f96d8c..3b57443 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -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: -- 1.8.3.2 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops 2014-03-12 9:48 ` Liu ShuoX @ 2014-03-12 14:55 ` Kees Cook 0 siblings, 0 replies; 6+ messages in thread From: Kees Cook @ 2014-03-12 14:55 UTC (permalink / raw) To: Liu ShuoX; +Cc: LKML, Anton Vorontsov, Colin Cross, Tony Luck, yanmin_zhang On Wed, Mar 12, 2014 at 2:48 AM, Liu ShuoX <shuox.liu@intel.com> wrote: > On Tue 11.Mar'14 at 13:37:23 -0700, Kees Cook wrote: >> >> On Mon, Mar 10, 2014 at 11:17 PM, Liu ShuoX <shuox.liu@intel.com> wrote: >>> >>> From: Liu ShuoX <shuox.liu@intel.com> >>> >>> In case that ramoops_init_przs failed, max_dump_cnt won't be reset to >>> zero in error handle path. >>> >>> Signed-off-by: Liu ShuoX <shuox.liu@intel.com> >>> --- >>> fs/pstore/ram.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c >>> index 6f96d8c..522e530 100644 >>> --- a/fs/pstore/ram.c >>> +++ b/fs/pstore/ram.c >>> @@ -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; >> >> >> 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? > > Yes, you are right. Below has the latest patch which move the =0 to the > top of that function, just as you mentioned. Thanks. > >> >>> } >>> 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 >>> >> >> 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 > > ----- > > > From: Liu ShuoX <shuox.liu@intel.com> > > In case that ramoops_init_przs failed, max_dump_cnt won't be reset to > zero in error handle path. > > Signed-off-by: Liu ShuoX <shuox.liu@intel.com> Thanks! Looks right now. Acked-by: Kees Cook <keescook@chromium.org> -Kees > --- > fs/pstore/ram.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c > index 6f96d8c..3b57443 100644 > --- a/fs/pstore/ram.c > +++ b/fs/pstore/ram.c > @@ -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: > -- > 1.8.3.2 > -- Kees Cook Chrome OS Security ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz 2014-03-11 6:15 [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz Liu ShuoX 2014-03-11 6:17 ` [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops Liu ShuoX @ 2014-03-11 20:30 ` Kees Cook 1 sibling, 0 replies; 6+ messages in thread From: Kees Cook @ 2014-03-11 20:30 UTC (permalink / raw) To: Liu ShuoX; +Cc: LKML, Anton Vorontsov, Colin Cross, Tony Luck, yanmin_zhang On Mon, Mar 10, 2014 at 11:15 PM, Liu ShuoX <shuox.liu@intel.com> wrote: > 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 <shuox.liu@intel.com> > > 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. > > Signed-off-by: Liu ShuoX <shuox.liu@intel.com> Thanks! Acked-by: Kees Cook <keescook@chromium.org> -Kees > --- > fs/pstore/ram.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c > index 1daed28..6f96d8c 100644 > --- a/fs/pstore/ram.c > +++ b/fs/pstore/ram.c > @@ -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 -- Kees Cook Chrome OS Security ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-12 14:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-03-11 6:15 [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz Liu ShuoX 2014-03-11 6:17 ` [PATCH 2/2] pstore: correct the max_dump_cnt clearing of ramoops Liu ShuoX 2014-03-11 20:37 ` Kees Cook 2014-03-12 9:48 ` Liu ShuoX 2014-03-12 14:55 ` Kees Cook 2014-03-11 20:30 ` [PATCH 1/2] pstore: fix NULL pointer fault if get NULL prz in ramoops_get_next_prz Kees Cook
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®