Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F106964802
D44364.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D44364.diff
View Options
diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -329,7 +329,18 @@
error = sooptcopyin(sopt, tls, sizeof(*tls), sizeof(*tls));
if (error != 0)
- goto done;
+ return (error);
+
+ if (tls->cipher_key_len < 0 || tls->cipher_key_len > TLS_MAX_PARAM_SIZE)
+ return (EINVAL);
+ if (tls->iv_len < 0 || tls->iv_len > sizeof(((struct ktls_session *)NULL)->params.iv))
+ return (EINVAL);
+ if (tls->auth_key_len < 0 || tls->auth_key_len > TLS_MAX_PARAM_SIZE)
+ return (EINVAL);
+
+ /* All supported algorithms require a cipher key. */
+ if (tls->cipher_key_len == 0)
+ return (EINVAL);
/*
* Now do a deep copy of the variable-length arrays in the struct, so that
@@ -338,23 +349,35 @@
* error paths so that our caller need only worry about outstanding
* allocations existing on successful return.
*/
- cipher_key = malloc(tls->cipher_key_len, M_KTLS, M_WAITOK);
- iv = malloc(tls->iv_len, M_KTLS, M_WAITOK);
- auth_key = malloc(tls->auth_key_len, M_KTLS, M_WAITOK);
- if (sopt->sopt_td != NULL) {
- error = copyin(tls->cipher_key, cipher_key, tls->cipher_key_len);
- if (error != 0)
- goto done;
- error = copyin(tls->iv, iv, tls->iv_len);
- if (error != 0)
- goto done;
- error = copyin(tls->auth_key, auth_key, tls->auth_key_len);
- if (error != 0)
- goto done;
- } else {
- bcopy(tls->cipher_key, cipher_key, tls->cipher_key_len);
- bcopy(tls->iv, iv, tls->iv_len);
- bcopy(tls->auth_key, auth_key, tls->auth_key_len);
+ if (tls->cipher_key_len != 0) {
+ cipher_key = malloc(tls->cipher_key_len, M_KTLS, M_WAITOK);
+ if (sopt->sopt_td != NULL) {
+ error = copyin(tls->cipher_key, cipher_key, tls->cipher_key_len);
+ if (error != 0)
+ goto done;
+ } else {
+ bcopy(tls->cipher_key, cipher_key, tls->cipher_key_len);
+ }
+ }
+ if (tls->iv_len != 0) {
+ iv = malloc(tls->iv_len, M_KTLS, M_WAITOK);
+ if (sopt->sopt_td != NULL) {
+ error = copyin(tls->iv, iv, tls->iv_len);
+ if (error != 0)
+ goto done;
+ } else {
+ bcopy(tls->iv, iv, tls->iv_len);
+ }
+ }
+ if (tls->auth_key_len != 0) {
+ auth_key = malloc(tls->auth_key_len, M_KTLS, M_WAITOK);
+ if (sopt->sopt_td != NULL) {
+ error = copyin(tls->auth_key, auth_key, tls->auth_key_len);
+ if (error != 0)
+ goto done;
+ } else {
+ bcopy(tls->auth_key, auth_key, tls->auth_key_len);
+ }
}
tls->cipher_key = cipher_key;
tls->iv = iv;
@@ -586,16 +609,6 @@
en->tls_vminor > TLS_MINOR_VER_THREE)
return (EINVAL);
- if (en->auth_key_len < 0 || en->auth_key_len > TLS_MAX_PARAM_SIZE)
- return (EINVAL);
- if (en->cipher_key_len < 0 || en->cipher_key_len > TLS_MAX_PARAM_SIZE)
- return (EINVAL);
- if (en->iv_len < 0 || en->iv_len > sizeof(tls->params.iv))
- return (EINVAL);
-
- /* All supported algorithms require a cipher key. */
- if (en->cipher_key_len == 0)
- return (EINVAL);
/* No flags are currently supported. */
if (en->flags != 0)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 9, 4:43 AM (6 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15729609
Default Alt Text
D44364.diff (2 KB)
Attached To
Mode
D44364: ktls: catch invalid parameters earlier
Attached
Detach File
Event Timeline
Log In to Comment