[PATCH 4.9 49/54] rxrpc: Downgrade the BUG() for unsupported token type in rxrpc_read()

From: Greg Kroah-Hartman
Date: Mon Oct 12 2020 - 10:05:30 EST


From: David Howells <dhowells@xxxxxxxxxx>

[ Upstream commit 9a059cd5ca7d9c5c4ca5a6e755cf72f230176b6a ]

If rxrpc_read() (which allows KEYCTL_READ to read a key), sees a token of a
type it doesn't recognise, it can BUG in a couple of places, which is
unnecessary as it can easily get back to userspace.

Fix this to print an error message instead.

Fixes: 99455153d067 ("RxRPC: Parse security index 5 keys (Kerberos 5)")
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
net/rxrpc/key.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
index fd9260620824e..01d2d40ef21cb 100644
--- a/net/rxrpc/key.c
+++ b/net/rxrpc/key.c
@@ -1104,7 +1104,8 @@ static long rxrpc_read(const struct key *key,
break;

default: /* we have a ticket we can't encode */
- BUG();
+ pr_err("Unsupported key token type (%u)\n",
+ token->security_index);
continue;
}

@@ -1225,7 +1226,6 @@ static long rxrpc_read(const struct key *key,
break;

default:
- BUG();
break;
}

--
2.25.1