sctp: Convert cookie authentication to use HMAC-SHA256

Convert 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.)

Acked-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Link: https://patch.msgid.link/20250818205426.30222-5-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Biggers 2025-08-18 13:54:25 -07:00 committed by Jakub Kicinski
parent bf40785fa4
commit 2f3dd6ec90
10 changed files with 80 additions and 188 deletions

View file

@ -3508,16 +3508,13 @@ cookie_hmac_alg - STRING
a listening sctp socket to a connecting client in the INIT-ACK chunk. a listening sctp socket to a connecting client in the INIT-ACK chunk.
Valid values are: Valid values are:
* md5 * sha256
* sha1
* none * none
Ability to assign md5 or sha1 as the selected alg is predicated on the md5 and sha1 are also accepted for backwards compatibility, but cause
configuration of those algorithms at build time (CONFIG_CRYPTO_MD5 and sha256 to be selected.
CONFIG_CRYPTO_SHA1).
Default: Dependent on configuration. MD5 if available, else SHA1 if Default: sha256
available, else none.
rcvbuf_policy - INTEGER rcvbuf_policy - INTEGER
Determines if the receive buffer is attributed to the socket or to Determines if the receive buffer is attributed to the socket or to

View file

@ -75,8 +75,8 @@ struct netns_sctp {
/* Whether Cookie Preservative is enabled(1) or not(0) */ /* Whether Cookie Preservative is enabled(1) or not(0) */
int cookie_preserve_enable; int cookie_preserve_enable;
/* The namespace default hmac alg */ /* Whether cookie authentication is enabled(1) or not(0) */
char *sctp_hmac_alg; int cookie_auth_enable;
/* Valid.Cookie.Life - 60 seconds */ /* Valid.Cookie.Life - 60 seconds */
unsigned int valid_cookie_life; unsigned int valid_cookie_life;

View file

@ -296,9 +296,8 @@ enum { SCTP_MAX_GABS = 16 };
*/ */
#define SCTP_DEFAULT_MINSEGMENT 512 /* MTU size ... if no mtu disc */ #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_COOKIE_KEY_SIZE 32 /* size of cookie HMAC key */
#define SCTP_COOKIE_MAC_SIZE 32 /* size of HMAC field in cookies */
#define SCTP_SIGNATURE_SIZE 20 /* size of a SLA-1 signature */
#define SCTP_COOKIE_MULTIPLE 32 /* Pad out our cookie to make our hash #define SCTP_COOKIE_MULTIPLE 32 /* Pad out our cookie to make our hash
* functions simpler to write. * functions simpler to write.

View file

@ -32,6 +32,7 @@
#ifndef __sctp_structs_h__ #ifndef __sctp_structs_h__
#define __sctp_structs_h__ #define __sctp_structs_h__
#include <crypto/sha2.h>
#include <linux/ktime.h> #include <linux/ktime.h>
#include <linux/generic-radix-tree.h> #include <linux/generic-radix-tree.h>
#include <linux/rhashtable-types.h> #include <linux/rhashtable-types.h>
@ -68,7 +69,6 @@ struct sctp_outq;
struct sctp_bind_addr; struct sctp_bind_addr;
struct sctp_ulpq; struct sctp_ulpq;
struct sctp_ep_common; struct sctp_ep_common;
struct crypto_shash;
struct sctp_stream; struct sctp_stream;
@ -155,10 +155,6 @@ struct sctp_sock {
/* PF_ family specific functions. */ /* PF_ family specific functions. */
struct sctp_pf *pf; struct sctp_pf *pf;
/* Access to HMAC transform. */
struct crypto_shash *hmac;
char *sctp_hmac_alg;
/* What is our base endpointer? */ /* What is our base endpointer? */
struct sctp_endpoint *ep; struct sctp_endpoint *ep;
@ -227,7 +223,8 @@ struct sctp_sock {
frag_interleave:1, frag_interleave:1,
recvrcvinfo:1, recvrcvinfo:1,
recvnxtinfo:1, recvnxtinfo:1,
data_ready_signalled:1; data_ready_signalled:1,
cookie_auth_enable:1;
atomic_t pd_mode; atomic_t pd_mode;
@ -335,7 +332,7 @@ struct sctp_cookie {
/* The format of our cookie that we send to our peer. */ /* The format of our cookie that we send to our peer. */
struct sctp_signed_cookie { struct sctp_signed_cookie {
__u8 signature[SCTP_SECRET_SIZE]; __u8 mac[SCTP_COOKIE_MAC_SIZE];
__u32 __pad; /* force sctp_cookie alignment to 64 bits */ __u32 __pad; /* force sctp_cookie alignment to 64 bits */
struct sctp_cookie c; struct sctp_cookie c;
} __packed; } __packed;
@ -1307,21 +1304,8 @@ struct sctp_endpoint {
/* This is really a list of struct sctp_association entries. */ /* This is really a list of struct sctp_association entries. */
struct list_head asocs; struct list_head asocs;
/* Secret Key: A secret key used by this endpoint to compute /* Cookie authentication key used by this endpoint */
* the MAC. This SHOULD be a cryptographic quality struct hmac_sha256_key cookie_auth_key;
* 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;
/* sendbuf acct. policy. */ /* sendbuf acct. policy. */
__u32 sndbuf_policy; __u32 sndbuf_policy;

View file

@ -49,48 +49,25 @@ config SCTP_DBG_OBJCNT
'cat /proc/net/sctp/sctp_dbg_objcnt' 'cat /proc/net/sctp/sctp_dbg_objcnt'
If unsure, say N If unsure, say N
choice choice
prompt "Default SCTP cookie HMAC encoding" prompt "Default SCTP cookie authentication method"
default SCTP_DEFAULT_COOKIE_HMAC_MD5 default SCTP_DEFAULT_COOKIE_HMAC_SHA256
help help
This option sets the default sctp cookie hmac algorithm This option sets the default SCTP cookie authentication method, for
when in doubt select 'md5' when a method hasn't been explicitly selected via the
net.sctp.cookie_hmac_alg sysctl.
config SCTP_DEFAULT_COOKIE_HMAC_MD5 If unsure, choose the default (HMAC-SHA256).
bool "Enable optional MD5 hmac cookie generation"
help
Enable optional MD5 hmac based SCTP cookie generation
select SCTP_COOKIE_HMAC_MD5
config SCTP_DEFAULT_COOKIE_HMAC_SHA1 config SCTP_DEFAULT_COOKIE_HMAC_SHA256
bool "Enable optional SHA1 hmac cookie generation" bool "HMAC-SHA256"
help
Enable optional SHA1 hmac based SCTP cookie generation
select SCTP_COOKIE_HMAC_SHA1
config SCTP_DEFAULT_COOKIE_HMAC_NONE config SCTP_DEFAULT_COOKIE_HMAC_NONE
bool "Use no hmac alg in SCTP cookie generation" bool "None"
help
Use no hmac algorithm in SCTP cookie generation
endchoice endchoice
config SCTP_COOKIE_HMAC_MD5
bool "Enable optional MD5 hmac cookie generation"
help
Enable optional MD5 hmac based SCTP cookie generation
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
select CRYPTO_HMAC
select CRYPTO_SHA1
config INET_SCTP_DIAG config INET_SCTP_DIAG
depends on INET_DIAG depends on INET_DIAG
def_tristate INET_DIAG def_tristate INET_DIAG

View file

@ -35,6 +35,15 @@
/* Forward declarations for internal helpers. */ /* Forward declarations for internal helpers. */
static void sctp_endpoint_bh_rcv(struct work_struct *work); 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. * Initialize the base fields of the endpoint structure.
*/ */
@ -45,10 +54,6 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct sctp_shared_key *null_key; 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->asconf_enable = net->sctp.addip_enable;
ep->auth_enable = net->sctp.auth_enable; ep->auth_enable = net->sctp.auth_enable;
if (ep->auth_enable) { if (ep->auth_enable) {
@ -90,8 +95,8 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
/* Get the receive buffer policy for this endpoint */ /* Get the receive buffer policy for this endpoint */
ep->rcvbuf_policy = net->sctp.rcvbuf_policy; ep->rcvbuf_policy = net->sctp.rcvbuf_policy;
/* Initialize the secret key used with cookie. */ /* Generate the cookie authentication key. */
get_random_bytes(ep->secret_key, sizeof(ep->secret_key)); gen_cookie_auth_key(&ep->cookie_auth_key);
/* SCTP-AUTH extensions*/ /* SCTP-AUTH extensions*/
INIT_LIST_HEAD(&ep->endpoint_shared_keys); INIT_LIST_HEAD(&ep->endpoint_shared_keys);
@ -118,7 +123,6 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
nomem_shkey: nomem_shkey:
sctp_auth_free(ep); sctp_auth_free(ep);
nomem: nomem:
kfree(ep->digest);
return NULL; return NULL;
} }
@ -205,9 +209,6 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
return; return;
} }
/* Free the digest buffer */
kfree(ep->digest);
/* SCTP-AUTH: Free up AUTH releated data such as shared keys /* SCTP-AUTH: Free up AUTH releated data such as shared keys
* chunks and hmacs arrays that were allocated * chunks and hmacs arrays that were allocated
*/ */
@ -218,7 +219,7 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
sctp_inq_free(&ep->base.inqueue); sctp_inq_free(&ep->base.inqueue);
sctp_bind_addr_free(&ep->base.bind_addr); 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; sk = ep->base.sk;
/* Remove and free the port */ /* Remove and free the port */

View file

@ -1334,14 +1334,9 @@ static int __net_init sctp_defaults_init(struct net *net)
/* Whether Cookie Preservative is enabled(1) or not(0) */ /* Whether Cookie Preservative is enabled(1) or not(0) */
net->sctp.cookie_preserve_enable = 1; net->sctp.cookie_preserve_enable = 1;
/* Default sctp sockets to use md5 as their hmac alg */ /* Whether cookie authentication is enabled(1) or not(0) */
#if defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_MD5) net->sctp.cookie_auth_enable =
net->sctp.sctp_hmac_alg = "md5"; !IS_ENABLED(CONFIG_SCTP_DEFAULT_COOKIE_HMAC_NONE);
#elif defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_SHA1)
net->sctp.sctp_hmac_alg = "sha1";
#else
net->sctp.sctp_hmac_alg = NULL;
#endif
/* Max.Burst - 4 */ /* Max.Burst - 4 */
net->sctp.max_burst = SCTP_DEFAULT_MAX_BURST; net->sctp.max_burst = SCTP_DEFAULT_MAX_BURST;

View file

@ -30,7 +30,6 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <crypto/hash.h>
#include <crypto/utils.h> #include <crypto/utils.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/kernel.h> #include <linux/kernel.h>
@ -1675,8 +1674,10 @@ static struct sctp_cookie_param *sctp_pack_cookie(
* out on the network. * out on the network.
*/ */
retval = kzalloc(*cookie_len, GFP_ATOMIC); retval = kzalloc(*cookie_len, GFP_ATOMIC);
if (!retval) if (!retval) {
goto nodata; *cookie_len = 0;
return NULL;
}
cookie = (struct sctp_signed_cookie *) retval->body; cookie = (struct sctp_signed_cookie *) retval->body;
@ -1707,26 +1708,14 @@ static struct sctp_cookie_param *sctp_pack_cookie(
memcpy((__u8 *)(cookie + 1) + memcpy((__u8 *)(cookie + 1) +
ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len); ntohs(init_chunk->chunk_hdr->length), raw_addrs, addrs_len);
if (sctp_sk(ep->base.sk)->hmac) { /* Sign the cookie, if cookie authentication is enabled. */
struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac; if (sctp_sk(ep->base.sk)->cookie_auth_enable) {
int err; static_assert(sizeof(cookie->mac) == SHA256_DIGEST_SIZE);
hmac_sha256(&ep->cookie_auth_key, (const u8 *)&cookie->c,
/* Sign the message. */ bodysize, cookie->mac);
err = crypto_shash_setkey(tfm, ep->secret_key,
sizeof(ep->secret_key)) ?:
crypto_shash_tfm_digest(tfm, (u8 *)&cookie->c, bodysize,
cookie->signature);
if (err)
goto free_cookie;
} }
return retval; return retval;
free_cookie:
kfree(retval);
nodata:
*cookie_len = 0;
return NULL;
} }
/* Unpack the cookie from COOKIE ECHO chunk, recreating the association. */ /* Unpack the cookie from COOKIE ECHO chunk, recreating the association. */
@ -1741,7 +1730,6 @@ struct sctp_association *sctp_unpack_cookie(
struct sctp_signed_cookie *cookie; struct sctp_signed_cookie *cookie;
struct sk_buff *skb = chunk->skb; struct sk_buff *skb = chunk->skb;
struct sctp_cookie *bear_cookie; struct sctp_cookie *bear_cookie;
__u8 *digest = ep->digest;
enum sctp_scope scope; enum sctp_scope scope;
unsigned int len; unsigned int len;
ktime_t kt; ktime_t kt;
@ -1771,30 +1759,19 @@ struct sctp_association *sctp_unpack_cookie(
cookie = chunk->subh.cookie_hdr; cookie = chunk->subh.cookie_hdr;
bear_cookie = &cookie->c; bear_cookie = &cookie->c;
if (!sctp_sk(ep->base.sk)->hmac) /* Verify the cookie's MAC, if cookie authentication is enabled. */
goto no_hmac; if (sctp_sk(ep->base.sk)->cookie_auth_enable) {
u8 mac[SHA256_DIGEST_SIZE];
/* Check the signature. */ hmac_sha256(&ep->cookie_auth_key, (const u8 *)bear_cookie,
{ bodysize, mac);
struct crypto_shash *tfm = sctp_sk(ep->base.sk)->hmac; static_assert(sizeof(cookie->mac) == sizeof(mac));
int err; if (crypto_memneq(mac, cookie->mac, sizeof(mac))) {
*error = -SCTP_IERROR_BAD_SIG;
err = crypto_shash_setkey(tfm, ep->secret_key,
sizeof(ep->secret_key)) ?:
crypto_shash_tfm_digest(tfm, (u8 *)bear_cookie, bodysize,
digest);
if (err) {
*error = -SCTP_IERROR_NOMEM;
goto fail; goto fail;
} }
} }
if (crypto_memneq(digest, cookie->signature, SCTP_SIGNATURE_SIZE)) {
*error = -SCTP_IERROR_BAD_SIG;
goto fail;
}
no_hmac:
/* IG Section 2.35.2: /* IG Section 2.35.2:
* 3) Compare the port numbers and the verification tag contained * 3) Compare the port numbers and the verification tag contained
* within the COOKIE ECHO chunk to the actual port numbers and the * within the COOKIE ECHO chunk to the actual port numbers and the

View file

@ -37,7 +37,6 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <crypto/hash.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/wait.h> #include <linux/wait.h>
@ -4987,7 +4986,7 @@ static int sctp_init_sock(struct sock *sk)
sp->default_rcv_context = 0; sp->default_rcv_context = 0;
sp->max_burst = net->sctp.max_burst; 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 /* Initialize default setup parameters. These parameters
* can be modified with the SCTP_INITMSG socket option or * can be modified with the SCTP_INITMSG socket option or
@ -5079,8 +5078,6 @@ static int sctp_init_sock(struct sock *sk)
if (!sp->ep) if (!sp->ep)
return -ENOMEM; return -ENOMEM;
sp->hmac = NULL;
sk->sk_destruct = sctp_destruct_sock; sk->sk_destruct = sctp_destruct_sock;
SCTP_DBG_OBJCNT_INC(sock); SCTP_DBG_OBJCNT_INC(sock);
@ -5117,18 +5114,8 @@ static void sctp_destroy_sock(struct sock *sk)
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 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) static void sctp_destruct_sock(struct sock *sk)
{ {
sctp_destruct_common(sk);
inet_sock_destruct(sk); inet_sock_destruct(sk);
} }
@ -8530,22 +8517,8 @@ static int sctp_listen_start(struct sock *sk, int backlog)
{ {
struct sctp_sock *sp = sctp_sk(sk); struct sctp_sock *sp = sctp_sk(sk);
struct sctp_endpoint *ep = sp->ep; struct sctp_endpoint *ep = sp->ep;
struct crypto_shash *tfm = NULL;
char alg[32];
int err; 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() * If a bind() or sctp_bindx() is not called prior to a listen()
* call that allows new associations to be accepted, the system * call that allows new associations to be accepted, the system
@ -9561,7 +9534,6 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
* copy. * copy.
*/ */
newsp->ep = newep; newsp->ep = newep;
newsp->hmac = NULL;
/* Hook this new socket in to the bind_hash list. */ /* Hook this new socket in to the bind_hash list. */
head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk), head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk),
@ -9713,7 +9685,6 @@ struct proto sctp_prot = {
static void sctp_v6_destruct_sock(struct sock *sk) static void sctp_v6_destruct_sock(struct sock *sk)
{ {
sctp_destruct_common(sk);
inet6_sock_destruct(sk); inet6_sock_destruct(sk);
} }

View file

@ -174,7 +174,7 @@ static struct ctl_table sctp_net_table[] = {
}, },
{ {
.procname = "cookie_hmac_alg", .procname = "cookie_hmac_alg",
.data = &init_net.sctp.sctp_hmac_alg, .data = &init_net.sctp.cookie_auth_enable,
.maxlen = 8, .maxlen = 8,
.mode = 0644, .mode = 0644,
.proc_handler = proc_sctp_do_hmac_alg, .proc_handler = proc_sctp_do_hmac_alg,
@ -388,10 +388,8 @@ static int proc_sctp_do_hmac_alg(const struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos) void *buffer, size_t *lenp, loff_t *ppos)
{ {
struct net *net = container_of(ctl->data, struct net, struct net *net = container_of(ctl->data, struct net,
sctp.sctp_hmac_alg); sctp.cookie_auth_enable);
struct ctl_table tbl; struct ctl_table tbl;
bool changed = false;
char *none = "none";
char tmp[8] = {0}; char tmp[8] = {0};
int ret; int ret;
@ -399,35 +397,28 @@ static int proc_sctp_do_hmac_alg(const struct ctl_table *ctl, int write,
if (write) { if (write) {
tbl.data = tmp; tbl.data = tmp;
tbl.maxlen = sizeof(tmp); tbl.maxlen = sizeof(tmp) - 1;
} else { ret = proc_dostring(&tbl, 1, buffer, lenp, ppos);
tbl.data = net->sctp.sctp_hmac_alg ? : none; if (ret)
tbl.maxlen = strlen(tbl.data); return ret;
if (!strcmp(tmp, "sha256") ||
/* for backwards compatibility */
!strcmp(tmp, "md5") || !strcmp(tmp, "sha1")) {
net->sctp.cookie_auth_enable = 1;
return 0;
}
if (!strcmp(tmp, "none")) {
net->sctp.cookie_auth_enable = 0;
return 0;
}
return -EINVAL;
} }
if (net->sctp.cookie_auth_enable)
ret = proc_dostring(&tbl, write, buffer, lenp, ppos); tbl.data = (char *)"sha256";
if (write && ret == 0) { else
#ifdef CONFIG_CRYPTO_MD5 tbl.data = (char *)"none";
if (!strncmp(tmp, "md5", 3)) { tbl.maxlen = strlen(tbl.data);
net->sctp.sctp_hmac_alg = "md5"; return proc_dostring(&tbl, 0, buffer, lenp, ppos);
changed = true;
}
#endif
#ifdef CONFIG_CRYPTO_SHA1
if (!strncmp(tmp, "sha1", 4)) {
net->sctp.sctp_hmac_alg = "sha1";
changed = true;
}
#endif
if (!strncmp(tmp, "none", 4)) {
net->sctp.sctp_hmac_alg = NULL;
changed = true;
}
if (!changed)
ret = -EINVAL;
}
return ret;
} }
static int proc_sctp_do_rto_min(const struct ctl_table *ctl, int write, static int proc_sctp_do_rto_min(const struct ctl_table *ctl, int write,