rxrpc: Ignore unknown tokens in key payload unless no known tokens

When parsing a payload for an rxrpc-type key, ignore any tokens that are
not of a known type and don't give an error for them - unless there are no
tokens of a known type.

Signed-off-by: David Howells <dhowells@redhat.com>
This commit is contained in:
David Howells 2020-10-15 15:59:36 +01:00
parent 4c20c33340
commit 9a0e6464f4

View File

@ -139,7 +139,7 @@ static int rxrpc_preparse_xdr(struct key_preparsed_payload *prep)
const char *cp; const char *cp;
unsigned int len, paddedlen, loop, ntoken, toklen, sec_ix; unsigned int len, paddedlen, loop, ntoken, toklen, sec_ix;
size_t datalen = prep->datalen; size_t datalen = prep->datalen;
int ret; int ret, ret2;
_enter(",{%x,%x,%x,%x},%zu", _enter(",{%x,%x,%x,%x},%zu",
ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), ntohl(xdr[3]), ntohl(xdr[0]), ntohl(xdr[1]), ntohl(xdr[2]), ntohl(xdr[3]),
@ -213,6 +213,7 @@ static int rxrpc_preparse_xdr(struct key_preparsed_payload *prep)
/* okay: we're going to assume it's valid XDR format /* okay: we're going to assume it's valid XDR format
* - we ignore the cellname, relying on the key to be correctly named * - we ignore the cellname, relying on the key to be correctly named
*/ */
ret = -EPROTONOSUPPORT;
do { do {
toklen = ntohl(*xdr++); toklen = ntohl(*xdr++);
token = xdr; token = xdr;
@ -225,27 +226,37 @@ static int rxrpc_preparse_xdr(struct key_preparsed_payload *prep)
switch (sec_ix) { switch (sec_ix) {
case RXRPC_SECURITY_RXKAD: case RXRPC_SECURITY_RXKAD:
ret = rxrpc_preparse_xdr_rxkad(prep, datalen, token, toklen); ret2 = rxrpc_preparse_xdr_rxkad(prep, datalen, token, toklen);
if (ret != 0)
goto error;
break; break;
default: default:
ret = -EPROTONOSUPPORT; ret2 = -EPROTONOSUPPORT;
break;
}
switch (ret2) {
case 0:
ret = 0;
break;
case -EPROTONOSUPPORT:
break;
case -ENOPKG:
if (ret != 0)
ret = -ENOPKG;
break;
default:
ret = ret2;
goto error; goto error;
} }
} while (--ntoken > 0); } while (--ntoken > 0);
_leave(" = 0"); error:
return 0; _leave(" = %d", ret);
return ret;
not_xdr: not_xdr:
_leave(" = -EPROTO"); _leave(" = -EPROTO");
return -EPROTO; return -EPROTO;
error:
_leave(" = %d", ret);
return ret;
} }
/* /*