Skip to content

Commit 6f3fe96

Browse files
dhowellsgregkh
authored andcommitted
rxrpc: Fix handling of an unsupported token type in rxrpc_read()
[ Upstream commit d52e419 ] 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: 9a059cd ("rxrpc: Downgrade the BUG() for unsupported token type in rxrpc_read()") Reported-by: Tom Rix <[email protected]> Signed-off-by: David Howells <[email protected]> Reviewed-by: Tom Rix <[email protected]> Link: https://lore.kernel.org/r/161046503122.2445787.16714129930607546635.stgit@warthog.procyon.org.uk Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2bfb953 commit 6f3fe96

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/rxrpc/key.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ static long rxrpc_read(const struct key *key,
11091109
default: /* we have a ticket we can't encode */
11101110
pr_err("Unsupported key token type (%u)\n",
11111111
token->security_index);
1112-
continue;
1112+
return -ENOPKG;
11131113
}
11141114

11151115
_debug("token[%u]: toksize=%u", ntoks, toksize);
@@ -1224,7 +1224,9 @@ static long rxrpc_read(const struct key *key,
12241224
break;
12251225

12261226
default:
1227-
break;
1227+
pr_err("Unsupported key token type (%u)\n",
1228+
token->security_index);
1229+
return -ENOPKG;
12281230
}
12291231

12301232
ASSERTCMP((unsigned long)xdr - (unsigned long)oldxdr, ==,

0 commit comments

Comments
 (0)