mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH][next] pstore/zone,blk: fix dereference of pointer before it has been null checked
@ 2020-05-12 17:07 Colin King
  2020-05-12 18:58 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-05-12 17:07 UTC (permalink / raw)
  To: Kees Cook, Anton Vorontsov, Colin Cross, Tony Luck, WeiXiong Liao
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the assignment of ctx dereferences pointer 'record' before
the pointer has been null checked. Fix this by only making this
dereference after it has been null checked close to the point ctx
is to be used.

Addresses-Coverity: ("Dereference before null check")
Fixes: bb4ccd1e6f56 ("pstore/zone,blk: Add ftrace frontend support")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/pstore/zone.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c
index bd8e194110fc..c5bf3b9f644f 100644
--- a/fs/pstore/zone.c
+++ b/fs/pstore/zone.c
@@ -998,7 +998,7 @@ static ssize_t psz_kmsg_read(struct pstore_zone *zone,
 static ssize_t psz_ftrace_read(struct pstore_zone *zone,
 		struct pstore_record *record)
 {
-	struct psz_context *cxt = record->psi->data;
+	struct psz_context *cxt;
 	struct psz_buffer *buf;
 	int ret;
 
@@ -1018,6 +1018,7 @@ static ssize_t psz_ftrace_read(struct pstore_zone *zone,
 		return ret;
 
 out:
+	cxt = record->psi->data;
 	if (cxt->ftrace_read_cnt < cxt->ftrace_max_cnt)
 		/* then, read next ftrace zone */
 		return -ENOMSG;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] pstore/zone,blk: fix dereference of pointer before it has been null checked
  2020-05-12 17:07 [PATCH][next] pstore/zone,blk: fix dereference of pointer before it has been null checked Colin King
@ 2020-05-12 18:58 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2020-05-12 18:58 UTC (permalink / raw)
  To: Colin King
  Cc: Anton Vorontsov, Colin Cross, Tony Luck, WeiXiong Liao,
	kernel-janitors, linux-kernel

On Tue, May 12, 2020 at 06:07:19PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently the assignment of ctx dereferences pointer 'record' before
> the pointer has been null checked. Fix this by only making this
> dereference after it has been null checked close to the point ctx
> is to be used.
> 
> Addresses-Coverity: ("Dereference before null check")
> Fixes: bb4ccd1e6f56 ("pstore/zone,blk: Add ftrace frontend support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks; applied.

-Kees

> ---
>  fs/pstore/zone.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c
> index bd8e194110fc..c5bf3b9f644f 100644
> --- a/fs/pstore/zone.c
> +++ b/fs/pstore/zone.c
> @@ -998,7 +998,7 @@ static ssize_t psz_kmsg_read(struct pstore_zone *zone,
>  static ssize_t psz_ftrace_read(struct pstore_zone *zone,
>  		struct pstore_record *record)
>  {
> -	struct psz_context *cxt = record->psi->data;
> +	struct psz_context *cxt;
>  	struct psz_buffer *buf;
>  	int ret;
>  
> @@ -1018,6 +1018,7 @@ static ssize_t psz_ftrace_read(struct pstore_zone *zone,
>  		return ret;
>  
>  out:
> +	cxt = record->psi->data;
>  	if (cxt->ftrace_read_cnt < cxt->ftrace_max_cnt)
>  		/* then, read next ftrace zone */
>  		return -ENOMSG;
> -- 
> 2.25.1
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-12 18:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 17:07 [PATCH][next] pstore/zone,blk: fix dereference of pointer before it has been null checked Colin King
2020-05-12 18:58 ` 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®