Skip to content

Commit 601590e

Browse files
lxindavem330
authored andcommitted
sctp: add sockopt SCTP_AUTH_DEACTIVATE_KEY
This patch is to add sockopt SCTP_AUTH_DEACTIVATE_KEY, as described in section 8.3.4 of RFC6458. This set option indicates that the application will no longer send user messages using the indicated key identifier. Note that RFC requires that only deactivated keys that are no longer used by an association can be deleted, but for the backward compatibility, it is not to check deactivated when deleting or replacing one sh_key. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3ff547c commit 601590e

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

include/net/sctp/auth.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct sctp_shared_key {
6565
struct sctp_auth_bytes *key;
6666
refcount_t refcnt;
6767
__u16 key_id;
68+
__u8 deactivated;
6869
};
6970

7071
#define key_for_each(__key, __list_head) \
@@ -113,14 +114,13 @@ void sctp_auth_shkey_hold(struct sctp_shared_key *sh_key);
113114
int sctp_auth_ep_add_chunkid(struct sctp_endpoint *ep, __u8 chunk_id);
114115
int sctp_auth_ep_set_hmacs(struct sctp_endpoint *ep,
115116
struct sctp_hmacalgo *hmacs);
116-
int sctp_auth_set_key(struct sctp_endpoint *ep,
117-
struct sctp_association *asoc,
117+
int sctp_auth_set_key(struct sctp_endpoint *ep, struct sctp_association *asoc,
118118
struct sctp_authkey *auth_key);
119119
int sctp_auth_set_active_key(struct sctp_endpoint *ep,
120-
struct sctp_association *asoc,
121-
__u16 key_id);
120+
struct sctp_association *asoc, __u16 key_id);
122121
int sctp_auth_del_key_id(struct sctp_endpoint *ep,
123-
struct sctp_association *asoc,
124-
__u16 key_id);
122+
struct sctp_association *asoc, __u16 key_id);
123+
int sctp_auth_deact_key_id(struct sctp_endpoint *ep,
124+
struct sctp_association *asoc, __u16 key_id);
125125

126126
#endif

include/uapi/linux/sctp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef __s32 sctp_assoc_t;
9999
#define SCTP_RECVRCVINFO 32
100100
#define SCTP_RECVNXTINFO 33
101101
#define SCTP_DEFAULT_SNDINFO 34
102+
#define SCTP_AUTH_DEACTIVATE_KEY 35
102103

103104
/* Internal Socket Options. Some of the sctp library functions are
104105
* implemented using these socket options.

net/sctp/auth.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,11 @@ struct sctp_shared_key *sctp_auth_get_shkey(
449449

450450
/* First search associations set of endpoint pair shared keys */
451451
key_for_each(key, &asoc->endpoint_shared_keys) {
452-
if (key->key_id == key_id)
453-
return key;
452+
if (key->key_id == key_id) {
453+
if (!key->deactivated)
454+
return key;
455+
break;
456+
}
454457
}
455458

456459
return NULL;
@@ -905,7 +908,7 @@ int sctp_auth_set_active_key(struct sctp_endpoint *ep,
905908
}
906909
}
907910

908-
if (!found)
911+
if (!found || key->deactivated)
909912
return -EINVAL;
910913

911914
if (asoc) {
@@ -956,3 +959,40 @@ int sctp_auth_del_key_id(struct sctp_endpoint *ep,
956959

957960
return 0;
958961
}
962+
963+
int sctp_auth_deact_key_id(struct sctp_endpoint *ep,
964+
struct sctp_association *asoc, __u16 key_id)
965+
{
966+
struct sctp_shared_key *key;
967+
struct list_head *sh_keys;
968+
int found = 0;
969+
970+
/* The key identifier MUST NOT be the current active key
971+
* The key identifier MUST correst to an existing key
972+
*/
973+
if (asoc) {
974+
if (asoc->active_key_id == key_id)
975+
return -EINVAL;
976+
977+
sh_keys = &asoc->endpoint_shared_keys;
978+
} else {
979+
if (ep->active_key_id == key_id)
980+
return -EINVAL;
981+
982+
sh_keys = &ep->endpoint_shared_keys;
983+
}
984+
985+
key_for_each(key, sh_keys) {
986+
if (key->key_id == key_id) {
987+
found = 1;
988+
break;
989+
}
990+
}
991+
992+
if (!found)
993+
return -EINVAL;
994+
995+
key->deactivated = 1;
996+
997+
return 0;
998+
}

net/sctp/socket.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,6 +3646,33 @@ static int sctp_setsockopt_del_key(struct sock *sk,
36463646

36473647
}
36483648

3649+
/*
3650+
* 8.3.4 Deactivate a Shared Key (SCTP_AUTH_DEACTIVATE_KEY)
3651+
*
3652+
* This set option will deactivate a shared secret key.
3653+
*/
3654+
static int sctp_setsockopt_deactivate_key(struct sock *sk, char __user *optval,
3655+
unsigned int optlen)
3656+
{
3657+
struct sctp_endpoint *ep = sctp_sk(sk)->ep;
3658+
struct sctp_authkeyid val;
3659+
struct sctp_association *asoc;
3660+
3661+
if (!ep->auth_enable)
3662+
return -EACCES;
3663+
3664+
if (optlen != sizeof(struct sctp_authkeyid))
3665+
return -EINVAL;
3666+
if (copy_from_user(&val, optval, optlen))
3667+
return -EFAULT;
3668+
3669+
asoc = sctp_id2assoc(sk, val.scact_assoc_id);
3670+
if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
3671+
return -EINVAL;
3672+
3673+
return sctp_auth_deact_key_id(ep, asoc, val.scact_keynumber);
3674+
}
3675+
36493676
/*
36503677
* 8.1.23 SCTP_AUTO_ASCONF
36513678
*
@@ -4238,6 +4265,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
42384265
case SCTP_AUTH_DELETE_KEY:
42394266
retval = sctp_setsockopt_del_key(sk, optval, optlen);
42404267
break;
4268+
case SCTP_AUTH_DEACTIVATE_KEY:
4269+
retval = sctp_setsockopt_deactivate_key(sk, optval, optlen);
4270+
break;
42414271
case SCTP_AUTO_ASCONF:
42424272
retval = sctp_setsockopt_auto_asconf(sk, optval, optlen);
42434273
break;
@@ -7212,6 +7242,7 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
72127242
case SCTP_AUTH_KEY:
72137243
case SCTP_AUTH_CHUNK:
72147244
case SCTP_AUTH_DELETE_KEY:
7245+
case SCTP_AUTH_DEACTIVATE_KEY:
72157246
retval = -EOPNOTSUPP;
72167247
break;
72177248
case SCTP_HMAC_IDENT:

0 commit comments

Comments
 (0)