From: Kees Cook <keescook@chromium.org>
To: Colin King <colin.king@canonical.com>
Cc: Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
WeiXiong Liao <liaoweixiong@allwinnertech.com>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] pstore/zone: fix dereference of pointer before it has been null checked
Date: Tue, 12 May 2020 18:59:16 +0000 [thread overview]
Message-ID: <202005121159.711F246@keescook> (raw)
In-Reply-To: <20200512171932.222102-1-colin.king@canonical.com>
On Tue, May 12, 2020 at 06:19:32PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the assignment of cnt 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 cnt
> is to be used.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 637ce64e7f57 ("pstore/zone,blk: Add support for pmsg frontend")
> 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 c5bf3b9f644f..3cf7d6762c76 100644
> --- a/fs/pstore/zone.c
> +++ b/fs/pstore/zone.c
> @@ -825,7 +825,7 @@ static int notrace psz_record_write(struct pstore_zone *zone,
> struct pstore_record *record)
> {
> size_t start, rem;
> - int cnt = record->size;
> + int cnt;
> bool is_full_data = false;
> char *buf = record->buf;
Also here. I'll fix both. Thanks!
-Kees
>
> @@ -835,6 +835,7 @@ static int notrace psz_record_write(struct pstore_zone *zone,
> if (atomic_read(&zone->buffer->datalen) >= zone->buffer_size)
> is_full_data = true;
>
> + cnt = record->size;
> if (unlikely(cnt > zone->buffer_size)) {
> buf += cnt - zone->buffer_size;
> cnt = zone->buffer_size;
> --
> 2.25.1
>
--
Kees Cook
WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Colin King <colin.king@canonical.com>
Cc: Anton Vorontsov <anton@enomsg.org>,
Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
WeiXiong Liao <liaoweixiong@allwinnertech.com>,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] pstore/zone: fix dereference of pointer before it has been null checked
Date: Tue, 12 May 2020 11:59:16 -0700 [thread overview]
Message-ID: <202005121159.711F246@keescook> (raw)
In-Reply-To: <20200512171932.222102-1-colin.king@canonical.com>
On Tue, May 12, 2020 at 06:19:32PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the assignment of cnt 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 cnt
> is to be used.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 637ce64e7f57 ("pstore/zone,blk: Add support for pmsg frontend")
> 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 c5bf3b9f644f..3cf7d6762c76 100644
> --- a/fs/pstore/zone.c
> +++ b/fs/pstore/zone.c
> @@ -825,7 +825,7 @@ static int notrace psz_record_write(struct pstore_zone *zone,
> struct pstore_record *record)
> {
> size_t start, rem;
> - int cnt = record->size;
> + int cnt;
> bool is_full_data = false;
> char *buf = record->buf;
Also here. I'll fix both. Thanks!
-Kees
>
> @@ -835,6 +835,7 @@ static int notrace psz_record_write(struct pstore_zone *zone,
> if (atomic_read(&zone->buffer->datalen) >= zone->buffer_size)
> is_full_data = true;
>
> + cnt = record->size;
> if (unlikely(cnt > zone->buffer_size)) {
> buf += cnt - zone->buffer_size;
> cnt = zone->buffer_size;
> --
> 2.25.1
>
--
Kees Cook
next prev parent reply other threads:[~2020-05-12 18:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-12 17:19 [PATCH][next] pstore/zone: fix dereference of pointer before it has been null checked Colin King
2020-05-12 17:19 ` Colin King
2020-05-12 18:59 ` Kees Cook [this message]
2020-05-12 18:59 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202005121159.711F246@keescook \
--to=keescook@chromium.org \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=colin.king@canonical.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=liaoweixiong@allwinnertech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.