Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>
Reviewed-by: Tom Rix <trix@redhat.com>
Link: https://lore.kernel.org/r/161046503122.2445787.16714129930607546635.stgit@warthog.procyon.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

David Howells and committed by
Jakub Kicinski
d52e419a c8a8ead0

+4 -2
+4 -2
net/rxrpc/key.c
··· 598 598 default: /* we have a ticket we can't encode */ 599 599 pr_err("Unsupported key token type (%u)\n", 600 600 token->security_index); 601 - continue; 601 + return -ENOPKG; 602 602 } 603 603 604 604 _debug("token[%u]: toksize=%u", ntoks, toksize); ··· 674 674 break; 675 675 676 676 default: 677 - break; 677 + pr_err("Unsupported key token type (%u)\n", 678 + token->security_index); 679 + return -ENOPKG; 678 680 } 679 681 680 682 ASSERTCMP((unsigned long)xdr - (unsigned long)oldxdr, ==,