-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'in-kernel-support-for-the-tls-alert-protocol'
Chuck Lever says: ==================== In-kernel support for the TLS Alert protocol IMO the kernel doesn't need user space (ie, tlshd) to handle the TLS Alert protocol. Instead, a set of small helper functions can be used to handle sending and receiving TLS Alerts for in-kernel TLS consumers. ==================== Merged on top of a tag in case it's needed in the NFS tree. Link: https://lore.kernel.org/r/169047923706.5241.1181144206068116926.stgit@oracle-102.nfsv4bat.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
- Loading branch information
Showing
13 changed files
with
431 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ | ||
/* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. | ||
* | ||
* TLS Protocol definitions | ||
* | ||
* From https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml | ||
*/ | ||
|
||
#ifndef _TLS_PROT_H | ||
#define _TLS_PROT_H | ||
|
||
/* | ||
* TLS Record protocol: ContentType | ||
*/ | ||
enum { | ||
TLS_RECORD_TYPE_CHANGE_CIPHER_SPEC = 20, | ||
TLS_RECORD_TYPE_ALERT = 21, | ||
TLS_RECORD_TYPE_HANDSHAKE = 22, | ||
TLS_RECORD_TYPE_DATA = 23, | ||
TLS_RECORD_TYPE_HEARTBEAT = 24, | ||
TLS_RECORD_TYPE_TLS12_CID = 25, | ||
TLS_RECORD_TYPE_ACK = 26, | ||
}; | ||
|
||
/* | ||
* TLS Alert protocol: AlertLevel | ||
*/ | ||
enum { | ||
TLS_ALERT_LEVEL_WARNING = 1, | ||
TLS_ALERT_LEVEL_FATAL = 2, | ||
}; | ||
|
||
/* | ||
* TLS Alert protocol: AlertDescription | ||
*/ | ||
enum { | ||
TLS_ALERT_DESC_CLOSE_NOTIFY = 0, | ||
TLS_ALERT_DESC_UNEXPECTED_MESSAGE = 10, | ||
TLS_ALERT_DESC_BAD_RECORD_MAC = 20, | ||
TLS_ALERT_DESC_RECORD_OVERFLOW = 22, | ||
TLS_ALERT_DESC_HANDSHAKE_FAILURE = 40, | ||
TLS_ALERT_DESC_BAD_CERTIFICATE = 42, | ||
TLS_ALERT_DESC_UNSUPPORTED_CERTIFICATE = 43, | ||
TLS_ALERT_DESC_CERTIFICATE_REVOKED = 44, | ||
TLS_ALERT_DESC_CERTIFICATE_EXPIRED = 45, | ||
TLS_ALERT_DESC_CERTIFICATE_UNKNOWN = 46, | ||
TLS_ALERT_DESC_ILLEGAL_PARAMETER = 47, | ||
TLS_ALERT_DESC_UNKNOWN_CA = 48, | ||
TLS_ALERT_DESC_ACCESS_DENIED = 49, | ||
TLS_ALERT_DESC_DECODE_ERROR = 50, | ||
TLS_ALERT_DESC_DECRYPT_ERROR = 51, | ||
TLS_ALERT_DESC_TOO_MANY_CIDS_REQUESTED = 52, | ||
TLS_ALERT_DESC_PROTOCOL_VERSION = 70, | ||
TLS_ALERT_DESC_INSUFFICIENT_SECURITY = 71, | ||
TLS_ALERT_DESC_INTERNAL_ERROR = 80, | ||
TLS_ALERT_DESC_INAPPROPRIATE_FALLBACK = 86, | ||
TLS_ALERT_DESC_USER_CANCELED = 90, | ||
TLS_ALERT_DESC_MISSING_EXTENSION = 109, | ||
TLS_ALERT_DESC_UNSUPPORTED_EXTENSION = 110, | ||
TLS_ALERT_DESC_UNRECOGNIZED_NAME = 112, | ||
TLS_ALERT_DESC_BAD_CERTIFICATE_STATUS_RESPONSE = 113, | ||
TLS_ALERT_DESC_UNKNOWN_PSK_IDENTITY = 115, | ||
TLS_ALERT_DESC_CERTIFICATE_REQUIRED = 116, | ||
TLS_ALERT_DESC_NO_APPLICATION_PROTOCOL = 120, | ||
}; | ||
|
||
#endif /* _TLS_PROT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Handle the TLS Alert protocol | ||
* | ||
* Author: Chuck Lever <chuck.lever@oracle.com> | ||
* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. | ||
*/ | ||
|
||
#include <linux/types.h> | ||
#include <linux/socket.h> | ||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
#include <linux/skbuff.h> | ||
#include <linux/inet.h> | ||
|
||
#include <net/sock.h> | ||
#include <net/handshake.h> | ||
#include <net/tls.h> | ||
#include <net/tls_prot.h> | ||
|
||
#include "handshake.h" | ||
|
||
#include <trace/events/handshake.h> | ||
|
||
/** | ||
* tls_alert_send - send a TLS Alert on a kTLS socket | ||
* @sock: open kTLS socket to send on | ||
* @level: TLS Alert level | ||
* @description: TLS Alert description | ||
* | ||
* Returns zero on success or a negative errno. | ||
*/ | ||
int tls_alert_send(struct socket *sock, u8 level, u8 description) | ||
{ | ||
u8 record_type = TLS_RECORD_TYPE_ALERT; | ||
u8 buf[CMSG_SPACE(sizeof(record_type))]; | ||
struct msghdr msg = { 0 }; | ||
struct cmsghdr *cmsg; | ||
struct kvec iov; | ||
u8 alert[2]; | ||
int ret; | ||
|
||
trace_tls_alert_send(sock->sk, level, description); | ||
|
||
alert[0] = level; | ||
alert[1] = description; | ||
iov.iov_base = alert; | ||
iov.iov_len = sizeof(alert); | ||
|
||
memset(buf, 0, sizeof(buf)); | ||
msg.msg_control = buf; | ||
msg.msg_controllen = sizeof(buf); | ||
msg.msg_flags = MSG_DONTWAIT; | ||
|
||
cmsg = CMSG_FIRSTHDR(&msg); | ||
cmsg->cmsg_level = SOL_TLS; | ||
cmsg->cmsg_type = TLS_SET_RECORD_TYPE; | ||
cmsg->cmsg_len = CMSG_LEN(sizeof(record_type)); | ||
memcpy(CMSG_DATA(cmsg), &record_type, sizeof(record_type)); | ||
|
||
iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, &iov, 1, iov.iov_len); | ||
ret = sock_sendmsg(sock, &msg); | ||
return ret < 0 ? ret : 0; | ||
} | ||
|
||
/** | ||
* tls_get_record_type - Look for TLS RECORD_TYPE information | ||
* @sk: socket (for IP address information) | ||
* @cmsg: incoming message to be parsed | ||
* | ||
* Returns zero or a TLS_RECORD_TYPE value. | ||
*/ | ||
u8 tls_get_record_type(const struct sock *sk, const struct cmsghdr *cmsg) | ||
{ | ||
u8 record_type; | ||
|
||
if (cmsg->cmsg_level != SOL_TLS) | ||
return 0; | ||
if (cmsg->cmsg_type != TLS_GET_RECORD_TYPE) | ||
return 0; | ||
|
||
record_type = *((u8 *)CMSG_DATA(cmsg)); | ||
trace_tls_contenttype(sk, record_type); | ||
return record_type; | ||
} | ||
EXPORT_SYMBOL(tls_get_record_type); | ||
|
||
/** | ||
* tls_alert_recv - Parse TLS Alert messages | ||
* @sk: socket (for IP address information) | ||
* @msg: incoming message to be parsed | ||
* @level: OUT - TLS AlertLevel value | ||
* @description: OUT - TLS AlertDescription value | ||
* | ||
*/ | ||
void tls_alert_recv(const struct sock *sk, const struct msghdr *msg, | ||
u8 *level, u8 *description) | ||
{ | ||
const struct kvec *iov; | ||
u8 *data; | ||
|
||
iov = msg->msg_iter.kvec; | ||
data = iov->iov_base; | ||
*level = data[0]; | ||
*description = data[1]; | ||
|
||
trace_tls_alert_recv(sk, *level, *description); | ||
} | ||
EXPORT_SYMBOL(tls_alert_recv); |
Oops, something went wrong.