Skip to content

Commit 5630511

Browse files
Marc Dionnedhowells
authored andcommitted
rxrpc: Fix rxkad token xdr encoding
The session key should be encoded with just the 8 data bytes and no length; ENCODE_DATA precedes it with a 4 byte length, which confuses some existing tools that try to parse this format. Add an ENCODE_BYTES macro that does not include a length, and use it for the key. Also adjust the expected length. Note that commit 774521f ("rxrpc: Fix an assertion in rxrpc_read()") had fixed a BUG by changing the length rather than fixing the encoding. The original length was correct. Fixes: 9945515 ("RxRPC: Parse security index 5 keys (Kerberos 5)") Signed-off-by: Marc Dionne <marc.dionne@auristor.com> Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 4296adc commit 5630511

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

net/rxrpc/key.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ static long rxrpc_read(const struct key *key,
10721072

10731073
switch (token->security_index) {
10741074
case RXRPC_SECURITY_RXKAD:
1075-
toksize += 9 * 4; /* viceid, kvno, key*2 + len, begin,
1075+
toksize += 8 * 4; /* viceid, kvno, key*2, begin,
10761076
* end, primary, tktlen */
10771077
toksize += RND(token->kad->ticket_len);
10781078
break;
@@ -1138,6 +1138,14 @@ static long rxrpc_read(const struct key *key,
11381138
memcpy((u8 *)xdr + _l, &zero, 4 - (_l & 3)); \
11391139
xdr += (_l + 3) >> 2; \
11401140
} while(0)
1141+
#define ENCODE_BYTES(l, s) \
1142+
do { \
1143+
u32 _l = (l); \
1144+
memcpy(xdr, (s), _l); \
1145+
if (_l & 3) \
1146+
memcpy((u8 *)xdr + _l, &zero, 4 - (_l & 3)); \
1147+
xdr += (_l + 3) >> 2; \
1148+
} while(0)
11411149
#define ENCODE64(x) \
11421150
do { \
11431151
__be64 y = cpu_to_be64(x); \
@@ -1165,7 +1173,7 @@ static long rxrpc_read(const struct key *key,
11651173
case RXRPC_SECURITY_RXKAD:
11661174
ENCODE(token->kad->vice_id);
11671175
ENCODE(token->kad->kvno);
1168-
ENCODE_DATA(8, token->kad->session_key);
1176+
ENCODE_BYTES(8, token->kad->session_key);
11691177
ENCODE(token->kad->start);
11701178
ENCODE(token->kad->expiry);
11711179
ENCODE(token->kad->primary_flag);

0 commit comments

Comments
 (0)