From: Tom Rix <trix@redhat.com>
To: David Howells <dhowells@redhat.com>
Cc: davem@davemloft.net, kuba@kernel.org, natechancellor@gmail.com,
ndesaulniers@google.com, linux-afs@lists.infradead.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
clang-built-linux@googlegroups.com
Subject: Re: [PATCH] rxrpc: fix handling of an unsupported token type in rxrpc_read()
Date: Wed, 6 Jan 2021 11:34:17 -0800 [thread overview]
Message-ID: <f02bdada-355c-97cd-bc32-f84516ddd93f@redhat.com> (raw)
In-Reply-To: <675150.1609954812@warthog.procyon.org.uk>
On 1/6/21 9:40 AM, David Howells wrote:
> David Howells <dhowells@redhat.com> wrote:
>
>> How about this?
>> ...
>> Fix the second loop so that it doesn't encode the size and type of an
>> unsupported token, but rather just ignore it as does the first loop.
> Actually, a better way is probably just to error out in this case. This
> should only happen if a new token type is incompletely implemented.
>
> David
> ---
> commit e68ef16f59aa57564761b21e5ecb2ebbd72d1c57
> Author: David Howells <dhowells@redhat.com>
> Date: Wed Jan 6 16:21:40 2021 +0000
>
> rxrpc: Fix handling of an unsupported token type in rxrpc_read()
>
> Clang static analysis reports the following:
>
> net/rxrpc/key.c:657:11: warning: Assigned value is garbage or undefined
> toksize = toksizes[tok++];
> ^ ~~~~~~~~~~~~~~~
>
> rxrpc_read() contains two consecutive loops. The first loop calculates the
> token sizes and stores the results in toksizes[] and the second one uses
> the array. When there is an error in identifying the token in the first
> loop, the token is skipped, no change is made to the toksizes[] array.
> When the same error happens in the second loop, the token is not skipped.
> This will cause the toksizes[] array to be out of step and will overrun
> past the calculated sizes.
>
> Fix this by making both loops log a message and return an error in this
> case. This should only happen if a new token type is incompletely
> implemented, so it should normally be impossible to trigger this.
>
> Fixes: 9a059cd5ca7d ("rxrpc: Downgrade the BUG() for unsupported token type in rxrpc_read()")
> Reported-by: Tom Rix <trix@redhat.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
>
> diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
> index 9631aa8543b5..8d2073e0e3da 100644
> --- a/net/rxrpc/key.c
> +++ b/net/rxrpc/key.c
> @@ -598,7 +598,7 @@ static long rxrpc_read(const struct key *key,
> default: /* we have a ticket we can't encode */
> pr_err("Unsupported key token type (%u)\n",
> token->security_index);
> - continue;
> + return -ENOPKG;
> }
These two loops iterate over the same data, i believe returning here is all that is needed.
Tom
>
> _debug("token[%u]: toksize=%u", ntoks, toksize);
> @@ -674,7 +674,9 @@ static long rxrpc_read(const struct key *key,
> break;
>
> default:
> - break;
> + pr_err("Unsupported key token type (%u)\n",
> + token->security_index);
> + return -ENOPKG;
> }
>
> ASSERTCMP((unsigned long)xdr - (unsigned long)oldxdr, ==,
>
next prev parent reply other threads:[~2021-01-06 19:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-29 17:39 [PATCH] rxrpc: fix handling of an unsupported token type in rxrpc_read() trix
2021-01-04 12:50 ` David Howells
2021-01-04 15:04 ` Tom Rix
2021-01-06 16:57 ` David Howells
2021-01-06 17:40 ` David Howells
2021-01-06 19:34 ` Tom Rix [this message]
2021-01-06 19:44 ` David Howells
2021-01-06 20:38 ` Tom Rix
2021-01-06 21:09 ` David Howells
2021-01-06 22:09 ` Tom Rix
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=f02bdada-355c-97cd-bc32-f84516ddd93f@redhat.com \
--to=trix@redhat.com \
--cc=clang-built-linux@googlegroups.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).