sctp: Convert to use crypto lib, and upgrade cookie auth
Subsystems (7)
v2 cover sctp: Convert to use crypto lib, and upgrade cookie auth
This series converts SCTP chunk and cookie authentication to use the crypto library API instead of crypto_shash. This is much simpler (the diffstat should speak for itself), and also faster too. In addition, this series upgrades the cookie authentication to use HMAC-SHA256.
I've tested that kernels with this series applied can continue to communicate using SCTP with older ones, in either direction, using any choice of None, HMAC-SHA1, or HMAC-SHA256 chunk authentication.
Changed in v2:
- Added patch which adds CONFIG_CRYPTO_SHA1 to some selftests configs
Eric Biggers (3):
selftests: net: Explicitly enable CONFIG_CRYPTO_SHA1 for IPsec
sctp: Use HMAC-SHA1 and HMAC-SHA256 library for chunk authentication
sctp: Convert cookie authentication to use HMAC-SHA256
Documentation/networking/ip-sysctl.rst | 11 +- include/net/netns/sctp.h | 4 +- include/net/sctp/auth.h | 17 +- include/net/sctp/constants.h | 9 +- include/net/sctp/structs.h | 35 +--- net/sctp/Kconfig | 47 ++---- net/sctp/auth.c | 166 ++++--------------- net/sctp/chunk.c | 3 +- net/sctp/endpointola.c | 23 +-- net/sctp/protocol.c | 11 +- net/sctp/sm_make_chunk.c | 60 +++---- net/sctp/sm_statefuns.c | 2 +- net/sctp/socket.c | 41 +---- net/sctp/sysctl.c | 51 +++--- tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/netfilter/config | 1 + 16 files changed, 124 insertions(+), 358 deletions(-)
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
Signature · 1 line
2.50.1
PATCH v2 1/3 selftests: net: Explicitly enable CONFIG_CRYPTO_SHA1 for IPsec
xfrm_policy.sh, nft_flowtable.sh, and vrf-xfrm-tests.sh use 'ip xfrm' with SHA-1, either 'auth sha1' or 'auth-trunc hmac(sha1)'. That requires CONFIG_CRYPTO_SHA1, which CONFIG_INET_ESP intentionally doesn't select (as per its help text). Previously, the config for these tests relied on CONFIG_CRYPTO_SHA1 being selected by the unrelated option CONFIG_IP_SCTP. Since CONFIG_IP_SCTP is being changed to no longer do that, instead add CONFIG_CRYPTO_SHA1 to the configs explicitly.
--- tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/netfilter/config | 1 + 2 files changed, 2 insertions(+)
tools/testing/selftests/net/config +1 -0
@@ -24,10 +24,11 @@ CONFIG_VLAN_8021Q=y CONFIG_GENEVE=m CONFIG_IFB=y CONFIG_INET_DIAG=y CONFIG_INET_ESP=y CONFIG_INET_ESP_OFFLOAD=y +CONFIG_CRYPTO_SHA1=y CONFIG_NET_FOU=y CONFIG_NET_FOU_IP_TUNNELS=y CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NETFILTER_XTABLES_LEGACY=y
tools/testing/selftests/net/netfilter/config +1 -0
@@ -11,10 +11,11 @@ CONFIG_BRIDGE_NETFILTER=m CONFIG_BRIDGE_NF_EBTABLES=m CONFIG_BRIDGE_VLAN_FILTERING=y CONFIG_CGROUP_BPF=y CONFIG_DUMMY=m CONFIG_INET_ESP=m +CONFIG_CRYPTO_SHA1=m CONFIG_IP_NF_MATCH_RPFILTER=m CONFIG_IP6_NF_MATCH_RPFILTER=m CONFIG_IP_NF_IPTABLES=m CONFIG_IP_NF_IPTABLES_LEGACY=m CONFIG_IP6_NF_IPTABLES=m
Signature · 1 line
2.50.1
PATCH v2 2/3 sctp: Use HMAC-SHA1 and HMAC-SHA256 library for chunk authentication
In reply to Eric BiggersFor SCTP chunk authentication, use the HMAC-SHA1 and HMAC-SHA256 library functions instead of crypto_shash. This is simpler and faster. There's no longer any need to pre-allocate 'crypto_shash' objects; the SCTP code now simply calls into the HMAC code directly.
As part of this, make SCTP always support both HMAC-SHA1 and HMAC-SHA256. Previously, it only guaranteed support for HMAC-SHA1. However, HMAC-SHA256 tended to be supported too anyway, as it was supported if CONFIG_CRYPTO_SHA256 was enabled elsewhere in the kconfig.
--- include/net/sctp/auth.h | 17 ++-- include/net/sctp/constants.h | 4 - include/net/sctp/structs.h | 5 -- net/sctp/Kconfig | 15 ++-- net/sctp/auth.c | 166 ++++++----------------------------- net/sctp/chunk.c | 3 +- net/sctp/sm_make_chunk.c | 2 +- net/sctp/sm_statefuns.c | 2 +- net/sctp/socket.c | 10 --- 9 files changed, 47 insertions(+), 177 deletions(-)
include/net/sctp/auth.h +6 -11
@@ -20,20 +20,15 @@struct sctp_endpoint ;struct sctp_association ;struct sctp_authkey ;struct sctp_hmacalgo ; -struct crypto_shash ; -/* -* Define a generic struct that will hold all the info -* necessary for an HMAC transform -*/ +/* Defines an HMAC algorithm supported by SCTP chunk authentication */ struct sctp_hmac { -__u16 hmac_id;/* one of the above ids */ -char *hmac_name;/* name for loading */ -__u16 hmac_len;/* length of the signature */ +__u16 hmac_id;/* one of SCTP_AUTH_HMAC_ID_* */ +__u16 hmac_len;/* length of the HMAC value in bytes */ };/* This is generic structure that containst authentication bytes used * as keying material. It's a what is referred to as byte-vector all * over SCTP-AUTH
@@ -76,13 +71,13 @@ struct sctp_shared_key *sctp_auth_get_shkey( __u16 key_id);int sctp_auth_asoc_copy_shkeys (const struct sctp_endpoint *ep,struct sctp_association *asoc,gfp_t gfp);int sctp_auth_init_hmacs (struct sctp_endpoint *ep,gfp_t gfp); -void sctp_auth_destroy_hmacs (struct crypto_shash *auth_hmacs[]); -struct sctp_hmac *sctp_auth_get_hmac (__u16 hmac_id); -struct sctp_hmac *sctp_auth_asoc_get_hmac (const struct sctp_association *asoc); +const struct sctp_hmac *sctp_auth_get_hmac (__u16 hmac_id); +const struct sctp_hmac * +sctp_auth_asoc_get_hmac (const struct sctp_association *asoc);void sctp_auth_asoc_set_default_hmac (struct sctp_association *asoc,struct sctp_hmac_algo_param *hmacs);int sctp_auth_asoc_verify_hmac_id (const struct sctp_association *asoc,__be16 hmac_id); int sctp_auth_send_cid(enum sctp_cid chunk,
include/net/sctp/constants.h +0 -4
@@ -415,20 +415,16 @@ enum sctp_lower_cwnd {*/ enum {SCTP_AUTH_HMAC_ID_RESERVED_0 ,SCTP_AUTH_HMAC_ID_SHA1 ,SCTP_AUTH_HMAC_ID_RESERVED_2 , -#if defined (CONFIG_CRYPTO_SHA256 ) || defined (CONFIG_CRYPTO_SHA256_MODULE )SCTP_AUTH_HMAC_ID_SHA256 , -#endif __SCTP_AUTH_HMAC_MAX };#define SCTP_AUTH_HMAC_ID_MAX __SCTP_AUTH_HMAC_MAX - 1#define SCTP_AUTH_NUM_HMACS __SCTP_AUTH_HMAC_MAX -#define SCTP_SHA1_SIG_SIZE 20 -#define SCTP_SHA256_SIG_SIZE 32/* SCTP-AUTH, Section 3.2 * The chunk types for INIT, INIT-ACK, SHUTDOWN-COMPLETE and AUTH chunks * MUST NOT be listed in the CHUNKS parameter */
include/net/sctp/structs.h +0 -5
@@ -1327,15 +1327,10 @@ struct sctp_endpoint {__u32 sndbuf_policy;/* rcvbuf acct. policy. */ __u32 rcvbuf_policy; -/* SCTP AUTH: array of the HMACs that will be allocated -* we need this per association so that we don't serialize -*/ -struct crypto_shash **auth_hmacs; -/* SCTP-AUTH: hmacs for the endpoint encoded into parameter */ struct sctp_hmac_algo_param *auth_hmacs_list;/* SCTP-AUTH: chunks to authenticate encoded into parameter */ struct sctp_chunks_param *auth_chunk_list;
net/sctp/Kconfig +8 -7
@@ -5,13 +5,12 @@ menuconfig IP_SCTP tristate "The SCTP Protocol" depends on INET depends on IPV6 || IPV6=n - select CRYPTO - select CRYPTO_HMAC - select CRYPTO_SHA1 + select CRYPTO_LIB_SHA1 + select CRYPTO_LIB_SHA256 select NET_CRC32C select NET_UDP_TUNNEL help Stream Control Transmission Protocol
@@ -77,19 +76,21 @@ endchoice config SCTP_COOKIE_HMAC_MD5 bool "Enable optional MD5 hmac cookie generation" help Enable optional MD5 hmac based SCTP cookie generation - select CRYPTO_HMAC if SCTP_COOKIE_HMAC_MD5 - select CRYPTO_MD5 if SCTP_COOKIE_HMAC_MD5 + select CRYPTO + select CRYPTO_HMAC + select CRYPTO_MD5 config SCTP_COOKIE_HMAC_SHA1 bool "Enable optional SHA1 hmac cookie generation" help Enable optional SHA1 hmac based SCTP cookie generation - select CRYPTO_HMAC if SCTP_COOKIE_HMAC_SHA1 - select CRYPTO_SHA1 if SCTP_COOKIE_HMAC_SHA1 + select CRYPTO + select CRYPTO_HMAC + select CRYPTO_SHA1 config INET_SCTP_DIAG depends on INET_DIAG def_tristate INET_DIAG
net/sctp/auth.c +29 -137
317 lines not on this page · raw message
net/sctp/chunk.c +2 -1
@@ -182,11 +182,12 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,/* If the peer requested that we authenticate DATA chunks * we need to account for bundling of the AUTH chunks along with * DATA. */ if (sctp_auth_send_cid (SCTP_CID_DATA , asoc)) { -struct sctp_hmac *hmac_desc =sctp_auth_asoc_get_hmac (asoc); +const struct sctp_hmac *hmac_desc = +sctp_auth_asoc_get_hmac (asoc);if (hmac_desc) max_data -=SCTP_PAD4 (sizeof (struct sctp_auth_chunk ) + hmac_desc->hmac_len);
net/sctp/sm_make_chunk.c +1 -1
@@ -1317,11 +1317,11 @@ struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,struct sctp_chunk *sctp_make_auth (const struct sctp_association *asoc,__u16 key_id) {struct sctp_authhdr auth_hdr; -struct sctp_hmac *hmac_desc; +const struct sctp_hmac *hmac_desc;struct sctp_chunk *retval;/* Get the first hmac that the peer told us to use */ hmac_desc =sctp_auth_asoc_get_hmac (asoc);if (unlikely (!hmac_desc))
net/sctp/sm_statefuns.c +1 -1
@@ -4359,11 +4359,11 @@ static enum sctp_ierror sctp_sf_authenticate( struct sctp_chunk *chunk) {struct sctp_shared_key *sh_key =NULL ;struct sctp_authhdr *auth_hdr;__u8 *save_digest, *digest; -struct sctp_hmac *hmac; +const struct sctp_hmac *hmac;unsigned int sig_len;__u16 key_id;/* Pull in the auth header, so we can do some more verification */ auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
net/sctp/socket.c +0 -10
@@ -9579,20 +9579,10 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, err =sctp_bind_addr_dup (&newsp->ep->base.bind_addr, &oldsp->ep->base.bind_addr,GFP_KERNEL );if (err)return err; -/* New ep's auth_hmacs should be set if old ep's is set, in case -* that net->sctp.auth_enable has been changed to 0 by users and -* new ep's auth_hmacs couldn't be set in sctp_endpoint_init(). -*/ -if (oldsp->ep->auth_hmacs) { - err =sctp_auth_init_hmacs (newsp->ep,GFP_KERNEL ); -if (err) -return err; - } -sctp_auto_asconf_init (newsp);/* Move any messages in the old socket's receive queue that are for the * peeled off association to the new socket's receive queue. */
Signature · 1 line
2.50.1
PATCH v2 3/3 sctp: Convert cookie authentication to use HMAC-SHA256
In reply to Eric BiggersConvert SCTP cookies to use HMAC-SHA256, instead of the previous choice of the legacy algorithms HMAC-MD5 and HMAC-SHA1. Simplify and optimize the code by using the HMAC-SHA256 library instead of crypto_shash, and by preparing the HMAC key when it is generated instead of per-operation.
This doesn't break compatibility, since the cookie format is an implementation detail, not part of the SCTP protocol itself.
Note that the cookie size doesn't change either. The HMAC field was already 32 bytes, even though previously at most 20 bytes were actually compared. 32 bytes exactly fits an untruncated HMAC-SHA256 value. So, although we could safely truncate the MAC to something slightly shorter, for now just keep the cookie size the same.
I also considered SipHash, but that would generate only 8-byte MACs. An 8-byte MAC *might* suffice here. However, there's quite a lot of information in the SCTP cookies: more than in TCP SYN cookies. So absent an analysis that occasional forgeries of all that information is okay in SCTP, I errored on the side of caution.
Remove HMAC-MD5 and HMAC-SHA1 as options, since the new HMAC-SHA256 option is just better. It's faster as well as more secure. For example, benchmarking on x86_64, cookie authentication is now nearly 3x as fast as the previous default choice and implementation of HMAC-MD5.
Also just make the kernel always support cookie authentication if SCTP is supported at all, rather than making it optional in the build. (It was sort of optional before, but it didn't really work properly. E.g., a kernel with CONFIG_SCTP_COOKIE_HMAC_MD5=n still supported HMAC-MD5 cookie authentication if CONFIG_CRYPTO_HMAC and CONFIG_CRYPTO_MD5 happened to be enabled in the kconfig for other reasons.)
--- Documentation/networking/ip-sysctl.rst | 11 ++--- include/net/netns/sctp.h | 4 +- include/net/sctp/constants.h | 5 +-- include/net/sctp/structs.h | 30 ++++--------- net/sctp/Kconfig | 44 +++++-------------- net/sctp/endpointola.c | 23 +++++----- net/sctp/protocol.c | 11 ++--- net/sctp/sm_make_chunk.c | 58 ++++++++------------------ net/sctp/socket.c | 31 +------------- net/sctp/sysctl.c | 51 ++++++++++------------ 10 files changed, 81 insertions(+), 187 deletions(-)
Documentation/networking/ip-sysctl.rst +4 -7
@@ -3506,20 +3506,17 @@ cookie_preserve_enable - BOOLEAN cookie_hmac_alg - STRING Select the hmac algorithm used when generating the cookie value sent by a listening sctp socket to a connecting client in the INIT-ACK chunk. Valid values are: - * md5 - * sha1 + * sha256 * none - Ability to assign md5 or sha1 as the selected alg is predicated on the - configuration of those algorithms at build time (CONFIG_CRYPTO_MD5 and - CONFIG_CRYPTO_SHA1). + md5 and sha1 are also accepted for backwards compatibility, but cause + sha256 to be selected. - Default: Dependent on configuration. MD5 if available, else SHA1 if - available, else none. + Default: sha256 rcvbuf_policy - INTEGER Determines if the receive buffer is attributed to the socket or to association. SCTP supports the capability to create multiple associations on a single socket. When using this capability, it is
include/net/netns/sctp.h +2 -2
@@ -73,12 +73,12 @@ struct netns_sctp {int max_burst;/* Whether Cookie Preservative is enabled(1) or not(0) */ int cookie_preserve_enable; -/* The namespace default hmac alg */ -char *sctp_hmac_alg; +/* Whether cookie authentication is enabled(1) or not(0) */ +int cookie_auth_enable;/* Valid.Cookie.Life - 60 seconds */ unsigned int valid_cookie_life;/* Delayed SACK timeout 200ms default*/
include/net/sctp/constants.h +2 -3
@@ -294,13 +294,12 @@ enum { SCTP_MAX_GABS = 16 };#define SCTP_DEFAULT_MAXSEGMENT 1500/* MTU size, this is the limit * to which we will raise the P-MTU. */ #define SCTP_DEFAULT_MINSEGMENT 512/* MTU size ... if no mtu disc */ -#define SCTP_SECRET_SIZE 32/* Number of octets in a 256 bits. */ - -#define SCTP_SIGNATURE_SIZE 20/* size of a SLA-1 signature */ +#define SCTP_COOKIE_KEY_SIZE 32/* size of cookie HMAC key */ +#define SCTP_COOKIE_MAC_SIZE 32/* size of HMAC field in cookies */ #define SCTP_COOKIE_MULTIPLE 32/* Pad out our cookie to make our hash * functions simpler to write. */
include/net/sctp/structs.h +7 -23
@@ -30,10 +30,11 @@*/ #ifndef __sctp_structs_h__#define __sctp_structs_h__ +#include <crypto/sha2.h> #include <linux/ktime.h> #include <linux/generic-radix-tree.h> #include <linux/rhashtable-types.h> #include <linux/socket.h> /* linux/in.h needs this!! */ #include <linux/in.h> /* We get struct sockaddr_in. */
@@ -66,11 +67,10 @@ struct sctp_chunk;struct sctp_inq ;struct sctp_outq ;struct sctp_bind_addr ;struct sctp_ulpq ;struct sctp_ep_common ; -struct crypto_shash ;struct sctp_stream ;#include <net/sctp/tsnmap.h> #include <net/sctp/ulpevent.h>
@@ -153,14 +153,10 @@ struct sctp_sock {enum sctp_socket_type type;/* PF_ family specific functions. */ struct sctp_pf *pf; -/* Access to HMAC transform. */ -struct crypto_shash *hmac; -char *sctp_hmac_alg; -/* What is our base endpointer? */ struct sctp_endpoint *ep;struct sctp_bind_bucket *bind_hash;/* Various Socket Options. */
@@ -225,11 +221,12 @@ struct sctp_sock { disable_fragments:1, v4mapped:1, frag_interleave:1, recvrcvinfo:1, recvnxtinfo:1, - data_ready_signalled:1; + data_ready_signalled:1, + cookie_auth_enable:1;atomic_t pd_mode;/* Fields after this point will be skipped on copies, like on accept * and peeloff operations
@@ -333,11 +330,11 @@ struct sctp_cookie { };/* The format of our cookie that we send to our peer. */ struct sctp_signed_cookie { -__u8 signature[SCTP_SECRET_SIZE ]; +__u8 mac[SCTP_COOKIE_MAC_SIZE ];__u32 __pad;/* force sctp_cookie alignment to 64 bits */ struct sctp_cookie c; } __packed;/* This is another convenience type to allocate memory for address
@@ -1305,26 +1302,13 @@ struct sctp_endpoint {* is implemented. */ /* This is really a list of struct sctp_association entries. */ struct list_head asocs; -/* Secret Key: A secret key used by this endpoint to compute -* the MAC. This SHOULD be a cryptographic quality -* random number with a sufficient length. -* Discussion in [RFC1750] can be helpful in -* selection of the key. -*/ -__u8 secret_key[SCTP_SECRET_SIZE ]; - -/* digest: This is a digest of the sctp cookie. This field is -* only used on the receive path when we try to validate -* that the cookie has not been tampered with. We put -* this here so we pre-allocate this once and can re-use -* on every receive. -*/ -__u8 *digest; - +/* Cookie authentication key used by this endpoint */ +struct hmac_sha256_key cookie_auth_key; +/* sendbuf acct. policy. */ __u32 sndbuf_policy;/* rcvbuf acct. policy. */ __u32 rcvbuf_policy;
net/sctp/Kconfig +11 -33
73 lines not on this page · raw message
net/sctp/endpointola.c +12 -11
@@ -33,24 +33,29 @@#include <net/sctp/sm.h> /* Forward declarations for internal helpers. */ static void sctp_endpoint_bh_rcv (struct work_struct *work); +static void gen_cookie_auth_key (struct hmac_sha256_key *key) +{ +u8 raw_key[SCTP_COOKIE_KEY_SIZE ]; + +get_random_bytes (raw_key,sizeof (raw_key)); +hmac_sha256_preparekey (key, raw_key,sizeof (raw_key)); +memzero_explicit (raw_key,sizeof (raw_key)); +} +/* * Initialize the base fields of the endpoint structure. */ static struct sctp_endpoint *sctp_endpoint_init (struct sctp_endpoint *ep,struct sock *sk,gfp_t gfp) {struct net *net =sock_net (sk);struct sctp_shared_key *null_key; - ep->digest =kzalloc (SCTP_SIGNATURE_SIZE , gfp); -if (!ep->digest) -return NULL ; - ep->asconf_enable = net->sctp.addip_enable; ep->auth_enable = net->sctp.auth_enable;if (ep->auth_enable) {if (sctp_auth_init (ep, gfp)) goto nomem;
@@ -88,12 +93,12 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,sock_set_flag (sk,SOCK_USE_WRITE_QUEUE );/* Get the receive buffer policy for this endpoint */ ep->rcvbuf_policy = net->sctp.rcvbuf_policy; -/* Initialize the secret key used with cookie. */ -get_random_bytes (ep->secret_key,sizeof (ep->secret_key)); +/* Generate the cookie authentication key. */ +gen_cookie_auth_key (&ep->cookie_auth_key);/* SCTP-AUTH extensions*/ INIT_LIST_HEAD (&ep->endpoint_shared_keys); null_key =sctp_auth_shkey_create (0 , gfp);if (!null_key)
@@ -116,11 +121,10 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,return ep; nomem_shkey:sctp_auth_free (ep); nomem: -kfree (ep->digest);return NULL ; }/* Create a sctp_endpoint with all that boring stuff initialized.
@@ -203,24 +207,21 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)if (unlikely (!ep->base.dead)) {WARN (1 ,"Attempt to destroy undead endpoint %p!\n" , ep);return ; } -/* Free the digest buffer */ -kfree (ep->digest); -/* SCTP-AUTH: Free up AUTH releated data such as shared keys * chunks and hmacs arrays that were allocated */ sctp_auth_destroy_keys (&ep->endpoint_shared_keys);sctp_auth_free (ep);/* Cleanup. */ sctp_inq_free (&ep->base.inqueue);sctp_bind_addr_free (&ep->base.bind_addr); -memset (ep->secret_key,0 ,sizeof (ep->secret_key)); +memzero_explicit (&ep->cookie_auth_key,sizeof (ep->cookie_auth_key)); sk = ep->base.sk;/* Remove and free the port */ if (sctp_sk (sk)->bind_hash)sctp_put_port (sk);
net/sctp/protocol.c +3 -8
@@ -1332,18 +1332,13 @@ static int __net_init sctp_defaults_init(struct net *net) net->sctp.valid_cookie_life =SCTP_DEFAULT_COOKIE_LIFE ;/* Whether Cookie Preservative is enabled(1) or not(0) */ net->sctp.cookie_preserve_enable =1 ; -/* Default sctp sockets to use md5 as their hmac alg */ -#if defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_MD5 ) - net->sctp.sctp_hmac_alg ="md5" ; -#elif defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_SHA1 ) - net->sctp.sctp_hmac_alg ="sha1" ; -#else - net->sctp.sctp_hmac_alg =NULL ; -#endif +/* Whether cookie authentication is enabled(1) or not(0) */ + net->sctp.cookie_auth_enable = + !IS_ENABLED (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_NONE );/* Max.Burst - 4 */ net->sctp.max_burst =SCTP_DEFAULT_MAX_BURST ;/* Disable of Primary Path Switchover by default */
net/sctp/sm_make_chunk.c +18 -40
116 lines not on this page · raw message
net/sctp/socket.c +1 -30
@@ -35,11 +35,10 @@* Kevin Gao <[email protected]> */ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <crypto/hash.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/wait.h> #include <linux/time.h> #include <linux/sched/signal.h>
@@ -4985,11 +4984,11 @@ static int sctp_init_sock(struct sock *sk) sp->default_timetolive =0 ; sp->default_rcv_context =0 ; sp->max_burst = net->sctp.max_burst; - sp->sctp_hmac_alg = net->sctp.sctp_hmac_alg; + sp->cookie_auth_enable = net->sctp.cookie_auth_enable;/* Initialize default setup parameters. These parameters * can be modified with the SCTP_INITMSG socket option or * overridden by the SCTP_INIT CMSG. */
@@ -5077,12 +5076,10 @@ static int sctp_init_sock(struct sock *sk)*/ sp->ep =sctp_endpoint_new (sk,GFP_KERNEL );if (!sp->ep)return -ENOMEM ; - sp->hmac =NULL ; - sk->sk_destruct = sctp_destruct_sock;SCTP_DBG_OBJCNT_INC (sock);sk_sockets_allocated_inc (sk);
@@ -5115,22 +5112,12 @@ static void sctp_destroy_sock(struct sock *sk)sctp_endpoint_free (sp->ep);sk_sockets_allocated_dec (sk);sock_prot_inuse_add (sock_net (sk), sk->sk_prot,-1 ); } -/* Triggered when there are no references on the socket anymore */ -static void sctp_destruct_common (struct sock *sk) -{ -struct sctp_sock *sp =sctp_sk (sk); - -/* Free up the HMAC transform. */ -crypto_free_shash (sp->hmac); -} -static void sctp_destruct_sock (struct sock *sk) { -sctp_destruct_common (sk);inet_sock_destruct (sk); }/* API 4.1.7 shutdown() - TCP Style Syntax * int shutdown(int socket, int how);
@@ -8528,26 +8515,12 @@ static int sctp_get_port(struct sock *sk, unsigned short snum)*/ static int sctp_listen_start (struct sock *sk,int backlog) {struct sctp_sock *sp =sctp_sk (sk);struct sctp_endpoint *ep = sp->ep; -struct crypto_shash *tfm =NULL ; -char alg[32 ];int err; -/* Allocate HMAC for generating cookie. */ -if (!sp->hmac && sp->sctp_hmac_alg) { -sprintf (alg,"hmac(%s)" , sp->sctp_hmac_alg); - tfm =crypto_alloc_shash (alg,0 ,0 ); -if (IS_ERR (tfm)) { -net_info_ratelimited ("failed to load transform for %s: %ld\n" , - sp->sctp_hmac_alg,PTR_ERR (tfm)); -return -ENOSYS ; - } -sctp_sk (sk)->hmac = tfm; - } -/* * If a bind() or sctp_bindx() is not called prior to a listen() * call that allows new associations to be accepted, the system * picks an ephemeral port and will choose an address set equivalent * to binding with a wildcard address.
@@ -9559,11 +9532,10 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,/* Restore the ep value that was overwritten with the above structure * copy. */ newsp->ep = newep; - newsp->hmac =NULL ;/* Hook this new socket in to the bind_hash list. */ head = &sctp_port_hashtable[sctp_phashfn (sock_net (oldsk),inet_sk (oldsk)->inet_num)];spin_lock_bh (&head->lock);
@@ -9711,11 +9683,10 @@ struct proto sctp_prot = {#if IS_ENABLED (CONFIG_IPV6 )static void sctp_v6_destruct_sock (struct sock *sk) { -sctp_destruct_common (sk);inet6_sock_destruct (sk); }static int sctp_v6_init_sock (struct sock *sk) {
net/sctp/sysctl.c +21 -30
82 lines not on this page · raw message
Signature · 1 line
2.50.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
net/sctp/sysctl.c static struct ctl_table sctp_net_table[] = { · line 421
Quoted 6 lines · On Tue, 12 Aug 2025 21:01:21 -0700 Eric Biggers wrote:
net/sctp/sysctl.c +6
-0+if (net->sctp.cookie_auth_enable) + tbl.data = (char *)"sha256" ; +else + tbl.data = (char *)"none" ; + tbl.maxlen =strlen (tbl.data); +return proc_dostring (&tbl,0 , buffer, lenp, ppos);
I wonder if someone out there expects to read back what they wrote, but let us find out.
It'd be great to get an ack / review from SCTP maintainers, otherwise we'll apply by Monday..
Xin Long
maintainerRe: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 11 lines · Jakub Kicinski
net/sctp/sysctl.c static struct ctl_table sctp_net_table[] = { · line 421
Quoted 6 lines · On Tue, 12 Aug 2025 21:01:21 -0700 Eric Biggers wrote:
net/sctp/sysctl.c +6
-0+if (net->sctp.cookie_auth_enable) + tbl.data = (char *)"sha256" ; +else + tbl.data = (char *)"none" ; + tbl.maxlen =strlen (tbl.data); +return proc_dostring (&tbl,0 , buffer, lenp, ppos);I wonder if someone out there expects to read back what they wrote, but let us find out.
I feel it's a bit weird to have:
# sysctl net.sctp.cookie_hmac_alg="md5" net.sctp.cookie_hmac_alg = md5 # sysctl net.sctp.cookie_hmac_alg net.sctp.cookie_hmac_alg = sha256
This patch deprecates md5 and sha1 use there.
So generally, for situations like this, should we also issue a warning, or just fail it?
Paolo, what do you think?
Quoted 3 lines
It'd be great to get an ack / review from SCTP maintainers, otherwise we'll apply by Monday..
Other than that, LGTM.
Sorry for the late reply, I was running some SCTP-auth related tests against the patchset.
Re: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 23 lines · Xin Long
Quoted 11 lines · Jakub Kicinski
Review
Quoted 6 lines · On Tue, 12 Aug 2025 21:01:21 -0700 Eric Biggers wrote:
(quoted diff) +6
-0+ if (net->sctp.cookie_auth_enable) + tbl.data = (char *)"sha256"; + else + tbl.data = (char *)"none"; + tbl.maxlen = strlen(tbl.data); + return proc_dostring(&tbl, 0, buffer, lenp, ppos);I wonder if someone out there expects to read back what they wrote, but let us find out.
I feel it's a bit weird to have:
# sysctl net.sctp.cookie_hmac_alg="md5" net.sctp.cookie_hmac_alg = md5 # sysctl net.sctp.cookie_hmac_alg net.sctp.cookie_hmac_alg = sha256This patch deprecates md5 and sha1 use there.
So generally, for situations like this, should we also issue a warning, or just fail it?
Quoted 8 lines
Paolo, what do you think?
Quoted 3 lines
It'd be great to get an ack / review from SCTP maintainers, otherwise we'll apply by Monday..
Other than that, LGTM.
Sorry for the late reply, I was running some SCTP-auth related tests against the patchset.
Ideally we'd just fail the write and remove the last mentions of md5 and sha1 from the code. But I'm concerned there could be a case where userspace is enabling cookie authentication by setting cookie_hmac_alg=md5 or cookie_hmac_alg=sha1, and by just failing the write the system would end up with cookie authentication not enabled.
It would have been nice if this sysctl had just been a boolean toggle.
A deprecation warning might be a good idea. How about the following on top of this patch:
net/sctp/sysctl.c +11 -3
@@ -399,20 +399,28 @@ static int proc_sctp_do_hmac_alg(const struct ctl_table *ctl, int write, tbl.data = tmp; tbl.maxlen =sizeof (tmp) -1 ; ret =proc_dostring (&tbl,1 , buffer, lenp, ppos);if (ret)return ret; -if (!strcmp (tmp,"sha256" ) || -/* for backwards compatibility */ - !strcmp (tmp,"md5" ) || !strcmp (tmp,"sha1" )) { +if (!strcmp (tmp,"sha256" )) { net->sctp.cookie_auth_enable =1 ;return 0 ; }if (!strcmp (tmp,"none" )) { net->sctp.cookie_auth_enable =0 ;return 0 ; } +/* +* Accept md5 and sha1 for backwards compatibility, but treat +* them simply as requests to enable cookie authentication. +*/ +if (!strcmp (tmp,"md5" ) || !strcmp (tmp,"sha1" )) { +pr_warn_once ("net.sctp.cookie_hmac_alg=%s is deprecated. Use net.sctp.cookie_hmac_alg=sha256\n" , + tmp); + net->sctp.cookie_auth_enable =1 ; +return 0 ; + }return -EINVAL ; }if (net->sctp.cookie_auth_enable) tbl.data = (char *)"sha256" ;else
Jakub Kicinski
maintainerRe: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 12 lines · On Fri, 15 Aug 2025 14:50:09 -0700 Eric Biggers wrote:
Quoted 5 lines
Quoted 2 lines
It'd be great to get an ack / review from SCTP maintainers, otherwise we'll apply by Monday..
Other than that, LGTM.
Sorry for the late reply, I was running some SCTP-auth related tests against the patchset.Ideally we'd just fail the write and remove the last mentions of md5 and sha1 from the code. But I'm concerned there could be a case where userspace is enabling cookie authentication by setting cookie_hmac_alg=md5 or cookie_hmac_alg=sha1, and by just failing the write the system would end up with cookie authentication not enabled.
Quoted 4 lines
It would have been nice if this sysctl had just been a boolean toggle.
A deprecation warning might be a good idea. How about the following on top of this patch:
No strong opinion but I find the deprecation warnings futile. Chances are we'll be printing this until the end of time. Either someone hard-cares and we'll need to revert, or nobody does and we can deprecate today.
Xin Long
maintainerRe: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 16 lines · Jakub Kicinski
Quoted 14 lines · On Fri, 15 Aug 2025 14:50:09 -0700 Eric Biggers wrote:
Quoted 5 lines
Quoted 2 lines
It'd be great to get an ack / review from SCTP maintainers, otherwise we'll apply by Monday..
Other than that, LGTM.
Sorry for the late reply, I was running some SCTP-auth related tests against the patchset.Ideally we'd just fail the write and remove the last mentions of md5 and sha1 from the code. But I'm concerned there could be a case where userspace is enabling cookie authentication by setting cookie_hmac_alg=md5 or cookie_hmac_alg=sha1, and by just failing the write the system would end up with cookie authentication not enabled.
It would have been nice if this sysctl had just been a boolean toggle.
Quoted 7 lines
Quoted 2 lines
A deprecation warning might be a good idea. How about the following on top of this patch:
No strong opinion but I find the deprecation warnings futile. Chances are we'll be printing this until the end of time. Either someone hard-cares and we'll need to revert, or nobody does and we can deprecate today.
Reviewing past network sysctl changes, several commits have simply removed or renamed parameters:
4a7f60094411 ("tcp: remove thin_dupack feature")4396e46187ca ("tcp: remove tcp_tw_recycle")d8b81175e412 ("tcp: remove sk_{tr}x_skb_cache")3e0b8f529c10 ("net/ipv6: Expand and rename accept_unsolicited_na to accept_untracked_na")5027d54a9c30 ("net: change accept_ra_min_rtr_lft to affect all RA lifetimes")
It seems to me that if we deprecate something, it's okay to change the sysctls, so I would prefer rejecting writes with md5 or sha1, or even better following Eric’s suggestion and turn this into a simple boolean toggle.
Thanks.
Jakub Kicinski
maintainerRe: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 25 lines · On Sat, 16 Aug 2025 13:15:12 -0400 Xin Long wrote:
Quoted 8 lines
Quoted 8 lines
Ideally we'd just fail the write and remove the last mentions of md5 and sha1 from the code. But I'm concerned there could be a case where userspace is enabling cookie authentication by setting cookie_hmac_alg=md5 or cookie_hmac_alg=sha1, and by just failing the write the system would end up with cookie authentication not enabled.
It would have been nice if this sysctl had just been a boolean toggle.
Quoted 7 lines
Quoted 2 lines
A deprecation warning might be a good idea. How about the following on top of this patch:
No strong opinion but I find the deprecation warnings futile. Chances are we'll be printing this until the end of time. Either someone hard-cares and we'll need to revert, or nobody does and we can deprecate today.
Reviewing past network sysctl changes, several commits have simply removed or renamed parameters:
4a7f60094411("tcp: removethin_dupackfeature")4396e46187ca("tcp: removetcp_tw_recycle")d8b81175e412("tcp: remove sk_{tr}x_skb_cache")3e0b8f529c10("net/ipv6: Expand and renameaccept_unsolicited_natoaccept_untracked_na")5027d54a9c30("net: changeaccept_ra_min_rtr_lftto affect all RA lifetimes")
Quoted 4 lines
It seems to me that if we deprecate something, it's okay to change the sysctls, so I would prefer rejecting writes with md5 or sha1, or even better following Eric’s suggestion and turn this into a simple boolean toggle.
Slight preference towards reject. bool is worse in case we need to revert (if it takes a few releases for the regression report to appear we may have to maintain backward compat with both string and bool formats going forward).
Re: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 31 lines · Jakub Kicinski
Quoted 25 lines · On Sat, 16 Aug 2025 13:15:12 -0400 Xin Long wrote:
Quoted 8 lines
Quoted 8 lines
Ideally we'd just fail the write and remove the last mentions of md5 and sha1 from the code. But I'm concerned there could be a case where userspace is enabling cookie authentication by setting cookie_hmac_alg=md5 or cookie_hmac_alg=sha1, and by just failing the write the system would end up with cookie authentication not enabled.
It would have been nice if this sysctl had just been a boolean toggle.
Quoted 7 lines
Quoted 2 lines
A deprecation warning might be a good idea. How about the following on top of this patch:
No strong opinion but I find the deprecation warnings futile. Chances are we'll be printing this until the end of time. Either someone hard-cares and we'll need to revert, or nobody does and we can deprecate today.
Reviewing past network sysctl changes, several commits have simply removed or renamed parameters:
4a7f60094411("tcp: removethin_dupackfeature")4396e46187ca("tcp: removetcp_tw_recycle")d8b81175e412("tcp: remove sk_{tr}x_skb_cache")3e0b8f529c10("net/ipv6: Expand and renameaccept_unsolicited_natoaccept_untracked_na")5027d54a9c30("net: changeaccept_ra_min_rtr_lftto affect all RA lifetimes")Quoted 4 lines
It seems to me that if we deprecate something, it's okay to change the sysctls, so I would prefer rejecting writes with md5 or sha1, or even better following Eric’s suggestion and turn this into a simple boolean toggle.
Quoted 4 lines
Slight preference towards reject. bool is worse in case we need to revert (if it takes a few releases for the regression report to appear we may have to maintain backward compat with both string and bool formats going forward).
To be clear, by "It would have been nice if this sysctl had just been a boolean toggle", I meant it would have been nice if it had been that way *originally*. I wasn't suggesting making that change now.
It would be safest to continue to honor existing attempts to enable cookie authentication (by writing md5 or sha1), as this patch does.
If you'd prefer that those attempts be rejected instead, I can do that, but how about I do it as a separate patch on top of this one? That way if there's a problem with it, we can just revert that patch, instead of the entire upgrade to the cookie auth.
- Eric
Xin Long
maintainerRe: [PATCH net-next v2 3/3] sctp: Convert cookie authentication to use HMAC-SHA256
Quoted 42 lines · Eric Biggers
Quoted 31 lines · Jakub Kicinski
Quoted 25 lines · On Sat, 16 Aug 2025 13:15:12 -0400 Xin Long wrote:
Quoted 8 lines
Quoted 8 lines
Ideally we'd just fail the write and remove the last mentions of md5 and sha1 from the code. But I'm concerned there could be a case where userspace is enabling cookie authentication by setting cookie_hmac_alg=md5 or cookie_hmac_alg=sha1, and by just failing the write the system would end up with cookie authentication not enabled.
It would have been nice if this sysctl had just been a boolean toggle.
Quoted 7 lines
Quoted 2 lines
A deprecation warning might be a good idea. How about the following on top of this patch:
No strong opinion but I find the deprecation warnings futile. Chances are we'll be printing this until the end of time. Either someone hard-cares and we'll need to revert, or nobody does and we can deprecate today.
Reviewing past network sysctl changes, several commits have simply removed or renamed parameters:
4a7f60094411("tcp: removethin_dupackfeature")4396e46187ca("tcp: removetcp_tw_recycle")d8b81175e412("tcp: remove sk_{tr}x_skb_cache")3e0b8f529c10("net/ipv6: Expand and renameaccept_unsolicited_natoaccept_untracked_na")5027d54a9c30("net: changeaccept_ra_min_rtr_lftto affect all RA lifetimes")Quoted 4 lines
It seems to me that if we deprecate something, it's okay to change the sysctls, so I would prefer rejecting writes with md5 or sha1, or even better following Eric’s suggestion and turn this into a simple boolean toggle.
Quoted 4 lines
Slight preference towards reject. bool is worse in case we need to revert (if it takes a few releases for the regression report to appear we may have to maintain backward compat with both string and bool formats going forward).
To be clear, by "It would have been nice if this sysctl had just been a boolean toggle", I meant it would have been nice if it had been that way *originally*. I wasn't suggesting making that change now.
Quoted 8 lines
It would be safest to continue to honor existing attempts to enable cookie authentication (by writing md5 or sha1), as this patch does.
If you'd prefer that those attempts be rejected instead, I can do that, but how about I do it as a separate patch on top of this one? That way if there's a problem with it, we can just revert that patch, instead of the entire upgrade to the cookie auth.
Sounds good to me.
Thanks.
Quoted 37 lines · Eric Biggers
This series converts SCTP chunk and cookie authentication to use the crypto library API instead of
crypto_shash. This is much simpler (the diffstat should speak for itself), and also faster too. In addition, this series upgrades the cookie authentication to use HMAC-SHA256.I've tested that kernels with this series applied can continue to communicate using SCTP with older ones, in either direction, using any choice of None, HMAC-SHA1, or HMAC-SHA256 chunk authentication.
Changed in v2:
- Added patch which addsCONFIG_CRYPTO_SHA1to some selftests configsEric Biggers (3):
selftests: net: Explicitly enableCONFIG_CRYPTO_SHA1for IPsec
sctp: Use HMAC-SHA1 and HMAC-SHA256 library for chunk authentication
sctp: Convert cookie authentication to use HMAC-SHA256Documentation/networking/ip-sysctl.rst | 11 +- include/net/netns/sctp.h | 4 +- include/net/sctp/auth.h | 17 +- include/net/sctp/constants.h | 9 +- include/net/sctp/structs.h | 35 +--- net/sctp/Kconfig | 47 ++---- net/sctp/auth.c | 166 ++++--------------- net/sctp/chunk.c | 3 +- net/sctp/endpointola.c | 23 +-- net/sctp/protocol.c | 11 +- net/sctp/sm_make_chunk.c | 60 +++---- net/sctp/sm_statefuns.c | 2 +- net/sctp/socket.c | 41 +---- net/sctp/sysctl.c | 51 +++--- tools/testing/selftests/net/config | 1 + tools/testing/selftests/net/netfilter/config | 1 + 16 files changed, 124 insertions(+), 358 deletions(-)
Quoted 4 lines
base-commit:
8f5ae30d69d7543eee0d70083daf4de8fe15d585--
2.50.1