net/rxrpc, crypto: Add Kerberos crypto lib and AF_RXRPC GSSAPI security class
Subsystems (12)
David Howells
maintainercover net/rxrpc, crypto: Add Kerberos crypto lib and AF_RXRPC GSSAPI security class
Here's a set of patches to add basic support for the AF_RXRPC GSSAPI security class. It provides transport security for keys that match the security index 4 (OpenAFS) and security index 6 (YFS) for connections to the AFS fileserver and VL server.
It can also be used to provide transport security on the callback channel, but a further set of patches is required to provide the token and key to set that up when the client responds to the fileserver's challenge.
[!] Note that these patches are on top of two fixes previously posted:
https://lore.kernel.org/netdev/[email protected]/
This series of patches consist of four parts:
(1) Provide an AEAD crypto driver, krb5enc, that mirrors the authenc driver, but that hashes the plaintext, not the ciphertext. This was made a separate module rather than just being a part of the authenc driver because it has to do all of the constituent operations in the opposite order - which impacts the async op handling.
Testmgr data is provided for AES+SHA2 and Camellia combinations of authenc and krb5enc used by the krb5 library. AES+SHA1 is not provided as the RFCs don't contain usable test vectors.
(2) Provide a Kerberos 5 crypto library. This is an extract from the sunrpc driver as that code can be shared between sunrpc/nfs and rxrpc/afs. This provides encryption, decryption, get MIC and verify MIC routines that use and wrap the crypto functions, along with some functions to provide layout management.
This supports AES+SHA1, AES+SHA2 and Camellia encryption types.
Self-testing is provided that goes further than is possible with testmgr, doing subkey derivation as well.
(3) Push reponding to CHALLENGE packets over to recvmsg() or the kernel equivalent so that the application layer can include user-defined information in the RESPONSE packet. In a follow-up patch set, this will allow the callback channel to be secured by the AFS filesystem.
(4) The AF_RXRPC RxGK security class that uses a key obtained from the AFS GSS security service to do Kerberos 5-based encryption instead of pcbc(fcrypt) and pcbc(des).
Can these all go through the same tree rather than the crypto bits going via the crypto tree and the rxrpc bits needing to go via the networking tree?
The patches can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=crypto-krb5
David
David Howells (24):
crypto/krb5: Add API Documentation
crypto/krb5: Add some constants out of sunrpc headers
crypto: Add 'krb5enc' hash and cipher AEAD algorithm crypto/krb5: Test manager data
crypto/krb5: Implement Kerberos crypto core
crypto/krb5: Add an API to query the layout of the crypto section crypto/krb5: Add an API to alloc and prepare a crypto object crypto/krb5: Add an API to perform requests
crypto/krb5: Provide infrastructure and key derivation crypto/krb5: Implement the Kerberos5 rfc3961 key derivation crypto/krb5: Provide RFC3961 setkey packaging functions crypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt
functions
crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic crypto/krb5: Implement the AES enctypes from rfc3962 crypto/krb5: Implement the AES enctypes from rfc8009 crypto/krb5: Implement the Camellia enctypes from rfc6803 crypto/krb5: Implement crypto self-testing
rxrpc: Pull out certain app callback funcs into an ops table
rxrpc: Pass CHALLENGE packets to the call for recvmsg() to respond to
rxrpc: Add the security index for yfs-rxgk
rxrpc: Add YFS RxGK (GSSAPI) security class
rxrpc: rxgk: Provide infrastructure and key derivation
rxrpc: rxgk: Implement the yfs-rxgk security class (GSSAPI)
rxrpc: rxgk: Implement connection rekeying
Documentation/crypto/index.rst | 1 + Documentation/crypto/krb5.rst | 262 ++++++ crypto/Kconfig | 13 + crypto/Makefile | 3 + crypto/krb5/Kconfig | 26 + crypto/krb5/Makefile | 18 + crypto/krb5/internal.h | 247 ++++++ crypto/krb5/krb5_api.c | 452 ++++++++++ crypto/krb5/krb5_kdf.c | 145 ++++ crypto/krb5/rfc3961_simplified.c | 797 +++++++++++++++++ crypto/krb5/rfc3962_aes.c | 115 +++ crypto/krb5/rfc6803_camellia.c | 237 ++++++ crypto/krb5/rfc8009_aes2.c | 362 ++++++++ crypto/krb5/selftest.c | 544 ++++++++++++ crypto/krb5/selftest_data.c | 291 +++++++ crypto/krb5enc.c | 504 +++++++++++ crypto/testmgr.c | 16 + crypto/testmgr.h | 351 ++++++++ fs/afs/Makefile | 1 + fs/afs/cm_security.c | 54 ++ fs/afs/internal.h | 6 + fs/afs/misc.c | 13 + fs/afs/rxrpc.c | 16 +- include/crypto/authenc.h | 2 + include/crypto/krb5.h | 160 ++++ include/keys/rxrpc-type.h | 17 + include/net/af_rxrpc.h | 37 +- include/trace/events/rxrpc.h | 53 +- include/uapi/linux/rxrpc.h | 63 +- net/rxrpc/Kconfig | 10 + net/rxrpc/Makefile | 5 +- net/rxrpc/af_rxrpc.c | 45 +- net/rxrpc/ar-internal.h | 57 +- net/rxrpc/call_accept.c | 31 +- net/rxrpc/call_object.c | 5 +- net/rxrpc/conn_event.c | 97 ++- net/rxrpc/conn_object.c | 2 + net/rxrpc/insecure.c | 13 +- net/rxrpc/io_thread.c | 8 +- net/rxrpc/key.c | 185 ++++ net/rxrpc/output.c | 58 +- net/rxrpc/protocol.h | 20 + net/rxrpc/recvmsg.c | 114 ++- net/rxrpc/rxgk.c | 1360 ++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 285 +++++++ net/rxrpc/rxgk_common.h | 138 +++ net/rxrpc/rxgk_kdf.c | 287 +++++++ net/rxrpc/rxkad.c | 287 ++++--- net/rxrpc/rxperf.c | 10 +- net/rxrpc/security.c | 3 + net/rxrpc/sendmsg.c | 69 +- net/rxrpc/server_key.c | 40 + 52 files changed, 7737 insertions(+), 198 deletions(-) create mode 100644 Documentation/crypto/krb5.rst create mode 100644 crypto/krb5/Kconfig create mode 100644 crypto/krb5/Makefile create mode 100644 crypto/krb5/internal.h create mode 100644 crypto/krb5/krb5_api.c create mode 100644 crypto/krb5/krb5_kdf.c create mode 100644 crypto/krb5/rfc3961_simplified.c create mode 100644 crypto/krb5/rfc3962_aes.c create mode 100644 crypto/krb5/rfc6803_camellia.c create mode 100644 crypto/krb5/rfc8009_aes2.c create mode 100644 crypto/krb5/selftest.c create mode 100644 crypto/krb5/selftest_data.c create mode 100644 crypto/krb5enc.c create mode 100644 fs/afs/cm_security.c create mode 100644 include/crypto/krb5.h create mode 100644 net/rxrpc/rxgk.c create mode 100644 net/rxrpc/rxgk_app.c create mode 100644 net/rxrpc/rxgk_common.h create mode 100644 net/rxrpc/rxgk_kdf.c
David Howells
maintainerPATCH 1/24 crypto/krb5: Add API Documentation
Add API documentation for the kerberos crypto library.
--- Documentation/crypto/index.rst | 1 + Documentation/crypto/krb5.rst | 262 +++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 Documentation/crypto/krb5.rst
Documentation/crypto/index.rst +1 -0
@@ -26,3 +26,4 @@ for cryptographic use cases, as well as programming examples. api-samples descore-readme device_drivers/index + krb5
Documentation/crypto/krb5.rst new file +262 -0
262 lines not on this page · raw message
David Howells
maintainerPATCH 2/24 crypto/krb5: Add some constants out of sunrpc headers
In reply to David HowellsAdd some constants from the sunrpc headers.
--- include/crypto/krb5.h | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/crypto/krb5.h
include/crypto/krb5.h new file +51 -0
@@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Kerberos 5 crypto +* +* Copyright (C) 2025 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#ifndef _CRYPTO_KRB5_H +#define _CRYPTO_KRB5_H + +/* +* Per Kerberos v5 protocol spec crypto types from the wire. These get mapped +* to linux kernel crypto routines. +*/ +#define KRB5_ENCTYPE_NULL 0x0000 +#define KRB5_ENCTYPE_DES_CBC_CRC 0x0001/* DES cbc mode with CRC-32 */ +#define KRB5_ENCTYPE_DES_CBC_MD4 0x0002/* DES cbc mode with RSA-MD4 */ +#define KRB5_ENCTYPE_DES_CBC_MD5 0x0003/* DES cbc mode with RSA-MD5 */ +#define KRB5_ENCTYPE_DES_CBC_RAW 0x0004/* DES cbc mode raw */ +/* XXX deprecated? */ +#define KRB5_ENCTYPE_DES3_CBC_SHA 0x0005/* DES-3 cbc mode with NIST-SHA */ +#define KRB5_ENCTYPE_DES3_CBC_RAW 0x0006/* DES-3 cbc mode raw */ +#define KRB5_ENCTYPE_DES_HMAC_SHA1 0x0008 +#define KRB5_ENCTYPE_DES3_CBC_SHA1 0x0010 +#define KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011 +#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012 +#define KRB5_ENCTYPE_ARCFOUR_HMAC 0x0017 +#define KRB5_ENCTYPE_ARCFOUR_HMAC_EXP 0x0018 +#define KRB5_ENCTYPE_UNKNOWN 0x01ff + +#define KRB5_CKSUMTYPE_CRC32 0x0001 +#define KRB5_CKSUMTYPE_RSA_MD4 0x0002 +#define KRB5_CKSUMTYPE_RSA_MD4_DES 0x0003 +#define KRB5_CKSUMTYPE_DESCBC 0x0004 +#define KRB5_CKSUMTYPE_RSA_MD5 0x0007 +#define KRB5_CKSUMTYPE_RSA_MD5_DES 0x0008 +#define KRB5_CKSUMTYPE_NIST_SHA 0x0009 +#define KRB5_CKSUMTYPE_HMAC_SHA1_DES3 0x000c +#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f +#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010 +#define KRB5_CKSUMTYPE_HMAC_MD5_ARCFOUR -138/* Microsoft md5 hmac cksumtype */ + +/* +* Constants used for key derivation +*/ +/* from rfc3961 */ +#define KEY_USAGE_SEED_CHECKSUM (0x99) +#define KEY_USAGE_SEED_ENCRYPTION (0xAA) +#define KEY_USAGE_SEED_INTEGRITY (0x55) + +#endif /* _CRYPTO_KRB5_H */
David Howells
maintainerPATCH 3/24 crypto: Add 'krb5enc' hash and cipher AEAD algorithm
In reply to David HowellsAdd an AEAD template that does hash-then-cipher (unlike authenc that does cipher-then-hash). This is required for a number of Kerberos 5 encoding types.
[!] Note that the net/sunrpc/auth_gss/ implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:
(1) firstly, there is an optimised assembly version of cts(cbc(aes)) on
x86_64 that should be used instead of having two ciphers;
(2) secondly, none of the hardware offload drivers seem to offer CTS support (Intel QAT does not, for instance).
However, I don't know if it's possible to query the crypto API to find out whether there's an optimised CTS algorithm available.
--- crypto/Kconfig | 12 + crypto/Makefile | 1 + crypto/krb5enc.c | 504 +++++++++++++++++++++++++++++++++++++++ include/crypto/authenc.h | 2 + 4 files changed, 519 insertions(+) create mode 100644 crypto/krb5enc.c
crypto/Kconfig +12 -0
@@ -228,6 +228,18 @@ config CRYPTO_AUTHENC This is required for IPSec ESP (XFRM_ESP). +config CRYPTO_KRB5ENC + tristate "Kerberos 5 combined hash+cipher support" + select CRYPTO_AEAD + select CRYPTO_SKCIPHER + select CRYPTO_MANAGER + select CRYPTO_HASH + select CRYPTO_NULL + help + Combined hash and cipher support for Kerberos 5 RFC3961 simplified + profile. This is required for Kerberos 5-style encryption, used by + sunrpc/NFS and rxrpc/AFS. + config CRYPTO_TEST tristate "Testing module" depends on m || EXPERT
crypto/Makefile +1 -0
@@ -159,6 +159,7 @@ obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_generic.o CFLAGS_crct10dif_generic.o += -DARCH=$(ARCH) obj-$(CONFIG_CRYPTO_CRC64_ROCKSOFT) += crc64_rocksoft_generic.o obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o +obj-$(CONFIG_CRYPTO_KRB5ENC) += krb5enc.o obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o obj-$(CONFIG_CRYPTO_LZ4) += lz4.o obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o
crypto/krb5enc.c new file +504 -0
504 lines not on this page · raw message
include/crypto/authenc.h +2 -0
@@ -28,5 +28,7 @@ struct crypto_authenc_keys {int crypto_authenc_extractkeys (struct crypto_authenc_keys *keys,const u8 *key,unsigned int keylen); +int crypto_krb5enc_extractkeys (struct crypto_authenc_keys *keys,const u8 *key, +unsigned int keylen);#endif /* _CRYPTO_AUTHENC_H */
Herbert Xu
maintainerRe: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 6 lines · David Howells
[!] Note that the
net/sunrpc/auth_gss/implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:
The CTS template will take any hardware accelerated CBC implementation and turn it into CTS.
So there is no reason to do the CTS/CBC thing by hand at all.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
David Howells
maintainerRe: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 10 lines · Herbert Xu
Quoted 5 lines
[!] Note that the
net/sunrpc/auth_gss/implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:The CTS template will take any hardware accelerated CBC implementation and turn it into CTS.
So there is no reason to do the CTS/CBC thing by hand at all.
Glad to hear it. I'm just reporting what net/sunrpc/ does now. My suspicion is that this is from before a lot of cpu crypto-based optimisations were made available in the crypto layer.
David
Re: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
In reply to David HowellsQuoted 6 lines · David Howells
[!] Note that the
net/sunrpc/auth_gss/implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:
Quoted 8 lines
(1) firstly, there is an optimised assembly version of cts(cbc(aes)) on
x86_64 that should be used instead of having two ciphers;(2) secondly, none of the hardware offload drivers seem to offer CTS support (Intel QAT does not, for instance).
However, I don't know if it's possible to query the crypto API to find out whether there's an optimised CTS algorithm available.
Linux's "cts" is specifically the CS3 variant of CTS (using the terminology of NIST SP800-38A https://dl.acm.org/doi/pdf/10.5555/2206248) which unconditionally swaps the last two blocks. Is that the variant that is needed here? SP800-38A mentions that CS3 is the variant used in Kerberos 5, so I assume yes. If yes, then you need to use cts(cbc(aes)) unconditionally. (BTW, I hope you have some test that shows that you actually implemented the Kerberos protocol correctly?)
x86_64 already has an AES-NI assembly optimized cts(cbc(aes)), as you mentioned. I will probably add a VAES optimized cts(cbc(aes)) at some point; I've just been doing other modes first. I don't see why off-CPU hardware offload support should deserve much attention here, given the extremely high speed of on-CPU crypto these days and the great difficulty of integrating off-CPU acceleration efficiently. In particular it seems weird to consider Intel QAT a reasonable thing to use over VAES. Regardless, absent direct support for cts(cbc(aes)) the cts template will build it on top of cbc(aes) anyway.
- Eric
David Howells
maintainerRe: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 4 lines · Eric Biggers
Linux's "cts" is specifically the CS3 variant of CTS (using the terminology of NIST SP800-38A https://dl.acm.org/doi/pdf/10.5555/2206248) which unconditionally swaps the last two blocks. Is that the variant that is needed here?
It's what NFS/SunRPC does and what works with the AuriStor YFS/AFS RxGK implementation, so I presume so.
Quoted 4 lines
SP800-38A mentions that CS3 is the variant used in Kerberos 5, so I assume yes. If yes, then you need to use cts(cbc(aes)) unconditionally. (BTW, I hope you have some test that shows that you actually implemented the Kerberos protocol correctly?)
Depends what you mean by "the Kerberos protocol", I suppose. I took the kerberos implementation from net/sunrpc/ and genericised it a bit so that I could also use it for net/rxrpc/ and added AES+SHA2 and Camellia. It doesn't use the Kerberos communications protocol per se, just the encryption formats.
To test this, I added test vectors for to crypto/testmgr.h and gave the krb5 lib its own selftests since those can do more comprehensive testing than the testmgr. Note that I didn't find test vectors for AES+SHA1 that I could use, so I haven't added those. I could generate some, by printing samples generated by my code - but that's kind of circular:-/
On top of that, I've tested the code by running xfstests, git checkouts and kernel builds against an AuriStor YFS server with an RxGK key - so it at least agrees with that server's expectations.
Quoted 3 lines
x86_64already has an AES-NI assembly optimized cts(cbc(aes)), as you mentioned. I will probably add a VAES optimized cts(cbc(aes)) at some point; I've just been doing other modes first.
One of the issues I have with doing it on the CPU is that you have to do two operations and, currently, they're done synchronously and serially.
Can you implement "auth5enc(hmac(sha256),cts(cbc(aes)))" in assembly and actually make the assembly do both the AES and SHA at the same time? It looks like it *might* be possible - but that you might be an XMM register short of being able to do it:-/
Quoted 5 lines
I don't see why off-CPU hardware offload support should deserve much attention here, given the extremely high speed of on-CPU crypto these days and the great difficulty of integrating off-CPU acceleration efficiently. In particular it seems weird to consider Intel QAT a reasonable thing to use over VAES.
Because some modern CPUs come with on-die crypto offload - and that can do hash+encrypt or encrypt+hash in parallel. Now, there are a couple of issues with using the QAT here:
(1) It doesn't support CTS. This means we'd have to impose the CTS from above - and that may well make it unusable in doing hash + encrypt simultaneously.
(2) It really needs batching to make it cheap enough to use. This might actually be less of a problem - at least for rxgk. The data is split up into fixed-size packets, but for a large amount of data we can end up filling packets faster than we can transmit them. This offers the opportunity to batch them - up to ~8192 packets in a single batch.
For NFS, things are a bit different. Because that mostly uses a streaming transport these days, it wants to prepare a single huge message in one go - and being able to parallellise the encrypt and the hash could be a benefit.
David
Re: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 7 lines · David Howells
One of the issues I have with doing it on the CPU is that you have to do two operations and, currently, they're done synchronously and serially.
Can you implement "auth5enc(hmac(sha256),cts(cbc(aes)))" in assembly and actually make the assembly do both the AES and SHA at the same time? It looks like it *might* be possible - but that you might be an XMM register short of being able to do it:-/
Yes, that would be the proper way to optimize that algorithm. Someone just needs to do it. (And presumably you want this one and not Camellia which you are also pushing for some reason?)
Quoted 20 lines
Quoted 5 lines
I don't see why off-CPU hardware offload support should deserve much attention here, given the extremely high speed of on-CPU crypto these days and the great difficulty of integrating off-CPU acceleration efficiently. In particular it seems weird to consider Intel QAT a reasonable thing to use over VAES.
Because some modern CPUs come with on-die crypto offload - and that can do hash+encrypt or encrypt+hash in parallel. Now, there are a couple of issues with using the QAT here:
(1) It doesn't support CTS. This means we'd have to impose the CTS from above - and that may well make it unusable in doing hash + encrypt simultaneously.
(2) It really needs batching to make it cheap enough to use. This might actually be less of a problem - at least for rxgk. The data is split up into fixed-size packets, but for a large amount of data we can end up filling packets faster than we can transmit them. This offers the opportunity to batch them - up to ~8192 packets in a single batch.
Quoted 3 lines
For NFS, things are a bit different. Because that mostly uses a streaming transport these days, it wants to prepare a single huge message in one go - and being able to parallellise the encrypt and the hash could be a benefit.
Right, the batching is always a huge issue for those types of accelerators. A much more promising approach is to just fully take advantage of the CPU instructions that already accelerate the same algorithms very well.
- Eric
Herbert Xu
maintainerRe: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
In reply to David HowellsQuoted 6 lines · David Howells
(2) It really needs batching to make it cheap enough to use. This might actually be less of a problem - at least for rxgk. The data is split up into fixed-size packets, but for a large amount of data we can end up filling packets faster than we can transmit them. This offers the opportunity to batch them - up to ~8192 packets in a single batch.
Hopefully this will become a solved problem once my request chaining work is complete. This should allow you to provide enough data that even something slow like PCI offload can work.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
In reply to David HowellsHi David,
Quoted 13 lines · David Howells
Add an AEAD template that does hash-then-cipher (unlike authenc that does cipher-then-hash). This is required for a number of Kerberos 5 encoding types.
[!] Note that the
net/sunrpc/auth_gss/implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:(1) firstly, there is an optimised assembly version of cts(cbc(aes)) on
x86_64 that should be used instead of having two ciphers;
Quoted 7 lines
(2) secondly, none of the hardware offload drivers seem to offer CTS support (Intel QAT does not, for instance).
However, I don't know if it's possible to query the crypto API to find out whether there's an optimised CTS algorithm available.
Signed-off-by David Howells <[email protected]>
Thanks for your patch, which is now commit d1775a177f7f3815 ("crypto:
Add 'krb5enc' hash and cipher AEAD algorithm") in crypto/master.
Quoted 7 lines
crypto/Kconfig +1
-0@@ -228,6 +228,18 @@ config CRYPTO_AUTHENC This is required for IPSec ESP (XFRM_ESP). +config CRYPTO_KRB5ENC
crypto/Kconfig config CRYPTO_AUTHENC · line 241
Quoted 10 lines
crypto/Kconfig +10
-0+ tristate "Kerberos 5 combined hash+cipher support" + select CRYPTO_AEAD + select CRYPTO_SKCIPHER + select CRYPTO_MANAGER + select CRYPTO_HASH + select CRYPTO_NULL + help + Combined hash and cipher support for Kerberos 5 RFC3961 simplified + profile. This is required for Kerberos 5-style encryption, used by + sunrpc/NFS and rxrpc/AFS.
Hence shouldn't the latter (e.g. RPCSEC_GSS_KRB5) select CRYPTO_KRB5ENC or CRYPTO_KRB5? Or am I missing something?
Thanks!
crypto/Kconfig config CRYPTO_AUTHENC · line 245
Quoted 4 lines
crypto/Kconfig +1
-0+ config CRYPTO_TEST tristate "Testing module" depends on m || EXPERT
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
David Howells
maintainerRe: [PATCH net 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 6 lines · Geert Uytterhoeven
crypto/Kconfig config CRYPTO_AUTHENC · line 241
Quoted 3 lines
crypto/Kconfig +3
-0+ Combined hash and cipher support for Kerberos 5 RFC3961 simplified + profile. This is required for Kerberos 5-style encryption, used by + sunrpc/NFS and rxrpc/AFS.Hence shouldn't the latter (e.g.
RPCSEC_GSS_KRB5) selectCRYPTO_KRB5ENCorCRYPTO_KRB5? Or am I missing something?
SunRPC hasn't been converted to use it yet. The help text is slightly misleading, I guess: "Kerberos 5-style encryption" is used by sunrpc/NFS within the kernel, but not this library yet.
Unfortunately, the rxrpc/AFS patches didn't make it in due to them requiring to go through the net-next tree, but having dependencies on both the VFS tree and the crypto tree.
Herbert wanted the crypto patches (krb5 lib) based on his tree, which I did and he pulled it - but then this disqualified it for also being pulled into net-next as that would've pulled *all* the crypodev patches there as well.
For reference, the rxrpc patches can be found here:
https://web.git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=rxrpc-next
I intend to post them for net-next inclusion after the merge window.
David
David Howells
maintainerPATCH 4/24 crypto/krb5: Test manager data
In reply to David HowellsAdd Kerberos crypto tests to the test manager database. This covers:
camellia128-cts-cmac samples from RFC6803 camellia256-cts-cmac samples from RFC6803 aes128-cts-hmac-sha256-128 samples from RFC8009 aes256-cts-hmac-sha384-192 samples from RFC8009
but not:
aes128-cts-hmac-sha1-96 aes256-cts-hmac-sha1-96
as the test samples in RFC3962 don't seem to be suitable.
--- crypto/testmgr.c | 16 +++ crypto/testmgr.h | 351 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 367 insertions(+)
crypto/testmgr.c +16 -0
@@ -4504,6 +4504,12 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "authenc(hmac(sha256),ctr(aes))", .test = alg_test_null, .fips_allowed = 1, + }, { + .alg = "authenc(hmac(sha256),cts(cbc(aes)))", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_aes128_cts_hmac_sha256_128) + } }, { .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))", .test = alg_test_null,
@@ -4524,6 +4530,12 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "authenc(hmac(sha384),ctr(aes))", .test = alg_test_null, .fips_allowed = 1, + }, { + .alg = "authenc(hmac(sha384),cts(cbc(aes)))", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_aes256_cts_hmac_sha384_192) + } }, { .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))", .test = alg_test_null,
@@ -5397,6 +5409,10 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "jitterentropy_rng", .fips_allowed = 1, .test = alg_test_null, + }, { + .alg = "krb5enc(cmac(camellia),cts(cbc(camellia)))", + .test = alg_test_aead, + .suite.aead =__VECS (krb5_test_camellia_cts_cmac) }, { .alg = "lrw(aes)", .generic_driver = "lrw(ecb(aes-generic))",
crypto/testmgr.h +351 -0
355 lines not on this page · raw message
David Howells
maintainerPATCH 5/24 crypto/krb5: Implement Kerberos crypto core
In reply to David HowellsProvide core structures, an encoding-type registry and basic module and config bits for a generic Kerberos crypto library.
--- crypto/Kconfig | 1 + crypto/Makefile | 2 + crypto/krb5/Kconfig | 14 ++++++ crypto/krb5/Makefile | 9 ++++ crypto/krb5/internal.h | 112 +++++++++++++++++++++++++++++++++++++++++ crypto/krb5/krb5_api.c | 42 ++++++++++++++++ include/crypto/krb5.h | 54 ++++++++++++++++++++ 7 files changed, 234 insertions(+) create mode 100644 crypto/krb5/Kconfig create mode 100644 crypto/krb5/Makefile create mode 100644 crypto/krb5/internal.h create mode 100644 crypto/krb5/krb5_api.c
crypto/Kconfig +1 -0
@@ -1472,5 +1472,6 @@ endif source "drivers/crypto/Kconfig" source "crypto/asymmetric_keys/Kconfig" source "certs/Kconfig" +source "crypto/krb5/Kconfig" endif # if CRYPTO
crypto/Makefile +2 -0
@@ -213,3 +213,5 @@ obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o # Key derivation function # obj-$(CONFIG_CRYPTO_KDF800108_CTR) += kdf_sp800108.o + +obj-$(CONFIG_CRYPTO_KRB5) += krb5/
crypto/krb5/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config CRYPTO_KRB5 + tristate "Kerberos 5 crypto" + select CRYPTO_MANAGER + select CRYPTO_KRB5ENC + select CRYPTO_AUTHENC + select CRYPTO_SKCIPHER + select CRYPTO_HASH_INFO + select CRYPTO_SHA1 + select CRYPTO_CBC + select CRYPTO_CTS + select CRYPTO_AES + help + Provide a library for provision of Kerberos-5-based crypto. This is + intended for network filesystems to use.
crypto/krb5/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for asymmetric cryptographic keys +# + +krb5-y += \ + krb5_api.o + +obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h new file +112 -0
112 lines not on this page · raw message
crypto/krb5/krb5_api.c new file +42 -0
42 lines not on this page · raw message
include/crypto/krb5.h +54 -0
64 lines not on this page · raw message
David Howells
maintainerPATCH 6/24 crypto/krb5: Add an API to query the layout of the crypto section
In reply to David HowellsProvide some functions to allow the called to find out about the layout of the crypto section:
(1) Calculate, for a given size of data, how big a buffer will be required to hold it and where the data will be within it.
(2) Calculate, for an amount of buffer, what's the maximum size of data that will fit therein, and where it will start.
(3) Determine where the data will be in a received message.
--- crypto/krb5/krb5_api.c | 108 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 9 ++++ 2 files changed, 117 insertions(+)
crypto/krb5/krb5_api.c +108 -0
@@ -40,3 +40,111 @@ const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype)return NULL ; }EXPORT_SYMBOL (crypto_krb5_find_enctype); + +/** +* crypto_krb5_how_much_buffer - Work out how much buffer is required for an amount of data +* @krb5: The encoding to use. +* @mode: The mode in which to operated (checksum/encrypt) +* @data_size: How much data we want to allow for +* @_offset: Where to place the offset into the buffer +* +* Calculate how much buffer space is required to wrap a given amount of data. +* This allows for a confounder, padding and checksum as appropriate. The +* amount of buffer required is returned and the offset into the buffer at +* which the data will start is placed in *_offset. +*/ +size_t crypto_krb5_how_much_buffer (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t data_size,size_t *_offset) +{ +switch (mode) { +case KRB5_CHECKSUM_MODE : + *_offset = krb5->cksum_len; +return krb5->cksum_len + data_size; + +case KRB5_ENCRYPT_MODE : + *_offset = krb5->conf_len; +return krb5->conf_len + data_size + krb5->cksum_len; + +default : +WARN_ON (1 ); + *_offset =0 ; +return 0 ; + } +} +EXPORT_SYMBOL (crypto_krb5_how_much_buffer); + +/** +* crypto_krb5_how_much_data - Work out how much data can fit in an amount of buffer +* @krb5: The encoding to use. +* @mode: The mode in which to operated (checksum/encrypt) +* @_buffer_size: How much buffer we want to allow for (may be reduced) +* @_offset: Where to place the offset into the buffer +* +* Calculate how much data can be fitted into given amount of buffer. This +* allows for a confounder, padding and checksum as appropriate. The amount of +* data that will fit is returned, the amount of buffer required is shrunk to +* allow for alignment and the offset into the buffer at which the data will +* start is placed in *_offset. +*/ +size_t crypto_krb5_how_much_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_buffer_size,size_t *_offset) +{ +size_t buffer_size = *_buffer_size, data_size; + +switch (mode) { +case KRB5_CHECKSUM_MODE : +if (WARN_ON (buffer_size < krb5->cksum_len +1 )) + goto bad; + *_offset = krb5->cksum_len; +return buffer_size - krb5->cksum_len; + +case KRB5_ENCRYPT_MODE : +if (WARN_ON (buffer_size < krb5->conf_len +1 + krb5->cksum_len)) + goto bad; + data_size = buffer_size - krb5->cksum_len; + *_offset = krb5->conf_len; +return data_size - krb5->conf_len; + +default : +WARN_ON (1 ); + goto bad; + } + +bad: + *_offset =0 ; +return 0 ; +} +EXPORT_SYMBOL (crypto_krb5_how_much_data); + +/** +* crypto_krb5_where_is_the_data - Find the data in a decrypted message +* @krb5: The encoding to use. +* @mode: Mode of operation +* @_offset: Offset of the secure blob in the buffer; updated to data offset. +* @_len: The length of the secure blob; updated to data length. +* +* Find the offset and size of the data in a secure message so that this +* information can be used in the metadata buffer which will get added to the +* digest by crypto_krb5_verify_mic(). +*/ +void crypto_krb5_where_is_the_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_offset,size_t *_len) +{ +switch (mode) { +case KRB5_CHECKSUM_MODE : + *_offset += krb5->cksum_len; + *_len -= krb5->cksum_len; +return ; +case KRB5_ENCRYPT_MODE : + *_offset += krb5->conf_len; + *_len -= krb5->conf_len + krb5->cksum_len; +return ; +default : +WARN_ON_ONCE (1 ); +return ; + } +} +EXPORT_SYMBOL (crypto_krb5_where_is_the_data);
include/crypto/krb5.h +9 -0
@@ -101,5 +101,14 @@ struct krb5_enctype {* krb5_api.c */ const struct krb5_enctype *crypto_krb5_find_enctype (u32 enctype); +size_t crypto_krb5_how_much_buffer (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t data_size,size_t *_offset); +size_t crypto_krb5_how_much_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_buffer_size,size_t *_offset); +void crypto_krb5_where_is_the_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_offset,size_t *_len);#endif /* _CRYPTO_KRB5_H */
David Howells
maintainerPATCH 7/24 crypto/krb5: Add an API to alloc and prepare a crypto object
In reply to David HowellsAdd an API by which users of the krb5 crypto library can get an allocated and keyed crypto object.
For encryption-mode operation, an AEAD object is returned; for checksum-mode operation, a synchronous hash object is returned.
--- crypto/krb5/internal.h | 10 +++ crypto/krb5/krb5_api.c | 144 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 7 ++ 3 files changed, 161 insertions(+)
crypto/krb5/internal.h +10 -0
@@ -110,3 +110,13 @@ struct krb5_crypto_profile {#define krb5_digest_size (TFM ) \ crypto_roundup(crypto_shash_digestsize(TFM))#define round16 (x) (((x) + 15) & ~15) + +/* +* krb5_api.c +*/ +struct crypto_aead *krb5_prepare_encryption (const struct krb5_enctype *krb5, +const struct krb5_buffer *keys, +gfp_t gfp); +struct crypto_shash *krb5_prepare_checksum (const struct krb5_enctype *krb5, +const struct krb5_buffer *Kc, +gfp_t gfp);
crypto/krb5/krb5_api.c +144 -0
147 lines not on this page · raw message
include/crypto/krb5.h +7 -0
@@ -10,6 +10,7 @@#include <linux/crypto.h> #include <crypto/aead.h> +#include <crypto/hash.h> struct crypto_shash ;struct scatterlist ;
@@ -110,5 +111,11 @@ size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,void crypto_krb5_where_is_the_data (const struct krb5_enctype *krb5,enum krb5_crypto_mode mode,size_t *_offset,size_t *_len); +struct crypto_aead *crypto_krb5_prepare_encryption (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +u32 usage,gfp_t gfp); +struct crypto_shash *crypto_krb5_prepare_checksum (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +u32 usage,gfp_t gfp);#endif /* _CRYPTO_KRB5_H */
David Howells
maintainerPATCH 8/24 crypto/krb5: Add an API to perform requests
In reply to David HowellsAdd an API by which users of the krb5 crypto library can perform crypto requests, such as encrypt, decrypt, get_mic and verify_mic. These functions take the previously prepared crypto objects to work on.
--- crypto/krb5/krb5_api.c | 141 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 21 ++++++ 2 files changed, 162 insertions(+)
crypto/krb5/krb5_api.c +141 -0
@@ -292,3 +292,144 @@ struct crypto_shash *crypto_krb5_prepare_checksum(const struct krb5_enctype *krbreturn ERR_PTR (ret); }EXPORT_SYMBOL (crypto_krb5_prepare_checksum); + +/** +* crypto_krb5_encrypt - Apply Kerberos encryption and integrity. +* @krb5: The encoding to use. +* @aead: The keyed crypto object to use. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @sg_len: The size of the buffer. +* @data_offset: The offset of the data in the @sg buffer. +* @data_len: The length of the data. +* @preconfounded: True if the confounder is already inserted. +* +* Using the specified Kerberos encoding, insert a confounder and padding as +* needed, encrypt this and the data in place and insert an integrity checksum +* into the buffer. +* +* The buffer must include space for the confounder, the checksum and any +* padding required. The caller can preinsert the confounder into the buffer +* (for testing, for example). +* +* The resulting secured blob may be less than the size of the buffer. +* +* Returns the size of the secure blob if successful, -ENOMEM on an allocation +* failure, -EFAULT if there is insufficient space, -EMSGSIZE if the confounder +* is too short or the data is misaligned. Other errors may also be returned +* from the crypto layer. +*/ +ssize_t crypto_krb5_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded) +{ +if (WARN_ON (data_offset > sg_len || + data_len > sg_len || + data_offset > sg_len - data_len)) +return -EMSGSIZE ; +return krb5->profile->encrypt (krb5, aead, sg, nr_sg, sg_len, + data_offset, data_len, preconfounded); +} +EXPORT_SYMBOL (crypto_krb5_encrypt); + +/** +* crypto_krb5_decrypt - Validate and remove Kerberos encryption and integrity. +* @krb5: The encoding to use. +* @aead: The keyed crypto object to use. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @_offset: Offset of the secure blob in the buffer; updated to data offset. +* @_len: The length of the secure blob; updated to data length. +* +* Using the specified Kerberos encoding, check and remove the integrity +* checksum and decrypt the secure region, stripping off the confounder. +* +* If successful, @_offset and @_len are updated to outline the region in which +* the data plus the trailing padding are stored. The caller is responsible +* for working out how much padding there is and removing it. +* +* Returns the 0 if successful, -ENOMEM on an allocation failure; sets +* *_error_code and returns -EPROTO if the data cannot be parsed, or -EBADMSG +* if the integrity checksum doesn't match). Other errors may also be returned +* from the crypto layer. +*/ +int crypto_krb5_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len) +{ +return krb5->profile->decrypt (krb5, aead, sg, nr_sg, _offset, _len); +} +EXPORT_SYMBOL (crypto_krb5_decrypt); + +/** +* crypto_krb5_get_mic - Apply Kerberos integrity checksum. +* @krb5: The encoding to use. +* @shash: The keyed hash to use. +* @metadata: Metadata to add into the hash before adding the data. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @sg_len: The size of the buffer. +* @data_offset: The offset of the data in the @sg buffer. +* @data_len: The length of the data. +* +* Using the specified Kerberos encoding, calculate and insert an integrity +* checksum into the buffer. +* +* The buffer must include space for the checksum at the front. +* +* Returns the size of the secure blob if successful, -ENOMEM on an allocation +* failure, -EFAULT if there is insufficient space, -EMSGSIZE if the gap for +* the checksum is too short. Other errors may also be returned from the +* crypto layer. +*/ +ssize_t crypto_krb5_get_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len) +{ +if (WARN_ON (data_offset > sg_len || + data_len > sg_len || + data_offset > sg_len - data_len)) +return -EMSGSIZE ; +return krb5->profile->get_mic (krb5, shash, metadata, sg, nr_sg, sg_len, + data_offset, data_len); +} +EXPORT_SYMBOL (crypto_krb5_get_mic); + +/** +* crypto_krb5_verify_mic - Validate and remove Kerberos integrity checksum. +* @krb5: The encoding to use. +* @shash: The keyed hash to use. +* @metadata: Metadata to add into the hash before adding the data. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @_offset: Offset of the secure blob in the buffer; updated to data offset. +* @_len: The length of the secure blob; updated to data length. +* +* Using the specified Kerberos encoding, check and remove the integrity +* checksum. +* +* If successful, @_offset and @_len are updated to outline the region in which +* the data is stored. +* +* Returns the 0 if successful, -ENOMEM on an allocation failure; sets +* *_error_code and returns -EPROTO if the data cannot be parsed, or -EBADMSG +* if the checksum doesn't match). Other errors may also be returned from the +* crypto layer. +*/ +int crypto_krb5_verify_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len) +{ +return krb5->profile->verify_mic (krb5, shash, metadata, sg, nr_sg, + _offset, _len); +} +EXPORT_SYMBOL (crypto_krb5_verify_mic);
include/crypto/krb5.h +21 -0
@@ -117,5 +117,26 @@ struct crypto_aead *crypto_krb5_prepare_encryption(const struct krb5_enctype *krstruct crypto_shash *crypto_krb5_prepare_checksum (const struct krb5_enctype *krb5,const struct krb5_buffer *TK ,u32 usage,gfp_t gfp); +ssize_t crypto_krb5_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded); +int crypto_krb5_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len); +ssize_t crypto_krb5_get_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len); +int crypto_krb5_verify_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len);#endif /* _CRYPTO_KRB5_H */
David Howells
maintainerPATCH 9/24 crypto/krb5: Provide infrastructure and key derivation
In reply to David HowellsProvide key derivation interface functions and a helper to implement the PRF+ function from rfc4402.
--- crypto/krb5/Makefile | 1 + crypto/krb5/internal.h | 10 +++ crypto/krb5/krb5_kdf.c | 145 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 10 +++ 4 files changed, 166 insertions(+) create mode 100644 crypto/krb5/krb5_kdf.c
crypto/krb5/Makefile +1 -0
@@ -4,6 +4,7 @@ # krb5-y += \ + krb5_kdf.o \ krb5_api.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +10 -0
@@ -120,3 +120,13 @@ struct crypto_aead *krb5_prepare_encryption(const struct krb5_enctype *krb5,struct crypto_shash *krb5_prepare_checksum (const struct krb5_enctype *krb5,const struct krb5_buffer *Kc,gfp_t gfp); + +/* +* krb5_kdf.c +*/ +int krb5_derive_Kc (const struct krb5_enctype *krb5,const struct krb5_buffer *TK , +u32 usage,struct krb5_buffer *key,gfp_t gfp); +int krb5_derive_Ke (const struct krb5_enctype *krb5,const struct krb5_buffer *TK , +u32 usage,struct krb5_buffer *key,gfp_t gfp); +int krb5_derive_Ki (const struct krb5_enctype *krb5,const struct krb5_buffer *TK , +u32 usage,struct krb5_buffer *key,gfp_t gfp);
crypto/krb5/krb5_kdf.c new file +145 -0
145 lines not on this page · raw message
include/crypto/krb5.h +10 -0
@@ -139,4 +139,14 @@ int crypto_krb5_verify_mic(const struct krb5_enctype *krb5, struct scatterlist *sg, unsigned int nr_sg, size_t *_offset, size_t *_len); +/* +* krb5_kdf.c +*/ +int crypto_krb5_calc_PRFplus (const struct krb5_enctype *krb5, +const struct krb5_buffer *K , +unsigned int L , +const struct krb5_buffer *S , +struct krb5_buffer *result, +gfp_t gfp); +#endif /* _CRYPTO_KRB5_H */
David Howells
maintainerPATCH 10/24 crypto/krb5: Implement the Kerberos5 rfc3961 key derivation
In reply to David HowellsImplement the simplified crypto profile for Kerberos 5 rfc3961 with the pseudo-random function, PRF(), from section 5.3 and the key derivation function, DK() from section 5.1.
--- crypto/krb5/Makefile | 3 +- crypto/krb5/internal.h | 6 + crypto/krb5/rfc3961_simplified.c | 407 +++++++++++++++++++++++++++++++ 3 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 crypto/krb5/rfc3961_simplified.c
crypto/krb5/Makefile +2 -1
@@ -5,6 +5,7 @@ krb5-y += \ krb5_kdf.o \ - krb5_api.o + krb5_api.o \ + rfc3961_simplified.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -5,6 +5,7 @@* Written by David Howells ([email protected]) */ +#include <linux/scatterlist.h> #include <crypto/krb5.h> /*
@@ -130,3 +131,8 @@ int krb5_derive_Ke(const struct krb5_enctype *krb5, const struct krb5_buffer *TK u32 usage, struct krb5_buffer *key, gfp_t gfp);int krb5_derive_Ki (const struct krb5_enctype *krb5,const struct krb5_buffer *TK ,u32 usage,struct krb5_buffer *key,gfp_t gfp); + +/* +* rfc3961_simplified.c +*/ +extern const struct krb5_crypto_profile rfc3961_simplified_profile;
crypto/krb5/rfc3961_simplified.c new file +407 -0
407 lines not on this page · raw message
David Howells
maintainerPATCH 11/24 crypto/krb5: Provide RFC3961 setkey packaging functions
In reply to David HowellsProvide functions to derive keys according to RFC3961 (or load the derived keys for the selftester where only derived keys are available) and to package them up appropriately for passing to a krb5enc AEAD setkey or a hash setkey function.
--- crypto/krb5/internal.h | 20 +++++ crypto/krb5/rfc3961_simplified.c | 122 ++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 4 deletions(-)
crypto/krb5/internal.h +20 -0
@@ -136,3 +136,23 @@ int krb5_derive_Ki(const struct krb5_enctype *krb5, const struct krb5_buffer *TK* rfc3961_simplified.c */ extern const struct krb5_crypto_profile rfc3961_simplified_profile; + +int authenc_derive_encrypt_keys (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +unsigned int usage, +struct krb5_buffer *setkey, +gfp_t gfp); +int authenc_load_encrypt_keys (const struct krb5_enctype *krb5, +const struct krb5_buffer *Ke, +const struct krb5_buffer *Ki, +struct krb5_buffer *setkey, +gfp_t gfp); +int rfc3961_derive_checksum_key (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +unsigned int usage, +struct krb5_buffer *setkey, +gfp_t gfp); +int rfc3961_load_checksum_key (const struct krb5_enctype *krb5, +const struct krb5_buffer *Kc, +struct krb5_buffer *setkey, +gfp_t gfp);
crypto/krb5/rfc3961_simplified.c +118 -4
133 lines not on this page · raw message
David Howells
maintainerPATCH 12/24 crypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt functions
In reply to David HowellsAdd functions that encrypt and decrypt a message according to rfc3961 sec 5.3, using Ki to checksum the data to be secured and Ke to encrypt it during the encryption phase, then decrypting with Ke and verifying the checksum with Ki in the decryption phase.
--- crypto/krb5/internal.h | 13 +++ crypto/krb5/rfc3961_simplified.c | 146 +++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+)
crypto/krb5/internal.h +13 -0
@@ -7,6 +7,8 @@#include <linux/scatterlist.h> #include <crypto/krb5.h> +#include <crypto/hash.h> +#include <crypto/skcipher.h> /* * Profile used for key derivation and encryption.
@@ -137,6 +139,8 @@ int krb5_derive_Ki(const struct krb5_enctype *krb5, const struct krb5_buffer *TK*/ extern const struct krb5_crypto_profile rfc3961_simplified_profile; +int crypto_shash_update_sg (struct shash_desc *desc,struct scatterlist *sg, +size_t offset,size_t len); int authenc_derive_encrypt_keys(const struct krb5_enctype *krb5, const struct krb5_buffer *TK, unsigned int usage,
@@ -156,3 +160,12 @@ int rfc3961_load_checksum_key(const struct krb5_enctype *krb5,const struct krb5_buffer *Kc, struct krb5_buffer *setkey, gfp_t gfp); +ssize_t krb5_aead_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg,size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded); +int krb5_aead_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len);
crypto/krb5/rfc3961_simplified.c +146 -0
169 lines not on this page · raw message
David Howells
maintainerPATCH 13/24 crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic
In reply to David HowellsAdd functions that sign and verify a message according to rfc3961 sec 5.4, using Kc to generate a checksum and insert it into the MIC field in the skbuff in the sign phase then checksum the data and compare it to the MIC in the verify phase.
--- crypto/krb5/internal.h | 10 +++ crypto/krb5/rfc3961_simplified.c | 130 +++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+)
crypto/krb5/internal.h +10 -0
@@ -169,3 +169,13 @@ int krb5_aead_decrypt(const struct krb5_enctype *krb5,struct crypto_aead *aead, struct scatterlist *sg, unsigned int nr_sg, size_t *_offset, size_t *_len); +ssize_t rfc3961_get_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg,size_t sg_len, +size_t data_offset,size_t data_len); +int rfc3961_verify_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len);
crypto/krb5/rfc3961_simplified.c +130 -0
140 lines not on this page · raw message
David Howells
maintainerPATCH 14/24 crypto/krb5: Implement the AES enctypes from rfc3962
In reply to David HowellsImplement the aes128-cts-hmac-sha1-96 and aes256-cts-hmac-sha1-96 enctypes from rfc3962, using the rfc3961 kerberos 5 simplified crypto scheme.
--- crypto/krb5/Kconfig | 1 + crypto/krb5/Makefile | 3 +- crypto/krb5/internal.h | 6 ++ crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc3962_aes.c | 115 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 crypto/krb5/rfc3962_aes.c
crypto/krb5/Kconfig +1 -0
@@ -5,6 +5,7 @@ config CRYPTO_KRB5 select CRYPTO_AUTHENC select CRYPTO_SKCIPHER select CRYPTO_HASH_INFO + select CRYPTO_HMAC select CRYPTO_SHA1 select CRYPTO_CBC select CRYPTO_CTS
crypto/krb5/Makefile +2 -1
@@ -6,6 +6,7 @@ krb5-y += \ krb5_kdf.o \ krb5_api.o \ - rfc3961_simplified.o + rfc3961_simplified.o \ + rfc3962_aes.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -179,3 +179,9 @@ int rfc3961_verify_mic(const struct krb5_enctype *krb5,const struct krb5_buffer *metadata, struct scatterlist *sg, unsigned int nr_sg, size_t *_offset, size_t *_len); + +/* +* rfc3962_aes.c +*/ +extern const struct krb5_enctype krb5_aes128_cts_hmac_sha1_96; +extern const struct krb5_enctype krb5_aes256_cts_hmac_sha1_96;
crypto/krb5/krb5_api.c +2 -0
@@ -17,6 +17,8 @@ MODULE_AUTHOR("Red Hat, Inc.");MODULE_LICENSE ("GPL" );static const struct krb5_enctype *const krb5_supported_enctypes[] = { + &krb5_aes128_cts_hmac_sha1_96, + &krb5_aes256_cts_hmac_sha1_96, };/**
crypto/krb5/rfc3962_aes.c new file +115 -0
115 lines not on this page · raw message
David Howells
maintainerPATCH 15/24 crypto/krb5: Implement the AES enctypes from rfc8009
In reply to David HowellsImplement the aes128-cts-hmac-sha256-128 and aes256-cts-hmac-sha384-192 enctypes from rfc8009, overriding the rfc3961 kerberos 5 simplified crypto scheme.
--- crypto/krb5/Kconfig | 2 + crypto/krb5/Makefile | 3 +- crypto/krb5/internal.h | 6 + crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc8009_aes2.c | 362 +++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 4 + 6 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 crypto/krb5/rfc8009_aes2.c
crypto/krb5/Kconfig +2 -0
@@ -7,6 +7,8 @@ config CRYPTO_KRB5 select CRYPTO_HASH_INFO select CRYPTO_HMAC select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA512 select CRYPTO_CBC select CRYPTO_CTS select CRYPTO_AES
crypto/krb5/Makefile +2 -1
@@ -7,6 +7,7 @@ krb5-y += \ krb5_kdf.o \ krb5_api.o \ rfc3961_simplified.o \ - rfc3962_aes.o + rfc3962_aes.o \ + rfc8009_aes2.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -185,3 +185,9 @@ int rfc3961_verify_mic(const struct krb5_enctype *krb5,*/ extern const struct krb5_enctype krb5_aes128_cts_hmac_sha1_96;extern const struct krb5_enctype krb5_aes256_cts_hmac_sha1_96; + +/* +* rfc8009_aes2.c +*/ +extern const struct krb5_enctype krb5_aes128_cts_hmac_sha256_128; +extern const struct krb5_enctype krb5_aes256_cts_hmac_sha384_192;
crypto/krb5/krb5_api.c +2 -0
@@ -19,6 +19,8 @@ MODULE_LICENSE("GPL");static const struct krb5_enctype *const krb5_supported_enctypes[] = { &krb5_aes128_cts_hmac_sha1_96, &krb5_aes256_cts_hmac_sha1_96, + &krb5_aes128_cts_hmac_sha256_128, + &krb5_aes256_cts_hmac_sha384_192, };/**
crypto/krb5/rfc8009_aes2.c new file +362 -0
362 lines not on this page · raw message
include/crypto/krb5.h +4 -0
@@ -31,6 +31,8 @@ struct scatterlist;#define KRB5_ENCTYPE_DES3_CBC_SHA1 0x0010#define KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012 +#define KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 0x0013 +#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 0x0014#define KRB5_ENCTYPE_ARCFOUR_HMAC 0x0017#define KRB5_ENCTYPE_ARCFOUR_HMAC_EXP 0x0018#define KRB5_ENCTYPE_UNKNOWN 0x01ff
@@ -45,6 +47,8 @@ struct scatterlist;#define KRB5_CKSUMTYPE_HMAC_SHA1_DES3 0x000c#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010 +#define KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128 0x0013 +#define KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256 0x0014#define KRB5_CKSUMTYPE_HMAC_MD5_ARCFOUR -138/* Microsoft md5 hmac cksumtype */ /*
David Howells
maintainerPATCH 16/24 crypto/krb5: Implement the Camellia enctypes from rfc6803
In reply to David HowellsImplement the camellia128-cts-cmac and camellia256-cts-cmac enctypes from rfc6803.
Note that the test vectors in rfc6803 for encryption are incomplete, lacking the key usage number needed to derive Ke and Ki, and there are errata for this:
https://www.rfc-editor.org/errata_search.php?rfc=6803
--- crypto/krb5/Kconfig | 2 + crypto/krb5/Makefile | 1 + crypto/krb5/internal.h | 6 + crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc6803_camellia.c | 237 +++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 4 + 6 files changed, 252 insertions(+) create mode 100644 crypto/krb5/rfc6803_camellia.c
crypto/krb5/Kconfig +2 -0
@@ -6,12 +6,14 @@ config CRYPTO_KRB5 select CRYPTO_SKCIPHER select CRYPTO_HASH_INFO select CRYPTO_HMAC + select CRYPTO_CMAC select CRYPTO_SHA1 select CRYPTO_SHA256 select CRYPTO_SHA512 select CRYPTO_CBC select CRYPTO_CTS select CRYPTO_AES + select CRYPTO_CAMELLIA help Provide a library for provision of Kerberos-5-based crypto. This is intended for network filesystems to use.
crypto/krb5/Makefile +1 -0
@@ -8,6 +8,7 @@ krb5-y += \ krb5_api.o \ rfc3961_simplified.o \ rfc3962_aes.o \ + rfc6803_camellia.o \ rfc8009_aes2.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -186,6 +186,12 @@ int rfc3961_verify_mic(const struct krb5_enctype *krb5,extern const struct krb5_enctype krb5_aes128_cts_hmac_sha1_96;extern const struct krb5_enctype krb5_aes256_cts_hmac_sha1_96; +/* +* rfc6803_camellia.c +*/ +extern const struct krb5_enctype krb5_camellia128_cts_cmac; +extern const struct krb5_enctype krb5_camellia256_cts_cmac; +/* * rfc8009_aes2.c */
crypto/krb5/krb5_api.c +2 -0
@@ -21,6 +21,8 @@ static const struct krb5_enctype *const krb5_supported_enctypes[] = { &krb5_aes256_cts_hmac_sha1_96, &krb5_aes128_cts_hmac_sha256_128, &krb5_aes256_cts_hmac_sha384_192, + &krb5_camellia128_cts_cmac, + &krb5_camellia256_cts_cmac, };/**
crypto/krb5/rfc6803_camellia.c new file +237 -0
237 lines not on this page · raw message
include/crypto/krb5.h +4 -0
@@ -35,6 +35,8 @@ struct scatterlist;#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 0x0014#define KRB5_ENCTYPE_ARCFOUR_HMAC 0x0017#define KRB5_ENCTYPE_ARCFOUR_HMAC_EXP 0x0018 +#define KRB5_ENCTYPE_CAMELLIA128_CTS_CMAC 0x0019 +#define KRB5_ENCTYPE_CAMELLIA256_CTS_CMAC 0x001a#define KRB5_ENCTYPE_UNKNOWN 0x01ff#define KRB5_CKSUMTYPE_CRC32 0x0001
@@ -47,6 +49,8 @@ struct scatterlist;#define KRB5_CKSUMTYPE_HMAC_SHA1_DES3 0x000c#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010 +#define KRB5_CKSUMTYPE_CMAC_CAMELLIA128 0x0011 +#define KRB5_CKSUMTYPE_CMAC_CAMELLIA256 0x0012#define KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128 0x0013#define KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256 0x0014#define KRB5_CKSUMTYPE_HMAC_MD5_ARCFOUR -138/* Microsoft md5 hmac cksumtype */
David Howells
maintainerPATCH 17/24 crypto/krb5: Implement crypto self-testing
In reply to David HowellsImplement self-testing infrastructure to test the pseudo-random function, key derivation, encryption and checksumming.
Add the testing data from rfc8009 to test AES + HMAC-SHA2.
Add the testing data from rfc6803 to test Camellia. Note some encryption test vectors here are incomplete, lacking the key usage number needed to derive Ke and Ki, and there are errata for this:
https://www.rfc-editor.org/errata_search.php?rfc=6803
--- crypto/krb5/Kconfig | 7 + crypto/krb5/Makefile | 4 + crypto/krb5/internal.h | 48 ++++ crypto/krb5/krb5_api.c | 11 + crypto/krb5/selftest.c | 544 ++++++++++++++++++++++++++++++++++++ crypto/krb5/selftest_data.c | 291 +++++++++++++++++++ 6 files changed, 905 insertions(+) create mode 100644 crypto/krb5/selftest.c create mode 100644 crypto/krb5/selftest_data.c
crypto/krb5/Kconfig +7 -0
@@ -17,3 +17,10 @@ config CRYPTO_KRB5 help Provide a library for provision of Kerberos-5-based crypto. This is intended for network filesystems to use. + +config CRYPTO_KRB5_SELFTESTS + bool "Kerberos 5 crypto selftests" + depends on CRYPTO_KRB5 + help + Turn on some self-testing for the kerberos 5 crypto functions. These + will be performed on module load or boot, if compiled in.
crypto/krb5/Makefile +4 -0
@@ -11,4 +11,8 @@ krb5-y += \ rfc6803_camellia.o \ rfc8009_aes2.o +krb5-$(CONFIG_CRYPTO_KRB5_SELFTESTS) += \ + selftest.o \ + selftest_data.o + obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +48 -0
57 lines not on this page · raw message
crypto/krb5/krb5_api.c +11 -0
@@ -439,3 +439,14 @@ int crypto_krb5_verify_mic(const struct krb5_enctype *krb5, _offset, _len); }EXPORT_SYMBOL (crypto_krb5_verify_mic); + +static int __init crypto_krb5_init (void ) +{ +return krb5_selftest (); +} +module_init (crypto_krb5_init); + +static void __exit crypto_krb5_exit(void) +{ +} +module_exit (crypto_krb5_exit);
crypto/krb5/selftest.c new file +544 -0
544 lines not on this page · raw message
crypto/krb5/selftest_data.c new file +291 -0
291 lines not on this page · raw message
David Howells
maintainerPATCH 18/24 rxrpc: Pull out certain app callback funcs into an ops table
In reply to David HowellsA number of functions separately furnish an AF_RXRPC socket with callback function pointers into a kernel app (such as the AFS filesystem) that is using it. Replace most of these with an ops table for the entire socket. This makes it easier to add more callback functions.
Note that the call incoming data processing callback is retaind as that gets set to different things, depending on the type of op.
--- fs/afs/rxrpc.c | 11 ++++++++--- include/net/af_rxrpc.h | 22 +++++++++++++--------- net/rxrpc/af_rxrpc.c | 20 ++++++++------------ net/rxrpc/ar-internal.h | 3 +-- net/rxrpc/call_accept.c | 31 +++++++++++++++---------------- net/rxrpc/rxperf.c | 10 +++++++--- 6 files changed, 52 insertions(+), 45 deletions(-)
fs/afs/rxrpc.c +8 -3
@@ -24,8 +24,15 @@ static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsignedstatic void afs_process_async_call (struct work_struct *);static void afs_rx_new_call (struct sock *,struct rxrpc_call *,unsigned long );static void afs_rx_discard_new_call (struct rxrpc_call *,unsigned long ); +static void afs_rx_attach (struct rxrpc_call *rxcall,unsigned long user_call_ID);static int afs_deliver_cm_op_id (struct afs_call *); +static const struct rxrpc_kernel_ops afs_rxrpc_callback_ops = { + .notify_new_call = afs_rx_new_call, + .discard_new_call = afs_rx_discard_new_call, + .user_attach_call = afs_rx_attach, +}; +/* asynchronous incoming call initial processing */ static const struct afs_call_type afs_RXCMxxxx = { .name ="CB.xxxx" ,
@@ -84,8 +91,7 @@ int afs_open_socket(struct afs_net *net)* it sends back to us. */ -rxrpc_kernel_new_call_notification (socket, afs_rx_new_call, - afs_rx_discard_new_call); +rxrpc_kernel_set_notifications (socket, &afs_rxrpc_callback_ops); ret =kernel_listen (socket,INT_MAX );if (ret <0 )
@@ -738,7 +744,6 @@ void afs_charge_preallocation(struct work_struct *work)if (rxrpc_kernel_charge_accept (net->socket, afs_wake_up_async_call, - afs_rx_attach, (unsigned long )call,GFP_KERNEL , call->debug_id) <0 )
include/net/af_rxrpc.h +13 -9
@@ -29,18 +29,23 @@ enum rxrpc_interruptibility {*/ extern atomic_t rxrpc_debug_id; +/* +* Operations table for rxrpc to call out to a kernel application (e.g. kAFS). +*/ +struct rxrpc_kernel_ops { +void (*notify_new_call)(struct sock *sk,struct rxrpc_call *call, +unsigned long user_call_ID); +void (*discard_new_call)(struct rxrpc_call *call,unsigned long user_call_ID); +void (*user_attach_call)(struct rxrpc_call *call,unsigned long user_call_ID); +}; +typedef void (*rxrpc_notify_rx_t )(struct sock *,struct rxrpc_call *,unsigned long );typedef void (*rxrpc_notify_end_tx_t )(struct sock *,struct rxrpc_call *,unsigned long ); -typedef void (*rxrpc_notify_new_call_t )(struct sock *,struct rxrpc_call *, -unsigned long ); -typedef void (*rxrpc_discard_new_call_t )(struct rxrpc_call *,unsigned long ); -typedef void (*rxrpc_user_attach_call_t )(struct rxrpc_call *,unsigned long ); -void rxrpc_kernel_new_call_notification (struct socket *, -rxrpc_notify_new_call_t , -rxrpc_discard_new_call_t ); +void rxrpc_kernel_set_notifications (struct socket *sock, +const struct rxrpc_kernel_ops *app_ops); struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, struct rxrpc_peer *peer, struct key *key,
@@ -70,8 +75,7 @@ struct rxrpc_peer *rxrpc_kernel_get_call_peer(struct socket *sock, struct rxrpc_const struct sockaddr_rxrpc *rxrpc_kernel_remote_srx (const struct rxrpc_peer *peer);const struct sockaddr *rxrpc_kernel_remote_addr (const struct rxrpc_peer *peer);unsigned int rxrpc_kernel_get_srtt (const struct rxrpc_peer *); -int rxrpc_kernel_charge_accept (struct socket *,rxrpc_notify_rx_t , -rxrpc_user_attach_call_t ,unsigned long ,gfp_t , +int rxrpc_kernel_charge_accept (struct socket *,rxrpc_notify_rx_t ,unsigned long ,gfp_t ,unsigned int );void rxrpc_kernel_set_tx_length (struct socket *,struct rxrpc_call *,s64 );bool rxrpc_kernel_check_life (const struct socket *,const struct rxrpc_call *);
net/rxrpc/af_rxrpc.c +8 -12
@@ -464,24 +464,20 @@ u32 rxrpc_kernel_get_epoch(struct socket *sock, struct rxrpc_call *call)EXPORT_SYMBOL (rxrpc_kernel_get_epoch);/** -* rxrpc_kernel_new_call_notification - Get notifications of new calls -* @sock: The socket to intercept received messages on -* @notify_new_call: Function to be called when new calls appear -* @discard_new_call: Function to discard preallocated calls +* rxrpc_kernel_set_notifications - Set table of callback operations +* @sock: The socket to install table upon +* @app_ops: Callback operation table to set * -* Allow a kernel service to be given notifications about new calls. +* Allow a kernel service to set a table of event notifications on a socket. */ -void rxrpc_kernel_new_call_notification ( -struct socket *sock, -rxrpc_notify_new_call_t notify_new_call, -rxrpc_discard_new_call_t discard_new_call) +void rxrpc_kernel_set_notifications (struct socket *sock, +const struct rxrpc_kernel_ops *app_ops) {struct rxrpc_sock *rx =rxrpc_sk (sock->sk); - rx->notify_new_call = notify_new_call; - rx->discard_new_call = discard_new_call; + rx->app_ops = app_ops; } -EXPORT_SYMBOL (rxrpc_kernel_new_call_notification); +EXPORT_SYMBOL (rxrpc_kernel_set_notifications);/** * rxrpc_kernel_set_max_life - Set maximum lifespan on a call
net/rxrpc/ar-internal.h +1 -2
@@ -146,8 +146,7 @@ struct rxrpc_backlog {struct rxrpc_sock {/* WARNING: sk has to be the first member */ struct sock sk; -rxrpc_notify_new_call_t notify_new_call;/* Func to notify of new call */ -rxrpc_discard_new_call_t discard_new_call;/* Func to discard a new call */ +const struct rxrpc_kernel_ops *app_ops;/* Table of kernel app notification funcs */ struct rxrpc_local *local;/* local endpoint */ struct rxrpc_backlog *backlog;/* Preallocation for services */ spinlock_t incoming_lock;/* Incoming call vs service shutdown lock */
net/rxrpc/call_accept.c +15 -16
@@ -34,7 +34,6 @@ static void rxrpc_dummy_notify(struct sock *sk, struct rxrpc_call *call,static int rxrpc_service_prealloc_one (struct rxrpc_sock *rx,struct rxrpc_backlog *b,rxrpc_notify_rx_t notify_rx, -rxrpc_user_attach_call_t user_attach_call,unsigned long user_call_ID,gfp_t gfp,unsigned int debug_id) {
@@ -123,9 +122,10 @@ static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx, call->user_call_ID = user_call_ID; call->notify_rx = notify_rx; -if (user_attach_call) { +if (rx->app_ops && + rx->app_ops->user_attach_call) {rxrpc_get_call (call, rxrpc_call_get_kernel_service); -user_attach_call (call, user_call_ID); + rx->app_ops->user_attach_call (call, user_call_ID); }rxrpc_get_call (call, rxrpc_call_get_userid);
@@ -219,9 +219,10 @@ void rxrpc_discard_prealloc(struct rxrpc_sock *rx)while (CIRC_CNT (head, tail, size) >0 ) {struct rxrpc_call *call = b->call_backlog[tail];rcu_assign_pointer (call->socket, rx); -if (rx->discard_new_call) { +if (rx->app_ops && + rx->app_ops->discard_new_call) {_debug ("discard %lx" , call->user_call_ID); - rx->discard_new_call (call, call->user_call_ID); + rx->app_ops->discard_new_call (call, call->user_call_ID);if (call->notify_rx) call->notify_rx = rxrpc_dummy_notify;rxrpc_put_call (call, rxrpc_call_put_kernel);
@@ -387,8 +388,9 @@ bool rxrpc_new_incoming_call(struct rxrpc_local *local,rxrpc_incoming_call (rx, call, skb); conn = call->conn; -if (rx->notify_new_call) - rx->notify_new_call (&rx->sk, call, call->user_call_ID); +if (rx->app_ops && + rx->app_ops->notify_new_call) + rx->app_ops->notify_new_call (&rx->sk, call, call->user_call_ID);spin_lock (&conn->state_lock);if (conn->state ==RXRPC_CONN_SERVICE_UNSECURED ) {
@@ -440,8 +442,7 @@ int rxrpc_user_charge_accept(struct rxrpc_sock *rx, unsigned long user_call_ID)if (rx->sk.sk_state ==RXRPC_CLOSE )return -ESHUTDOWN ; -return rxrpc_service_prealloc_one (rx, b,NULL ,NULL , user_call_ID, -GFP_KERNEL , +return rxrpc_service_prealloc_one (rx, b,NULL , user_call_ID,GFP_KERNEL ,atomic_inc_return (&rxrpc_debug_id)); }
@@ -449,20 +450,19 @@ int rxrpc_user_charge_accept(struct rxrpc_sock *rx, unsigned long user_call_ID)* rxrpc_kernel_charge_accept - Charge up socket with preallocated calls * @sock: The socket on which to preallocate * @notify_rx: Event notification function for the call -* @user_attach_call: Func to attach call to user_call_ID * @user_call_ID: The tag to attach to the preallocated call * @gfp: The allocation conditions. * @debug_id: The tracing debug ID. * -* Charge up the socket with preallocated calls, each with a user ID. A -* function should be provided to effect the attachment from the user's side. -* The user is given a ref to hold on the call. +* Charge up the socket with preallocated calls, each with a user ID. The +* ->user_attach_call() callback function should be provided to effect the +* attachment from the user's side. The user is given a ref to hold on the +* call. * * Note that the call may be come connected before this function returns. */ int rxrpc_kernel_charge_accept (struct socket *sock,rxrpc_notify_rx_t notify_rx, -rxrpc_user_attach_call_t user_attach_call,unsigned long user_call_ID,gfp_t gfp,unsigned int debug_id) {
@@ -472,8 +472,7 @@ int rxrpc_kernel_charge_accept(struct socket *sock,if (sock->sk->sk_state ==RXRPC_CLOSE )return -ESHUTDOWN ; -return rxrpc_service_prealloc_one (rx, b, notify_rx, - user_attach_call, user_call_ID, +return rxrpc_service_prealloc_one (rx, b, notify_rx, user_call_ID, gfp, debug_id); }EXPORT_SYMBOL (rxrpc_kernel_charge_accept);
net/rxrpc/rxperf.c +7 -3
@@ -136,6 +136,12 @@ static void rxperf_notify_end_reply_tx(struct sock *sock, RXPERF_CALL_SV_AWAIT_ACK); } +static const struct rxrpc_kernel_ops rxperf_rxrpc_callback_ops = { + .notify_new_call = rxperf_rx_new_call, + .discard_new_call = rxperf_rx_discard_new_call, + .user_attach_call = rxperf_rx_attach, +}; +/* * Charge the incoming call preallocation. */
@@ -161,7 +167,6 @@ static void rxperf_charge_preallocation(struct work_struct *work)if (rxrpc_kernel_charge_accept (rxperf_socket, rxperf_notify_rx, - rxperf_rx_attach, (unsigned long )call,GFP_KERNEL , call->debug_id) <0 )
@@ -209,8 +214,7 @@ static int rxperf_open_socket(void)if (ret <0 ) goto error_2; -rxrpc_kernel_new_call_notification (socket, rxperf_rx_new_call, - rxperf_rx_discard_new_call); +rxrpc_kernel_set_notifications (socket, &rxperf_rxrpc_callback_ops); ret =kernel_listen (socket,INT_MAX );if (ret <0 )
David Howells
maintainerPATCH 19/24 rxrpc: Pass CHALLENGE packets to the call for recvmsg() to respond to
In reply to David HowellsPass CHALLENGE packets to the receive queue of one of the calls on a connection for recvmsg() to process rather than doing it behind the scenes in a worker thread.
This will allow the application (AFS or userspace) to interact with the process if it wants to and put values into user-defined fields. This will be used by AFS when talking to a fileserver to supply that fileserver with a crypto key by which callback RPCs can be encrypted (ie. notifications from the fileserver to the client).
--- fs/afs/Makefile | 1 + fs/afs/cm_security.c | 47 ++++++ fs/afs/internal.h | 6 + fs/afs/rxrpc.c | 5 + include/net/af_rxrpc.h | 15 ++ include/trace/events/rxrpc.h | 8 +- include/uapi/linux/rxrpc.h | 46 ++++-- net/rxrpc/af_rxrpc.c | 25 +++- net/rxrpc/ar-internal.h | 32 +++- net/rxrpc/call_object.c | 5 +- net/rxrpc/conn_event.c | 97 +++++++++++- net/rxrpc/conn_object.c | 1 + net/rxrpc/insecure.c | 13 +- net/rxrpc/io_thread.c | 8 +- net/rxrpc/output.c | 56 +++++++ net/rxrpc/recvmsg.c | 114 +++++++++++++- net/rxrpc/rxkad.c | 281 +++++++++++++++++++++-------------- net/rxrpc/sendmsg.c | 69 ++++++++- net/rxrpc/server_key.c | 40 +++++ 19 files changed, 722 insertions(+), 147 deletions(-) create mode 100644 fs/afs/cm_security.c
fs/afs/Makefile +1 -0
@@ -8,6 +8,7 @@ kafs-y := \ addr_prefs.o \ callback.o \ cell.o \ + cm_security.o \ cmservice.o \ dir.o \ dir_edit.o \
fs/afs/cm_security.c new file +47 -0
47 lines not on this page · raw message
fs/afs/internal.h +6 -0
@@ -1061,6 +1061,12 @@ extern void __net_exit afs_cell_purge(struct afs_net *);*/ extern bool afs_cm_incoming_call (struct afs_call *); +/* +* cm_security.c +*/ +int afs_respond_to_challenge (struct rxrpc_call *rxcall,unsigned long user_call_ID, +u16 service_id,u8 security_index); +/* * dir.c */
fs/afs/rxrpc.c +5 -0
@@ -31,6 +31,7 @@ static const struct rxrpc_kernel_ops afs_rxrpc_callback_ops = { .notify_new_call = afs_rx_new_call, .discard_new_call = afs_rx_discard_new_call, .user_attach_call = afs_rx_attach, + .respond_to_challenge = afs_respond_to_challenge, };/* asynchronous incoming call initial processing */
@@ -71,6 +72,10 @@ int afs_open_socket(struct afs_net *net)if (ret <0 ) goto error_2; + ret =rxrpc_sock_set_manage_response (socket->sk, true); +if (ret <0 ) + goto error_2; + ret =kernel_bind (socket, (struct sockaddr *) &srx,sizeof (srx));if (ret == -EADDRINUSE ) { srx.transport.sin6.sin6_port =0 ;
include/net/af_rxrpc.h +15 -0
@@ -16,6 +16,7 @@ struct sock;struct socket ;struct rxrpc_call ;struct rxrpc_peer ; +struct krb5_buffer ;enum rxrpc_abort_reason ;enum rxrpc_interruptibility {
@@ -37,6 +38,14 @@ struct rxrpc_kernel_ops { unsigned long user_call_ID);void (*discard_new_call)(struct rxrpc_call *call,unsigned long user_call_ID);void (*user_attach_call)(struct rxrpc_call *call,unsigned long user_call_ID); +int (*respond_to_challenge)(struct rxrpc_call *call,unsigned long user_call_ID, +u16 service_id,u8 security_index); +ssize_t (*rxgk_get_appdata)(struct rxrpc_call *call,unsigned long user_call_ID, +u16 service_id,u8 security_index,u32 enctype, +void *buffer,size_t bufsize); +int (*rxgk_check_appdata)(struct rxrpc_call *call,unsigned long user_call_ID, +u16 service_id,u8 security_index,u32 enctype, +const void *buffer,size_t bufsize); }; typedef void (*rxrpc_notify_rx_t)(struct sock *, struct rxrpc_call *,
@@ -85,5 +94,11 @@ void rxrpc_kernel_set_max_life(struct socket *, struct rxrpc_call *,int rxrpc_sock_set_min_security_level (struct sock *sk,unsigned int val);int rxrpc_sock_set_security_keyring (struct sock *,struct key *); +int rxrpc_sock_set_manage_response (struct sock *sk,bool set); + +int rxrpc_kernel_reject_challenge (struct rxrpc_call *call,u32 abort_code,int error, +enum rxrpc_abort_reason why); +int rxkad_kernel_respond_to_challenge (struct rxrpc_call *call); +int rxgk_kernel_respond_to_challenge (struct rxrpc_call *call,struct krb5_buffer *appdata);#endif /* _NET_RXRPC_H */
include/trace/events/rxrpc.h +7 -1
@@ -25,6 +25,7 @@ EM(afs_abort_probeuuid_negative, "afs-probeuuid-neg") \ EM(afs_abort_send_data_error, "afs-send-data") \ EM(afs_abort_unmarshal_error, "afs-unmarshal") \ +EM (afs_abort_unsupported_sec_class,"afs-unsup-sec-class" ) \ /* rxperf errors */ \ EM(rxperf_abort_general_error, "rxperf-error") \EM (rxperf_abort_oom,"rxperf-oom" ) \
@@ -77,6 +78,7 @@ EM(rxrpc_abort_call_timeout, "call-timeout") \ EM(rxrpc_abort_no_service_key, "no-serv-key") \ EM(rxrpc_abort_nomem, "nomem") \ + EM(rxrpc_abort_response_sendmsg, "resp-sendmsg") \ EM(rxrpc_abort_service_not_offered, "serv-not-offered") \ EM(rxrpc_abort_shut_down, "shut-down") \EM (rxrpc_abort_unsupported_security,"unsup-sec" ) \
@@ -133,6 +135,7 @@ EM(rxrpc_skb_get_conn_secured, "GET conn-secd") \ EM(rxrpc_skb_get_conn_work, "GET conn-work") \ EM(rxrpc_skb_get_local_work, "GET locl-work") \ + EM(rxrpc_skb_get_post_challenge, "GET post-chal") \ EM(rxrpc_skb_get_reject_work, "GET rej-work ") \ EM(rxrpc_skb_get_to_recvmsg, "GET to-recv ") \EM (rxrpc_skb_get_to_recvmsg_oos,"GET to-recv-o" ) \
@@ -141,12 +144,14 @@ EM(rxrpc_skb_new_jumbo_subpacket, "NEW jumbo-sub") \ EM(rxrpc_skb_new_unshared, "NEW unshared ") \ EM(rxrpc_skb_put_call_rx, "PUT call-rx ") \ + EM(rxrpc_skb_put_challenge, "PUT challenge") \ EM(rxrpc_skb_put_conn_secured, "PUT conn-secd") \ EM(rxrpc_skb_put_conn_work, "PUT conn-work") \ EM(rxrpc_skb_put_error_report, "PUT error-rep") \ EM(rxrpc_skb_put_input, "PUT input ") \ EM(rxrpc_skb_put_jumbo_subpacket, "PUT jumbo-sub") \ EM(rxrpc_skb_put_purge, "PUT purge ") \ + EM(rxrpc_skb_put_response, "PUT response ") \ EM(rxrpc_skb_put_rotate, "PUT rotate ") \ EM(rxrpc_skb_put_unknown, "PUT unknown ") \EM (rxrpc_skb_see_conn_work,"SEE conn-work" ) \
@@ -219,6 +224,7 @@ EM(rxrpc_conn_get_conn_input, "GET inp-conn") \ EM(rxrpc_conn_get_idle, "GET idle ") \ EM(rxrpc_conn_get_poke_abort, "GET pk-abort") \ + EM(rxrpc_conn_get_poke_response, "GET response") \ EM(rxrpc_conn_get_poke_secured, "GET secured ") \ EM(rxrpc_conn_get_poke_timer, "GET poke ") \EM (rxrpc_conn_get_service_conn,"GET svc-conn" ) \
@@ -456,7 +462,7 @@ EM(rxrpc_tx_point_conn_abort, "ConnAbort") \ EM(rxrpc_tx_point_reject, "Reject") \ EM(rxrpc_tx_point_rxkad_challenge, "RxkadChall") \ - EM(rxrpc_tx_point_rxkad_response, "RxkadResp") \ + EM(rxrpc_tx_point_response, "Response") \ EM(rxrpc_tx_point_version_keepalive, "VerKeepalive") \E_ (rxrpc_tx_point_version_reply,"VerReply" )
include/uapi/linux/rxrpc.h +34 -12
64 lines not on this page · raw message
net/rxrpc/af_rxrpc.c +23 -2
@@ -445,7 +445,8 @@ bool rxrpc_kernel_check_life(const struct socket *sock,return true;if (call->completion !=RXRPC_CALL_SUCCEEDED )return false; -return !skb_queue_empty (&call->recvmsg_queue); +return (!skb_queue_empty (&call->recvmsg_queue) || + !skb_queue_empty (&call->recvmsg_oobq)); }EXPORT_SYMBOL (rxrpc_kernel_check_life);
@@ -655,7 +656,7 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, unsigned int optlen) {struct rxrpc_sock *rx =rxrpc_sk (sock->sk); -unsigned int min_sec_level; +unsigned int min_sec_level, val;u16 service_upgrade[2 ];int ret;
@@ -736,6 +737,26 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname, rx->service_upgrade.to = service_upgrade[1 ]; goto success; +case RXRPC_MANAGE_RESPONSE : + ret = -EINVAL ; +if (optlen !=sizeof (unsigned int )) + goto error; + ret = -EISCONN ; +if (rx->sk.sk_state !=RXRPC_UNBOUND ) + goto error; + ret =copy_safe_from_sockptr (&val,sizeof (val), + optval, optlen); +if (ret) + goto error; + ret = -EINVAL ; +if (val >1 ) + goto error; +if (val) +set_bit (RXRPC_SOCK_MANAGE_RESPONSE , &rx->flags); +else +clear_bit (RXRPC_SOCK_MANAGE_RESPONSE , &rx->flags); + goto success; +default :break ; }
net/rxrpc/ar-internal.h +30 -2
@@ -159,6 +159,7 @@ struct rxrpc_sock {struct rb_root calls;/* User ID -> call mapping */ unsigned long flags;#define RXRPC_SOCK_CONNECTED 0/* connect_srx is set */ +#define RXRPC_SOCK_MANAGE_RESPONSE 1/* User wants to manage RESPONSE packets */ rwlock_t call_lock;/* lock for calls */ u32 min_sec_level;/* minimum security level */ #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
@@ -216,6 +217,11 @@ struct rxrpc_skb_priv {u16 nr_acks;/* Number of acks+nacks */ u8 reason;/* Reason for ack */ } ack; +u32 rxkad_nonce; +struct { +rxrpc_serial_t challenge_serial; +u16 len; + } resp; };struct rxrpc_host_header hdr;/* RxRPC packet header from this packet */ };
@@ -269,9 +275,24 @@ struct rxrpc_security {/* issue a challenge */ int (*issue_challenge)(struct rxrpc_connection *); +/* Validate a challenge packet */ +bool (*validate_challenge)(struct rxrpc_connection *conn, +struct sk_buff *skb); + +/* Fill out the cmsg for recvmsg() to pass on a challenge to userspace. +* The security class gets to add additional information. +*/ +int (*challenge_to_recvmsg)(struct rxrpc_connection *conn, +struct sk_buff *challenge, +struct msghdr *msg); + +/* Parse sendmsg() control message and respond to challenge. */ +int (*sendmsg_respond_to_challenge)(struct rxrpc_call *call, +struct msghdr *msg); +/* respond to a challenge */ -int (*respond_to_challenge)(struct rxrpc_connection *, -struct sk_buff *); +int (*respond_to_challenge)(struct rxrpc_connection *conn, +struct sk_buff *challenge);/* verify a response */ int (*verify_response)(struct rxrpc_connection *,
@@ -526,6 +547,7 @@ struct rxrpc_connection {u32 nonce;/* response re-use preventer */ } rxkad; }; +struct sk_buff *tx_response;/* Response packet to be transmitted */ unsigned long flags;unsigned long events;unsigned long idle_timestamp;/* Time at which last became idle */
@@ -670,6 +692,7 @@ struct rxrpc_call {struct list_head sock_link;/* Link in rx->sock_calls */ struct rb_node sock_node;/* Node in rx->calls */ struct list_head attend_link;/* Link in local->call_attend_q */ +struct sk_buff *challenge;/* Pending challenge to respond to */ struct rxrpc_txbuf *tx_pending;/* Tx buffer being filled */ wait_queue_head_t waitq;/* Wait queue for channel or Tx */ s64 tx_total_len;/* Total length left to be transmitted (or -1) */
@@ -718,6 +741,7 @@ struct rxrpc_call {/* Received data tracking */ struct sk_buff_head recvmsg_queue;/* Queue of packets ready for recvmsg() */ +struct sk_buff_head recvmsg_oobq;/* Queue of OOB packets ready for recvmsg() */ struct sk_buff_head rx_queue;/* Queue of packets for this call to receive */ struct sk_buff_head rx_oos_queue;/* Queue of out of sequence packets */
@@ -831,6 +855,8 @@ enum rxrpc_command {RXRPC_CMD_SEND_ABORT ,/* request abort generation */ RXRPC_CMD_REJECT_BUSY ,/* [server] reject a call as busy */ RXRPC_CMD_CHARGE_ACCEPT ,/* [server] charge accept preallocation */ +RXRPC_CMD_SEND_RESPONSE ,/* [clnt] Send a RESPONSE packet to a challenge */ + RXRPC_CMD_ABORT_RESPONSE, /* [clnt] Send an ABORT packet to a challenge */ }; struct rxrpc_call_params {
@@ -1198,6 +1224,7 @@ void rxrpc_error_report(struct sock *);bool rxrpc_direct_abort (struct sk_buff *skb,enum rxrpc_abort_reason why,s32 abort_code,int err);int rxrpc_io_thread (void *data); +void rxrpc_post_response (struct rxrpc_connection *conn,struct sk_buff *skb);static inline void rxrpc_wake_up_io_thread (struct rxrpc_local *local) {wake_up_process (READ_ONCE (local->io_thread));
@@ -1299,6 +1326,7 @@ void rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_send_data_reqvoid rxrpc_send_conn_abort (struct rxrpc_connection *conn);void rxrpc_reject_packet (struct rxrpc_local *local,struct sk_buff *skb);void rxrpc_send_keepalive (struct rxrpc_peer *); +void rxrpc_send_response (struct rxrpc_connection *conn,struct sk_buff *skb);/* * peer_event.c
net/rxrpc/call_object.c +4 -1
@@ -145,8 +145,9 @@ struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *rx, gfp_t gfp,INIT_LIST_HEAD (&call->recvmsg_link);INIT_LIST_HEAD (&call->sock_link);INIT_LIST_HEAD (&call->attend_link); -skb_queue_head_init (&call->rx_queue);skb_queue_head_init (&call->recvmsg_queue); +skb_queue_head_init (&call->recvmsg_oobq); +skb_queue_head_init (&call->rx_queue);skb_queue_head_init (&call->rx_oos_queue);init_waitqueue_head (&call->waitq);spin_lock_init (&call->notify_lock);
@@ -551,6 +552,7 @@ static void rxrpc_cleanup_tx_buffers(struct rxrpc_call *call)static void rxrpc_cleanup_rx_buffers (struct rxrpc_call *call) {rxrpc_purge_queue (&call->recvmsg_queue); +rxrpc_purge_queue (&call->recvmsg_oobq);rxrpc_purge_queue (&call->rx_queue);rxrpc_purge_queue (&call->rx_oos_queue); }
@@ -692,6 +694,7 @@ static void rxrpc_destroy_call(struct work_struct *work)rxrpc_cleanup_tx_buffers (call);rxrpc_cleanup_rx_buffers (call); +rxrpc_free_skb (call->challenge, rxrpc_skb_put_challenge);rxrpc_put_txbuf (call->tx_pending, rxrpc_txbuf_put_cleaned);rxrpc_put_connection (call->conn, rxrpc_conn_put_call);rxrpc_deactivate_bundle (call->bundle);
net/rxrpc/conn_event.c +91 -6
138 lines not on this page · raw message
net/rxrpc/conn_object.c +1 -0
@@ -329,6 +329,7 @@ static void rxrpc_clean_up_connection(struct work_struct *work) }rxrpc_purge_queue (&conn->rx_queue); +rxrpc_free_skb (conn->tx_response, rxrpc_skb_put_response);rxrpc_kill_client_conn (conn);
net/rxrpc/insecure.c +10 -3
@@ -42,13 +42,19 @@ static void none_free_call_crypto(struct rxrpc_call *call) { } -static int none_respond_to_challenge (struct rxrpc_connection *conn, -struct sk_buff *skb) +static bool none_validate_challenge (struct rxrpc_connection *conn, +struct sk_buff *skb) {return rxrpc_abort_conn (conn, skb,RX_PROTOCOL_ERROR , -EPROTO , rxrpc_eproto_rxnull_challenge); } +static int none_sendmsg_respond_to_challenge (struct rxrpc_call *call, +struct msghdr *msg) +{ +return -EINVAL ; +} +static int none_verify_response (struct rxrpc_connection *conn,struct sk_buff *skb) {
@@ -82,7 +88,8 @@ const struct rxrpc_security rxrpc_no_security = { .alloc_txbuf = none_alloc_txbuf, .secure_packet = none_secure_packet, .verify_packet = none_verify_packet, - .respond_to_challenge = none_respond_to_challenge, + .validate_challenge = none_validate_challenge, + .sendmsg_respond_to_challenge = none_sendmsg_respond_to_challenge, .verify_response = none_verify_response, .clear = none_clear, };
net/rxrpc/io_thread.c +5 -3
@@ -501,9 +501,11 @@ int rxrpc_io_thread(void *data) }/* Deal with connections that want immediate attention. */ -spin_lock_irq (&local->lock); -list_splice_tail_init (&local->conn_attend_q, &conn_attend_q); -spin_unlock_irq (&local->lock); +if (!list_empty_careful (&local->conn_attend_q)) { +spin_lock_irq (&local->lock); +list_splice_tail_init (&local->conn_attend_q, &conn_attend_q); +spin_unlock_irq (&local->lock); + } while ((conn = list_first_entry_or_null(&conn_attend_q, struct rxrpc_connection,
net/rxrpc/output.c +56 -0
59 lines not on this page · raw message
net/rxrpc/recvmsg.c +109 -5
165 lines not on this page · raw message
net/rxrpc/rxkad.c +173 -108
341 lines not on this page · raw message
net/rxrpc/sendmsg.c +65 -4
88 lines not on this page · raw message
net/rxrpc/server_key.c +40 -0
@@ -169,3 +169,43 @@ int rxrpc_sock_set_security_keyring(struct sock *sk, struct key *keyring)return ret; }EXPORT_SYMBOL (rxrpc_sock_set_security_keyring); + +/** +* rxrpc_sock_set_manage_response - Set the manage-response flag for a kernel service +* @sk: The socket to set the keyring on +* @set: True to set, false to clear the flag +* +* Set the flag on an rxrpc socket to say that the caller wants to manage the +* RESPONSE packet and the user-defined data it may contain. Setting this +* means that recvmsg() will return messages with RXRPC_CHALLENGED in the +* control message buffer containing information about the challenge. +* +* The user should respond to the challenge by passing RXRPC_RESPOND or +* RXRPC_RESPOND_ABORT control messages with sendmsg() to the same call. +* Supplementary control messages, such as RXRPC_RESP_RXGK_APPDATA, may be +* included to indicate the parts the user wants to supply. +* +* The server will be passed the response data with a RXRPC_RESPONDED control +* message when it gets the first data from each call. +* +* Note that this is only honoured by security classes that need auxiliary data +* (e.g. RxGK). Those that don't offer the facility (e.g. RxKAD) respond +* without consulting userspace. +* +* Returns the previous setting. +*/ +int rxrpc_sock_set_manage_response (struct sock *sk,bool set) +{ +struct rxrpc_sock *rx =rxrpc_sk (sk); +int ret; + +lock_sock (sk); + ret = !!test_bit (RXRPC_SOCK_MANAGE_RESPONSE , &rx->flags); +if (set) +set_bit (RXRPC_SOCK_MANAGE_RESPONSE , &rx->flags); +else +clear_bit (RXRPC_SOCK_MANAGE_RESPONSE , &rx->flags); +release_sock (sk); +return ret; +} +EXPORT_SYMBOL (rxrpc_sock_set_manage_response);
David Howells
maintainerPATCH 20/24 rxrpc: Add the security index for yfs-rxgk
In reply to David HowellsAdd the security index and abort codes for the YFS variant of rxgk.
--- fs/afs/misc.c | 13 +++++++++++++ include/uapi/linux/rxrpc.h | 17 +++++++++++++++++ 2 files changed, 30 insertions(+)
fs/afs/misc.c +13 -0
@@ -103,6 +103,19 @@ int afs_abort_to_error(u32 abort_code)case RXKADDATALEN :return -EKEYREJECTED ;case RXKADILLEGALLEVEL :return -EKEYREJECTED ; +case RXGK_INCONSISTENCY :return -EPROTO ; +case RXGK_PACKETSHORT :return -EPROTO ; +case RXGK_BADCHALLENGE :return -EPROTO ; +case RXGK_BADETYPE :return -ENOPKG ; +case RXGK_BADLEVEL :return -EKEYREJECTED ; +case RXGK_BADKEYNO :return -EKEYREJECTED ; +case RXGK_EXPIRED :return -EKEYEXPIRED ; +case RXGK_NOTAUTH :return -EKEYREJECTED ; +case RXGK_BAD_TOKEN :return -EKEYREJECTED ; +case RXGK_SEALED_INCON :return -EKEYREJECTED ; +case RXGK_DATA_LEN :return -EPROTO ; +case RXGK_BAD_QOP :return -EKEYREJECTED ; +case RXGEN_OPCODE :return -ENOTSUPP ;default :return -EREMOTEIO ;
include/uapi/linux/rxrpc.h +17 -0
@@ -80,6 +80,7 @@ enum rxrpc_cmsg_type {#define RXRPC_SECURITY_RXKAD 2/* kaserver or kerberos 4 */ #define RXRPC_SECURITY_RXGK 4/* gssapi-based */ #define RXRPC_SECURITY_RXK5 5/* kerberos 5 */ +#define RXRPC_SECURITY_YFS_RXGK 6/* YFS gssapi-based */ /* * RxRPC-level abort codes
@@ -125,6 +126,22 @@ enum rxrpc_cmsg_type {#define RXKADDATALEN 19270411/* user data too long */ #define RXKADILLEGALLEVEL 19270412/* caller not authorised to use encrypted conns */ +/* +* RxGK GSSAPI security abort codes. +*/ +#define RXGK_INCONSISTENCY 1233242880/* Security module structure inconsistent */ +#define RXGK_PACKETSHORT 1233242881/* Packet too short for security challenge */ +#define RXGK_BADCHALLENGE 1233242882/* Invalid security challenge */ +#define RXGK_BADETYPE 1233242883/* Invalid or impermissible encryption type */ +#define RXGK_BADLEVEL 1233242884/* Invalid or impermissible security level */ +#define RXGK_BADKEYNO 1233242885/* Key version number not found */ +#define RXGK_EXPIRED 1233242886/* Token has expired */ +#define RXGK_NOTAUTH 1233242887/* Caller not authorized */ +#define RXGK_BAD_TOKEN 1233242888/* Security object was passed a bad token */ +#define RXGK_SEALED_INCON 1233242889/* Sealed data inconsistent */ +#define RXGK_DATA_LEN 1233242890/* User data too long */ +#define RXGK_BAD_QOP 1233242891/* Inadequate quality of protection available */ +/* * Challenge information in the RXRPC_CHALLENGED control message. */
Re: [PATCH net 20/24] rxrpc: Add the security index for yfs-rxgk
Quoted 14 lines · David Howells
Add the security index and abort codes for the YFS variant of rxgk.
Signed-off-by David Howells <[email protected]>---
fs/afs/misc.c| 13 +++++++++++++include/uapi/linux/rxrpc.h| 17 +++++++++++++++++2 files changed, 30 insertions(+)fs/afs/misc.c +0
-0
...
Quoted 25 lines
include/uapi/linux/rxrpc.h +10
-0@@ -80,6 +80,7 @@ enum rxrpc_cmsg_type {#define RXRPC_SECURITY_RXKAD 2/* kaserver or kerberos 4 */ #define RXRPC_SECURITY_RXGK 4/* gssapi-based */ #define RXRPC_SECURITY_RXK5 5/* kerberos 5 */ +#define RXRPC_SECURITY_YFS_RXGK 6/* YFS gssapi-based */ /* * RxRPC-level abort codes @@ -125,6 +126,22 @@ enum rxrpc_cmsg_type {#define RXKADDATALEN 19270411/* user data too long */ #define RXKADILLEGALLEVEL 19270412/* caller not authorised to use encrypted conns */ +/* +* RxGK GSSAPI security abort codes. +*/ +#define RXGK_INCONSISTENCY 1233242880/* Security module structure inconsistent */ +#define RXGK_PACKETSHORT 1233242881/* Packet too short for security challenge */ +#define RXGK_BADCHALLENGE 1233242882/* Invalid security challenge */ +#define RXGK_BADETYPE 1233242883/* Invalid or impermissible encryption type */ +#define RXGK_BADLEVEL 1233242884/* Invalid or impermissible security level */ +#define RXGK_BADKEYNO 1233242885/* Key version number not found */
include/uapi/linux/rxrpc.h enum rxrpc_cmsg_type { · line 147
Quoted 10 lines
include/uapi/linux/rxrpc.h +7
-0+#define RXGK_EXPIRED 1233242886/* Token has expired */ +#define RXGK_NOTAUTH 1233242887/* Caller not authorized */ +#define RXGK_BAD_TOKEN 1233242888/* Security object was passed a bad token */ +#define RXGK_SEALED_INCON 1233242889/* Sealed data inconsistent */ +#define RXGK_DATA_LEN 1233242890/* User data too long */ +#define RXGK_BAD_QOP 1233242891/* Inadequate quality of protection available */ +/* * Challenge information in the RXRPC_CHALLENGED control message. */
David,
Unfortunately these are not the RXGK error code assignments used by YFS_RXGK. The correct assignments are documented at
https://registrar.central.org/et/RXGK_auristorfs.html
RXGKINCONSISTENCY (1233242880L) Security module structure inconsistent RXGKPACKETSHORT (1233242881L) Packet too short for security challenge RXGKBADCHALLENGE (1233242882L) Security challenge/response failed RXGKSEALEDINCON (1233242883L) Sealed data is inconsistent RXGKNOTAUTH (1233242884L) Caller not authorised
RXGKEXPIRED (1233242885L) Authentication expired RXGKBADLEVEL (1233242886L) Unsupported or not permitted security level RXGKBADKEYNO (1233242887L) Bad transport key number RXGKNOTRXGK (1233242888L) Security layer is not rxgk RXGKUNSUPPORTED (1233242889L) Endpoint does not support rxgk RXGKGSSERROR (1233242890L) GSSAPI mechanism error
The YFS_RXGK variant of the RXGK error table conflicts with the error table documented in rxgk: GSSAPI based security class for RX.
https://datatracker.ietf.org/doc/draft-wilkinson-afs3-rxgk/
The RXGK error table used in conjunction with the yfs-rxgk security class predates the error table in the Internet-Draft by more than two years.
A request that OpenAFS renumber was submitted in June 2023 but has yet to be acted upon.
https://gerrit.openafs.org/#/c/15467/
Sorry for the inconvenience.
Jeffrey Altman
David Howells
maintainerPATCH 21/24 rxrpc: Add YFS RxGK (GSSAPI) security class
In reply to David HowellsAdd support for the YFS-variant RxGK security class to support GSSAPI-derived authentication. This also allows the use of better crypto over the rxkad security class.
The key payload is XDR encoded of the form:
typedef int64_t opr_time;
const AFSTOKEN_RK_TIX_MAX = 12000; /* Matches entry in rxkad.h */
struct token_rxkad {
afs_int32 viceid;
afs_int32 kvno;
afs_int64 key;
afs_int32 begintime;
afs_int32 endtime;
afs_int32 primary_flag;
opaque ticket<AFSTOKEN_RK_TIX_MAX>;
};
struct token_rxgk {
opr_time begintime;
opr_time endtime;
afs_int64 level;
afs_int64 lifetime;
afs_int64 bytelife;
afs_int64 enctype;
opaque key<>;
opaque ticket<>;
};
const AFSTOKEN_UNION_NOAUTH = 0;
const AFSTOKEN_UNION_KAD = 2;
const AFSTOKEN_UNION_YFSGK = 6;
union ktc_tokenUnion switch (afs_int32 type) {
case AFSTOKEN_UNION_KAD:
token_rxkad kad;
case AFSTOKEN_UNION_YFSGK:
token_rxgk gk;
};
const AFSTOKEN_LENGTH_MAX = 16384;
typedef opaque token_opaque<AFSTOKEN_LENGTH_MAX>;
const AFSTOKEN_MAX = 8;
const AFSTOKEN_CELL_MAX = 64;
struct ktc_setTokenData {
afs_int32 flags;
string cell<AFSTOKEN_CELL_MAX>;
token_opaque tokens<AFSTOKEN_MAX>;
};The parser for the basic token struct is already present, as is the rxkad token type. This adds a parser for the rxgk token type.
--- include/keys/rxrpc-type.h | 17 ++++ net/rxrpc/key.c | 185 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+)
include/keys/rxrpc-type.h +17 -0
@@ -9,6 +9,7 @@#define _KEYS_RXRPC_TYPE_H#include <linux/key.h> +#include <crypto/krb5.h> /* * key type for AF_RXRPC keys
@@ -31,6 +32,21 @@ struct rxkad_key {u8 ticket[];/* the encrypted ticket */ }; +/* +* RxRPC key for YFS-RxGK (type-6 security) +*/ +struct rxgk_key { +s64 begintime;/* Time at which the ticket starts */ +s64 endtime;/* Time at which the ticket ends */ +u64 lifetime;/* Maximum lifespan of a connection (seconds) */ +u64 bytelife;/* Maximum number of bytes on a connection */ +unsigned int enctype;/* Encoding type */ +s8 level;/* Negotiated security RXRPC_SECURITY_PLAIN/AUTH/ENCRYPT */ +struct krb5_buffer key;/* Master key, K0 */ +struct krb5_buffer ticket;/* Ticket to be passed to server */ +u8 _key[];/* Key storage */ +}; +/* * list of tokens attached to an rxrpc key */
@@ -40,6 +56,7 @@ struct rxrpc_key_token {struct rxrpc_key_token *next;/* the next token in the list */ union {struct rxkad_key *kad; +struct rxgk_key *rxgk; }; };
net/rxrpc/key.c +185 -0
221 lines not on this page · raw message
David Howells
maintainerPATCH 22/24 rxrpc: rxgk: Provide infrastructure and key derivation
In reply to David HowellsProvide some infrastructure for implementing the RxGK transport security class:
(1) A definition of an encoding type, including:
- Relevant crypto-layer names
- Lengths of the crypto keys and checksums involved
- Crypto functions specific to the encoding type
- Crypto scheme used for that type
(2) A definition of a crypto scheme, including:
- Underlying crypto handlers
- The pseudo-random function, PRF, used in base key derivation
- Functions for deriving usage keys Kc, Ke and Ki
- Functions for en/decrypting parts of an sk_buff
(3) A key context, with the usage keys required for a derivative of a transport key for a specific key number. This includes keys for securing packets for transmission, extracting received packets and dealing with response packets.
(3) A function to look up an encoding type by number.
(4) A function to set up a key context and derive the keys.
(5) A function to set up the keys required to extract the ticket obtained from the GSS negotiation in the server.
(6) Miscellaneous functions for context handling.
The keys and key derivation functions are described in:
tools.ietf.org/html/draft-wilkinson-afs3-rxgk-11
--- net/rxrpc/Kconfig | 10 ++ net/rxrpc/Makefile | 3 +- net/rxrpc/ar-internal.h | 3 + net/rxrpc/rxgk_common.h | 48 +++++++ net/rxrpc/rxgk_kdf.c | 287 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 net/rxrpc/rxgk_common.h create mode 100644 net/rxrpc/rxgk_kdf.c
net/rxrpc/Kconfig +10 -0
@@ -67,6 +67,16 @@ config RXKAD See Documentation/networking/rxrpc.rst. +config RXGK + bool "RxRPC GSSAPI security" + depends on AF_RXRPC + depends on CRYPTO_KRB5 + help + Provide the GSSAPI-based RxGK security class for AFS. Keys are added + with add_key(). + + See Documentation/networking/rxrpc.rst. + config RXPERF tristate "RxRPC test service" help
net/rxrpc/Makefile +2 -1
@@ -39,6 +39,7 @@ rxrpc-y := \ rxrpc-$(CONFIG_PROC_FS) += proc.o rxrpc-$(CONFIG_RXKAD) += rxkad.o rxrpc-$(CONFIG_SYSCTL) += sysctl.o - +rxrpc-$(CONFIG_RXGK) += \ + rxgk_kdf.o obj-$(CONFIG_RXPERF) += rxperf.o
net/rxrpc/ar-internal.h +3 -0
@@ -546,6 +546,9 @@ struct rxrpc_connection {struct rxrpc_crypt csum_iv;/* packet checksum base */ u32 nonce;/* response re-use preventer */ } rxkad; +struct { +u64 start_time;/* The start time for TK derivation */ + } rxgk; };struct sk_buff *tx_response;/* Response packet to be transmitted */ unsigned long flags;
net/rxrpc/rxgk_common.h new file +48 -0
48 lines not on this page · raw message
net/rxrpc/rxgk_kdf.c new file +287 -0
287 lines not on this page · raw message
David Howells
maintainerPATCH 23/24 rxrpc: rxgk: Implement the yfs-rxgk security class (GSSAPI)
In reply to David HowellsImplement the basic parts of the yfs-rxgk security class (security index 6) to support GSSAPI-negotiated security.
--- fs/afs/cm_security.c | 7 + include/trace/events/rxrpc.h | 45 +- net/rxrpc/Makefile | 2 + net/rxrpc/ar-internal.h | 16 + net/rxrpc/output.c | 2 +- net/rxrpc/protocol.h | 20 + net/rxrpc/rxgk.c | 1216 ++++++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 285 ++++++++ net/rxrpc/rxgk_common.h | 90 +++ net/rxrpc/rxkad.c | 6 +- net/rxrpc/security.c | 3 + 11 files changed, 1687 insertions(+), 5 deletions(-) create mode 100644 net/rxrpc/rxgk.c create mode 100644 net/rxrpc/rxgk_app.c
fs/afs/cm_security.c +7 -0
@@ -6,6 +6,7 @@*/ #include <linux/slab.h> +#include <crypto/krb5.h> #include "internal.h" #include "afs_fs.h" #include "protocol_yfs.h"
@@ -18,6 +19,8 @@int afs_respond_to_challenge (struct rxrpc_call *rxcall,unsigned long user_call_ID,u16 service_id,u8 security_index) { +struct krb5_buffer appdata = {}; +_enter ("%u,%u" , service_id, security_index);switch (service_id) {
@@ -40,6 +43,10 @@ int afs_respond_to_challenge(struct rxrpc_call *rxcall, unsigned long user_call_case RXRPC_SECURITY_RXKAD :return rxkad_kernel_respond_to_challenge (rxcall); +case RXRPC_SECURITY_RXGK : +case RXRPC_SECURITY_YFS_RXGK : +return rxgk_kernel_respond_to_challenge (rxcall, &appdata); +default :return rxrpc_kernel_reject_challenge (rxcall,RX_USER_ABORT , -EPROTO , afs_abort_unsupported_sec_class);
include/trace/events/rxrpc.h +43 -2
101 lines not on this page · raw message
net/rxrpc/Makefile +2 -0
@@ -40,6 +40,8 @@ rxrpc-$(CONFIG_PROC_FS) += proc.o rxrpc-$(CONFIG_RXKAD) += rxkad.o rxrpc-$(CONFIG_SYSCTL) += sysctl.o rxrpc-$(CONFIG_RXGK) += \ + rxgk.o \ + rxgk_app.o \ rxgk_kdf.o obj-$(CONFIG_RXPERF) += rxperf.o
net/rxrpc/ar-internal.h +16 -0
@@ -31,6 +31,7 @@ struct key_preparsed_payload;struct rxrpc_connection ;struct rxrpc_txbuf ;struct rxrpc_txqueue ; +struct rxgk_context ;/* * Mark applied to socket buffers in skb->mark. skb->priority is used
@@ -300,6 +301,11 @@ struct rxrpc_security {/* clear connection security */ void (*clear)(struct rxrpc_connection *); + +/* Default ticket -> key decoder */ +int (*default_decode_ticket)(struct rxrpc_connection *conn,struct sk_buff *skb, +unsigned int ticket_offset,unsigned int ticket_len, +struct key **_key); };/*
@@ -547,7 +553,9 @@ struct rxrpc_connection {u32 nonce;/* response re-use preventer */ } rxkad;struct { +struct rxgk_context *keys[1 ];u64 start_time;/* The start time for TK derivation */ +u8 nonce[20 ];/* Response re-use preventer */ } rxgk; };struct sk_buff *tx_response;/* Response packet to be transmitted */
@@ -895,6 +903,8 @@ struct rxrpc_txbuf {unsigned short len;/* Amount of data in buffer */ unsigned short space;/* Remaining data space */ unsigned short offset;/* Offset of fill point */ +unsigned short crypto_header;/* Size of crypto header */ +unsigned short sec_header;/* Size of security header */ unsigned short pkt_len;/* Size of packet content */ unsigned short alloc_size;/* Amount of bufferage allocated */ unsigned int flags;
@@ -1321,6 +1331,7 @@ static inline struct rxrpc_net *rxrpc_net(struct net *net)/* * output.c */ +ssize_t do_udp_sendmsg (struct socket *socket,struct msghdr *msg,size_t len);void rxrpc_send_ACK (struct rxrpc_call *call,u8 ack_reason,rxrpc_serial_t serial,enum rxrpc_propose_ack_trace why);void rxrpc_send_probe_for_pmtud (struct rxrpc_call *call);
@@ -1393,6 +1404,11 @@ void rxrpc_call_add_rtt(struct rxrpc_call *call, enum rxrpc_rtt_rx_trace why,ktime_t rxrpc_get_rto_backoff (struct rxrpc_call *call,bool retrans);void rxrpc_call_init_rtt (struct rxrpc_call *call); +/* +* rxgk.c +*/ +extern const struct rxrpc_security rxgk_yfs; +/* * rxkad.c */
net/rxrpc/output.c +1 -1
@@ -18,7 +18,7 @@extern int udpv6_sendmsg (struct sock *sk,struct msghdr *msg,size_t len); -static ssize_t do_udp_sendmsg (struct socket *socket,struct msghdr *msg,size_t len) +ssize_t do_udp_sendmsg (struct socket *socket,struct msghdr *msg,size_t len) {struct sockaddr *sa = msg->msg_name;struct sock *sk = socket->sk;
net/rxrpc/protocol.h +20 -0
@@ -181,4 +181,24 @@ struct rxkad_response { __be32 ticket_len; /* Kerberos ticket length */ } __packed; +/* +* GSSAPI security type-4 and type-6 data header. +*/ +struct rxgk_header { +__be32 epoch; +__be32 cid; +__be32 call_number; +__be32 seq; +__be32 sec_index; +__be32 data_len; +} __packed; + +/* +* GSSAPI security type-4 and type-6 response packet header. +*/ +struct rxgk_response { +__be64 start_time; +__be32 token_len; +} __packed; +#endif /* _LINUX_RXRPC_PACKET_H */
net/rxrpc/rxgk.c new file +1216 -0
1,216 lines not on this page · raw message
net/rxrpc/rxgk_app.c new file +285 -0
285 lines not on this page · raw message
net/rxrpc/rxgk_common.h +90 -0
99 lines not on this page · raw message
net/rxrpc/rxkad.c +4 -2
@@ -177,8 +177,10 @@ static struct rxrpc_txbuf *rxkad_alloc_txbuf(struct rxrpc_call *call, size_t remif (!txb)return NULL ; - txb->offset += shdr; - txb->space = part; + txb->crypto_header =0 ; + txb->sec_header = shdr; + txb->offset += shdr; + txb->space = part;return txb; }
net/rxrpc/security.c +3 -0
@@ -20,6 +20,9 @@ static const struct rxrpc_security *rxrpc_security_types[] = { #ifdef CONFIG_RXKAD [RXRPC_SECURITY_RXKAD ] = &rxkad, #endif +#ifdef CONFIG_RXGK + [RXRPC_SECURITY_YFS_RXGK] = &rxgk_yfs, +#endif };int __init rxrpc_init_security (void )
David Howells
maintainerPATCH 24/24 rxrpc: rxgk: Implement connection rekeying
In reply to David HowellsImplement rekeying of connections with the RxGK security class. This involves regenerating the keys with a different key number as part of the input data after a certain amount of time or a certain amount of bytes encrypted. Rekeying may be triggered by either end.
The LSW of the key number is inserted into the security-specific field in the RX header, and we try and expand it to 32-bits to make it last longer.
--- net/rxrpc/ar-internal.h | 5 +- net/rxrpc/conn_object.c | 1 + net/rxrpc/rxgk.c | 156 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 155 insertions(+), 7 deletions(-)
net/rxrpc/ar-internal.h +4 -1
@@ -553,12 +553,15 @@ struct rxrpc_connection {u32 nonce;/* response re-use preventer */ } rxkad;struct { -struct rxgk_context *keys[1 ]; +struct rxgk_context *keys[4 ];/* (Re-)keying buffer */ u64 start_time;/* The start time for TK derivation */ u8 nonce[20 ];/* Response re-use preventer */ +u32 key_number;/* Current key number */ } rxgk; }; +rwlock_t security_use_lock;/* Security use/modification lock */ struct sk_buff *tx_response;/* Response packet to be transmitted */ +unsigned long flags;unsigned long events;unsigned long idle_timestamp;/* Time at which last became idle */
net/rxrpc/conn_object.c +1 -0
@@ -73,6 +73,7 @@ struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *rxnet,skb_queue_head_init (&conn->rx_queue); conn->rxnet = rxnet; conn->security = &rxrpc_no_security; +rwlock_init (&conn->security_use_lock);spin_lock_init (&conn->state_lock); conn->debug_id =atomic_inc_return (&rxrpc_debug_id); conn->idle_timestamp = jiffies;
net/rxrpc/rxgk.c +150 -6
178 lines not on this page · raw message
David Howells
maintainerOops. This should have been tagged for net-next, not for net.
David