tlshd: Return errnos from QUIC helper functions
Chuck Lever
maintainerPATCH 1/1 tlshd: Return errnos from QUIC helper functions
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that tlshd_quic_serverhello_handshake() expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).
--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)
src/tlshd/server.c +32 -22
@@ -575,45 +575,47 @@ static int tlshd_quic_server_set_x509_session(struct tlshd_quic_conn *conn)return ret; } - ret =gnutls_certificate_allocate_credentials (&cred); -if (ret) + ret = -ENOMEM ; +if (gnutls_certificate_allocate_credentials (&cred) !=GNUTLS_E_SUCCESS ) goto err; - ret =tlshd_server_get_truststore (cred); -if (ret) + ret = -EINVAL ; +if (tlshd_server_get_truststore (cred) !=GNUTLS_E_SUCCESS ) goto err;gnutls_certificate_set_retrieve_function2 (cred, tlshd_x509_retrieve_key_cb);gnutls_certificate_set_verify_function (cred, tlshd_quic_server_x509_verify_function); - ret =gnutls_init (&session,GNUTLS_SERVER |GNUTLS_NO_AUTO_SEND_TICKET | -GNUTLS_ENABLE_EARLY_DATA |GNUTLS_NO_END_OF_EARLY_DATA ); -if (ret) + ret = -ENOMEM ; +if (gnutls_init (&session,GNUTLS_SERVER |GNUTLS_NO_AUTO_SEND_TICKET | +GNUTLS_ENABLE_EARLY_DATA | +GNUTLS_NO_END_OF_EARLY_DATA ) !=GNUTLS_E_SUCCESS ) goto err_cred;if (!tlshd_quic_server_anti_replay) { - ret =gnutls_anti_replay_init (&tlshd_quic_server_anti_replay); -if (ret) +if (gnutls_anti_replay_init (&tlshd_quic_server_anti_replay) !=GNUTLS_E_SUCCESS ) goto err_session;gnutls_anti_replay_set_add_function (tlshd_quic_server_anti_replay, tlshd_quic_server_anti_replay_db_add_func);gnutls_anti_replay_set_ptr (tlshd_quic_server_anti_replay,NULL ); }gnutls_anti_replay_enable (session, tlshd_quic_server_anti_replay); - ret =gnutls_record_set_max_early_data_size (session,0xffffffffu ); -if (ret) + ret = -EINVAL ; +if (gnutls_record_set_max_early_data_size (session, +0xffffffffu ) !=GNUTLS_E_SUCCESS ) goto err_session;gnutls_session_set_ptr (session, conn); ticket_key.data = conn->ticket; ticket_key.size = conn->ticket_len; - ret =gnutls_session_ticket_enable_server (session, &ticket_key); -if (ret) +if (gnutls_session_ticket_enable_server (session, + &ticket_key) !=GNUTLS_E_SUCCESS ) goto err_session;gnutls_handshake_set_hook_function (session,GNUTLS_HANDSHAKE_CLIENT_HELLO ,GNUTLS_HOOK_POST , tlshd_quic_server_alpn_verify); - ret =gnutls_credentials_set (session,GNUTLS_CRD_CERTIFICATE , cred); -if (ret) + ret = -ENOMEM ; +if (gnutls_credentials_set (session,GNUTLS_CRD_CERTIFICATE , + cred) !=GNUTLS_E_SUCCESS ) goto err_session;gnutls_certificate_server_set_request (session, conn->cert_req);
@@ -635,21 +637,29 @@ static int tlshd_quic_server_set_psk_session(struct tlshd_quic_conn *conn) {gnutls_psk_server_credentials_t cred;gnutls_session_t session; -int ret; +int ret, err; - ret =gnutls_psk_allocate_server_credentials (&cred); -if (ret) +switch (gnutls_psk_allocate_server_credentials (&cred)) { +case GNUTLS_E_SUCCESS : +break ; +case GNUTLS_E_MEMORY_ERROR : + ret = -ENOMEM ; goto err; +case GNUTLS_E_INVALID_REQUEST : + ret = -EINVAL ; + goto err; + }gnutls_psk_set_server_credentials_function (cred, tlshd_quic_server_psk_cb); - ret =gnutls_init (&session,GNUTLS_SERVER |GNUTLS_NO_AUTO_SEND_TICKET ); -if (ret) + ret = -ENOMEM ; +if (gnutls_init (&session,GNUTLS_SERVER | +GNUTLS_NO_AUTO_SEND_TICKET ) !=GNUTLS_E_SUCCESS ) goto err_cred;gnutls_session_set_ptr (session, conn);gnutls_handshake_set_hook_function (session,GNUTLS_HANDSHAKE_CLIENT_HELLO ,GNUTLS_HOOK_POST , tlshd_quic_server_alpn_verify); - ret =gnutls_credentials_set (session,GNUTLS_CRD_PSK , cred); -if (ret) +if (gnutls_credentials_set (session,GNUTLS_CRD_PSK , + cred) !=GNUTLS_E_SUCCESS ) goto err_session; conn->is_serv =1 ;
Signature · 1 line
2.51.0
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).
Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)
Xin -
Looks like src/tlshd/quic.c has the same issue with conn->errcode. Callers expect an errno, but internally the utility functions set that field to a GNUTLS_E_ value.
Can you apply this patch, fix up quic.c as well, and then test both and post the fixes here?
Signature · 1 line
Chuck Lever
Quoted 17 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)
Quoted 9 lines
Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?
Sure.
But conn->errcode is used to pass the err to parms->session_status. What does parms->session_status expect? errno or GNUTLS_E_ value? looking at tlshd_start_tls_handshake():
/* Any errors here should default to blocking access: */
parms->session_status = EACCES; <---
switch (ret) {
case GNUTLS_E_CERTIFICATE_ERROR:
case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR:
tlshd_log_cert_verification_error(session);
break;
case -ETIMEDOUT:
tlshd_log_gnutls_error(ret);
parms->session_status = -ret; <----
parms->session_status = tlshd_initialize_ktls(session);It also seems mixed, no?
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.
Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_status contains a positive errno or zero.
Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);
Quoted 1 line
It also seems mixed, no?
The -ETIMEDOUT arm sets session_status to -ret. ret always contains the value -ETIMEDOUT in that arm, so -ret is ETIMEDOUT.
This code comes from commit b010190cfed2 ("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing -ETIMEDOUT directly to tlshd_log_gnutls_error() does seem a little bogus.
Signature · 1 line
Chuck Lever
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);
Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.
Got it. I'm trying to align the QUIC err process with tls13 code.
- tlshd_tls13_client_x509_handshake()
- tlshd_tls13_client_psk_handshake()
- tlshd_tls13_server_x509_handshake()
- tlshd_tls13_server_psk_handshake()
It seems to me that: When gnutls_xxx() returns errs in these functions, it only logs them, and doesn't set any value to parms->session_status, but sets it until tlshd_start_tls_handshake().
So my suggestion is: not touch these functions for QUIC code:
- tlshd_quic_client_set_x509_session()
- tlshd_quic_client_set_psk_session()
- tlshd_quic_server_set_x509_session()
- tlshd_quic_server_set_psk_session()
but change their callers tlshd_quic_client/serverhello_handshake():
@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms)
ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)",
parms->auth_mode);
}- if (ret) {
- conn->errcode = -ret;
- goto out;
+ if (!ret) {
+ tlshd_quic_start_handshake(conn);
+ parms->session_status = conn->errcode;
}
-
- tlshd_quic_start_handshake(conn);
-out:
- parms->session_status = conn->errcode;
tlshd_quic_conn_destroy(conn);and then in tlshd_quic_start_handshake(), keep the code setting conn->errcode = errno, but set conn->errcode = EACCES for all GNUTLS_E_ places.
What do you think?
Thanks.
Quoted 84 lines · Xin Long
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.Got it. I'm trying to align the QUIC err process with tls13 code.
-
tlshd_tls13_client_x509_handshake()
-tlshd_tls13_client_psk_handshake()-
tlshd_tls13_server_x509_handshake()
-tlshd_tls13_server_psk_handshake()It seems to me that: When
gnutls_xxx()returns errs in these functions, it only logs them, and doesn't set any value toparms->session_status, but sets it untiltlshd_start_tls_handshake().So my suggestion is: not touch these functions for QUIC code:
-
tlshd_quic_client_set_x509_session()
-tlshd_quic_client_set_psk_session()-
tlshd_quic_server_set_x509_session()
-tlshd_quic_server_set_psk_session()but change their callers tlshd_quic_client/serverhello_handshake():
Review void tlshd_quic_serverhello_handshake(struct · line 604
Quoted 9 lines
(quoted diff) +1
-3@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms) ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)", parms->auth_mode); } - if (ret) { - conn->errcode = -ret; - goto out; + if (!ret) {
if (ret == GNUTLS_E_SUCCESSS) {is preferred.
Review void tlshd_quic_serverhello_handshake(struct · line 608
Quoted 8 lines
(quoted diff) +2
-4+ tlshd_quic_start_handshake(conn); + parms->session_status = conn->errcode; } - - tlshd_quic_start_handshake(conn); -out: - parms->session_status = conn->errcode; tlshd_quic_conn_destroy(conn);
We usually express the return code checking as
do something
if (error) {
error flow
}That's why the goto is in there. But I'll leave it up to you in the quic code.
Quoted 5 lines
and then in
tlshd_quic_start_handshake(), keep the code settingconn->errcode= errno, but setconn->errcode= EACCES for allGNUTLS_E_places.What do you think?
I think that still mixes the error return values for the internal functions?
The reason I noticed this is I'm trying to add proper Doxygen comments in here. The internal functions need to be consistent about returning either only GNUTLS_E or errno. The documenting comments can't say "returns GNUTLS_E, negative errno, or zero", for example.
Signature · 1 line
Chuck Lever
Quoted 127 lines · Chuck Lever
Quoted 84 lines · Xin Long
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.Got it. I'm trying to align the QUIC err process with tls13 code.
-
tlshd_tls13_client_x509_handshake()
-tlshd_tls13_client_psk_handshake()-
tlshd_tls13_server_x509_handshake()
-tlshd_tls13_server_psk_handshake()It seems to me that: When
gnutls_xxx()returns errs in these functions, it only logs them, and doesn't set any value toparms->session_status, but sets it untiltlshd_start_tls_handshake().So my suggestion is: not touch these functions for QUIC code:
-
tlshd_quic_client_set_x509_session()
-tlshd_quic_client_set_psk_session()-
tlshd_quic_server_set_x509_session()
-tlshd_quic_server_set_psk_session()but change their callers tlshd_quic_client/serverhello_handshake():
Review void tlshd_quic_serverhello_handshake(struct · line 604
Quoted 9 lines
(quoted diff) +1
-3@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms) ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)", parms->auth_mode); } - if (ret) { - conn->errcode = -ret; - goto out; + if (!ret) {if (ret == GNUTLS_E_SUCCESSS) {is preferred.
Review void tlshd_quic_serverhello_handshake(struct · line 608
Quoted 8 lines
(quoted diff) +2
-4+ tlshd_quic_start_handshake(conn); + parms->session_status = conn->errcode; } - - tlshd_quic_start_handshake(conn); -out: - parms->session_status = conn->errcode; tlshd_quic_conn_destroy(conn);We usually express the return code checking as
do something if (error) { error flow }That's why the goto is in there. But I'll leave it up to you in the quic code.
Quoted 5 lines
and then in
tlshd_quic_start_handshake(), keep the code settingconn->errcode= errno, but setconn->errcode= EACCES for allGNUTLS_E_places.What do you think?
Quoted 8 lines
I think that still mixes the error return values for the internal functions?
The reason I noticed this is I'm trying to add proper Doxygen comments in here. The internal functions need to be consistent about returning either only
GNUTLS_Eor errno. The documenting comments can't say "returnsGNUTLS_E, negative errno, or zero", for example.
I see, how about if I do this in all GNUTLS_E returned functions?
src/tlshd/server.c +1 -1
@@ -538,7 +538,7 @@ err:tlshd_x509_server_put_privkey ();tlshd_x509_server_put_certs ();tlshd_log_gnutls_error (ret); -return ret; +return ret ? -EACCES :0 ; }
This way, we will not need to change their callers.
Quoted 150 lines · Xin Long
Quoted 127 lines · Chuck Lever
Quoted 84 lines · Xin Long
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.Got it. I'm trying to align the QUIC err process with tls13 code.
-
tlshd_tls13_client_x509_handshake()
-tlshd_tls13_client_psk_handshake()-
tlshd_tls13_server_x509_handshake()
-tlshd_tls13_server_psk_handshake()It seems to me that: When
gnutls_xxx()returns errs in these functions, it only logs them, and doesn't set any value toparms->session_status, but sets it untiltlshd_start_tls_handshake().So my suggestion is: not touch these functions for QUIC code:
-
tlshd_quic_client_set_x509_session()
-tlshd_quic_client_set_psk_session()-
tlshd_quic_server_set_x509_session()
-tlshd_quic_server_set_psk_session()but change their callers tlshd_quic_client/serverhello_handshake():
Review void tlshd_quic_serverhello_handshake(struct · line 604
Quoted 9 lines
(quoted diff) +1
-3@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms) ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)", parms->auth_mode); } - if (ret) { - conn->errcode = -ret; - goto out; + if (!ret) {if (ret == GNUTLS_E_SUCCESSS) {is preferred.
Review void tlshd_quic_serverhello_handshake(struct · line 608
Quoted 8 lines
(quoted diff) +2
-4+ tlshd_quic_start_handshake(conn); + parms->session_status = conn->errcode; } - - tlshd_quic_start_handshake(conn); -out: - parms->session_status = conn->errcode; tlshd_quic_conn_destroy(conn);We usually express the return code checking as
do something if (error) { error flow }That's why the goto is in there. But I'll leave it up to you in the quic code.
Quoted 5 lines
and then in
tlshd_quic_start_handshake(), keep the code settingconn->errcode= errno, but setconn->errcode= EACCES for allGNUTLS_E_places.What do you think?
Quoted 8 lines
I think that still mixes the error return values for the internal functions?
The reason I noticed this is I'm trying to add proper Doxygen comments in here. The internal functions need to be consistent about returning either only
GNUTLS_Eor errno. The documenting comments can't say "returnsGNUTLS_E, negative errno, or zero", for example.I see, how about if I do this in all
GNUTLS_Ereturned functions?src/tlshd/server.c +1
-1@@ -538,7 +538,7 @@ err:tlshd_x509_server_put_privkey ();tlshd_x509_server_put_certs ();tlshd_log_gnutls_error (ret); -return ret; +return ret ? -EACCES :0 ; }
Quoted 1 line
This way, we will not need to change their callers.
IMHO we want to distinguish between a temporary memory allocation failure, invalid input, and a permanent access failure.
Signature · 1 line
Chuck Lever
Quoted 152 lines · Chuck Lever
Quoted 150 lines · Xin Long
Quoted 127 lines · Chuck Lever
Quoted 84 lines · Xin Long
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.Got it. I'm trying to align the QUIC err process with tls13 code.
-
tlshd_tls13_client_x509_handshake()
-tlshd_tls13_client_psk_handshake()-
tlshd_tls13_server_x509_handshake()
-tlshd_tls13_server_psk_handshake()It seems to me that: When
gnutls_xxx()returns errs in these functions, it only logs them, and doesn't set any value toparms->session_status, but sets it untiltlshd_start_tls_handshake().So my suggestion is: not touch these functions for QUIC code:
-
tlshd_quic_client_set_x509_session()
-tlshd_quic_client_set_psk_session()-
tlshd_quic_server_set_x509_session()
-tlshd_quic_server_set_psk_session()but change their callers tlshd_quic_client/serverhello_handshake():
Review void tlshd_quic_serverhello_handshake(struct · line 604
Quoted 9 lines
(quoted diff) +1
-3@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms) ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)", parms->auth_mode); } - if (ret) { - conn->errcode = -ret; - goto out; + if (!ret) {if (ret == GNUTLS_E_SUCCESSS) {is preferred.
Review void tlshd_quic_serverhello_handshake(struct · line 608
Quoted 8 lines
(quoted diff) +2
-4+ tlshd_quic_start_handshake(conn); + parms->session_status = conn->errcode; } - - tlshd_quic_start_handshake(conn); -out: - parms->session_status = conn->errcode; tlshd_quic_conn_destroy(conn);We usually express the return code checking as
do something if (error) { error flow }That's why the goto is in there. But I'll leave it up to you in the quic code.
Quoted 5 lines
and then in
tlshd_quic_start_handshake(), keep the code settingconn->errcode= errno, but setconn->errcode= EACCES for allGNUTLS_E_places.What do you think?
Quoted 8 lines
I think that still mixes the error return values for the internal functions?
The reason I noticed this is I'm trying to add proper Doxygen comments in here. The internal functions need to be consistent about returning either only
GNUTLS_Eor errno. The documenting comments can't say "returnsGNUTLS_E, negative errno, or zero", for example.I see, how about if I do this in all
GNUTLS_Ereturned functions?src/tlshd/server.c +1
-1@@ -538,7 +538,7 @@ err:tlshd_x509_server_put_privkey ();tlshd_x509_server_put_certs ();tlshd_log_gnutls_error (ret); -return ret; +return ret ? -EACCES :0 ; }
Quoted 5 lines
Quoted 1 line
This way, we will not need to change their callers.
IMHO we want to distinguish between a temporary memory allocation failure, invalid input, and a permanent access failure.
Yes, that will be nice.
However, the tlshd_tls13_* functions don’t currently convert GNUTLS_E values into errno for parms->session_status; they only log them via tlshd_log_gnutls_error(ret).
If we adopt your original patch (which kind of maps GNUTLS_E values to errno and assigns them to parms->session_status) for QUIC, it would make the tlshd_quic_* functions diverge in behavior from the tlshd_tls13_* functions.
Or you think we should make this change in quic first and align tls13 later?
Sorry for the confusion.
Quoted 153 lines · Xin Long
Quoted 152 lines · Chuck Lever
Quoted 150 lines · Xin Long
Quoted 127 lines · Chuck Lever
Quoted 84 lines · Xin Long
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.Got it. I'm trying to align the QUIC err process with tls13 code.
-
tlshd_tls13_client_x509_handshake()
-tlshd_tls13_client_psk_handshake()-
tlshd_tls13_server_x509_handshake()
-tlshd_tls13_server_psk_handshake()It seems to me that: When
gnutls_xxx()returns errs in these functions, it only logs them, and doesn't set any value toparms->session_status, but sets it untiltlshd_start_tls_handshake().So my suggestion is: not touch these functions for QUIC code:
-
tlshd_quic_client_set_x509_session()
-tlshd_quic_client_set_psk_session()-
tlshd_quic_server_set_x509_session()
-tlshd_quic_server_set_psk_session()but change their callers tlshd_quic_client/serverhello_handshake():
Review void tlshd_quic_serverhello_handshake(struct · line 604
Quoted 9 lines
(quoted diff) +1
-3@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms) ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)", parms->auth_mode); } - if (ret) { - conn->errcode = -ret; - goto out; + if (!ret) {if (ret == GNUTLS_E_SUCCESSS) {is preferred.
Review void tlshd_quic_serverhello_handshake(struct · line 608
Quoted 8 lines
(quoted diff) +2
-4+ tlshd_quic_start_handshake(conn); + parms->session_status = conn->errcode; } - - tlshd_quic_start_handshake(conn); -out: - parms->session_status = conn->errcode; tlshd_quic_conn_destroy(conn);We usually express the return code checking as
do something if (error) { error flow }That's why the goto is in there. But I'll leave it up to you in the quic code.
Quoted 5 lines
and then in
tlshd_quic_start_handshake(), keep the code settingconn->errcode= errno, but setconn->errcode= EACCES for allGNUTLS_E_places.What do you think?
Quoted 8 lines
I think that still mixes the error return values for the internal functions?
The reason I noticed this is I'm trying to add proper Doxygen comments in here. The internal functions need to be consistent about returning either only
GNUTLS_Eor errno. The documenting comments can't say "returnsGNUTLS_E, negative errno, or zero", for example.I see, how about if I do this in all
GNUTLS_Ereturned functions?src/tlshd/server.c +1
-1@@ -538,7 +538,7 @@ err:tlshd_x509_server_put_privkey ();tlshd_x509_server_put_certs ();tlshd_log_gnutls_error (ret); -return ret; +return ret ? -EACCES :0 ; }
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
This way, we will not need to change their callers.
IMHO we want to distinguish between a temporary memory allocation failure, invalid input, and a permanent access failure.
Yes, that will be nice.
Perhaps all that matters here is the audit message -- the admin will want to know what kind of error it was. tlshd recovery is just clean up and exit for all three.
Quoted 3 lines
However, the tlshd_tls13_* functions don’t currently convert
GNUTLS_Evalues into errno forparms->session_status; they only log them viatlshd_log_gnutls_error(ret).
The tlshd_tls13_ helpers return void, IIRC, because the session_status field is initialized to EIO, and that gets cleared by tlshd_start_tls_handshake() when the handshake is successful.
The quic helpers return an int... maybe they should return void as well?
Quoted 8 lines
If we adopt your original patch (which kind of maps
GNUTLS_Evalues to errno and assigns them toparms->session_status) for QUIC, it would make the tlshd_quic_* functions diverge in behavior from the tlshd_tls13_* functions.Or you think we should make this change in quic first and align tls13 later?
Sorry for the confusion.
Confusion is mostly because I don't remember how any of this works.
Signature · 1 line
Chuck Lever
Quoted 171 lines · Chuck Lever
Quoted 153 lines · Xin Long
Quoted 152 lines · Chuck Lever
Quoted 150 lines · Xin Long
Quoted 127 lines · Chuck Lever
Quoted 84 lines · Xin Long
Quoted 50 lines · Chuck Lever
Quoted 24 lines · Xin Long
Quoted 23 lines · Chuck Lever
Quoted 8 lines · Chuck Lever
From: Chuck Lever <[email protected]>
Static analysis tools have noticed that
tlshd_quic_serverhello_handshake()expects its helper functions to return errno values, but two of them return GNUTLS_E_* values in most cases. Convert those functions to always return errno values or zero (on success).Quoted 6 lines
Cc Xin Long <[email protected]>Fixes 43a15fed2f33 ("tlshd: add support for quic handshake")Signed-off-by Chuck Lever <[email protected]>--- src/tlshd/server.c | 54 +++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 22 deletions(-)Xin -
Looks like
src/tlshd/quic.chas the same issue withconn->errcode. Callers expect an errno, but internally the utility functions set that field to aGNUTLS_E_value.Quoted 7 lines
Quoted 3 lines
Can you apply this patch, fix up
quic.cas well, and then test both and post the fixes here?Sure.
But
conn->errcodeis used to pass the err toparms->session_status. What doesparms->session_statusexpect? errno orGNUTLS_E_value?
session_statuscontains a positive errno or zero.Quoted 13 lines
looking at
tlshd_start_tls_handshake():/* Any errors here should default to blocking access: */ parms->session_status = EACCES; <--- switch (ret) { case GNUTLS_E_CERTIFICATE_ERROR: case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR: tlshd_log_cert_verification_error(session); break; case -ETIMEDOUT: tlshd_log_gnutls_error(ret); parms->session_status = -ret; <---- parms->session_status = tlshd_initialize_ktls(session);Quoted 9 lines
Quoted 1 line
It also seems mixed, no?
The
-ETIMEDOUTarm setssession_statusto -ret. ret always contains the value-ETIMEDOUTin that arm, so -ret is ETIMEDOUT.This code comes from commit
b010190cfed2("tlshd: Pass ETIMEDOUT from gnutls to kernel"). Passing-ETIMEDOUTdirectly totlshd_log_gnutls_error()does seem a little bogus.Got it. I'm trying to align the QUIC err process with tls13 code.
-
tlshd_tls13_client_x509_handshake()
-tlshd_tls13_client_psk_handshake()-
tlshd_tls13_server_x509_handshake()
-tlshd_tls13_server_psk_handshake()It seems to me that: When
gnutls_xxx()returns errs in these functions, it only logs them, and doesn't set any value toparms->session_status, but sets it untiltlshd_start_tls_handshake().So my suggestion is: not touch these functions for QUIC code:
-
tlshd_quic_client_set_x509_session()
-tlshd_quic_client_set_psk_session()-
tlshd_quic_server_set_x509_session()
-tlshd_quic_server_set_psk_session()but change their callers tlshd_quic_client/serverhello_handshake():
Review void tlshd_quic_serverhello_handshake(struct · line 604
Quoted 9 lines
(quoted diff) +1
-3@@ -601,14 +599,10 @@ void tlshd_quic_serverhello_handshake(struct tlshd_handshake_parms *parms) ret = -EINVAL; tlshd_log_debug("Unrecognized auth mode (%d)", parms->auth_mode); } - if (ret) { - conn->errcode = -ret; - goto out; + if (!ret) {if (ret == GNUTLS_E_SUCCESSS) {is preferred.
Review void tlshd_quic_serverhello_handshake(struct · line 608
Quoted 8 lines
(quoted diff) +2
-4+ tlshd_quic_start_handshake(conn); + parms->session_status = conn->errcode; } - - tlshd_quic_start_handshake(conn); -out: - parms->session_status = conn->errcode; tlshd_quic_conn_destroy(conn);We usually express the return code checking as
do something if (error) { error flow }That's why the goto is in there. But I'll leave it up to you in the quic code.
Quoted 5 lines
and then in
tlshd_quic_start_handshake(), keep the code settingconn->errcode= errno, but setconn->errcode= EACCES for allGNUTLS_E_places.What do you think?
Quoted 8 lines
I think that still mixes the error return values for the internal functions?
The reason I noticed this is I'm trying to add proper Doxygen comments in here. The internal functions need to be consistent about returning either only
GNUTLS_Eor errno. The documenting comments can't say "returnsGNUTLS_E, negative errno, or zero", for example.I see, how about if I do this in all
GNUTLS_Ereturned functions?src/tlshd/server.c +1
-1@@ -538,7 +538,7 @@ err:tlshd_x509_server_put_privkey ();tlshd_x509_server_put_certs ();tlshd_log_gnutls_error (ret); -return ret; +return ret ? -EACCES :0 ; }Quoted 6 lines
Quoted 5 lines
Quoted 1 line
This way, we will not need to change their callers.
IMHO we want to distinguish between a temporary memory allocation failure, invalid input, and a permanent access failure.
Yes, that will be nice.
Perhaps all that matters here is the audit message -- the admin will want to know what kind of error it was. tlshd recovery is just clean up and exit for all three.
Quoted 3 lines
However, the tlshd_tls13_* functions don’t currently convert
GNUTLS_Evalues into errno forparms->session_status; they only log them viatlshd_log_gnutls_error(ret).
Quoted 5 lines
The
tlshd_tls13_helpers return void, IIRC, because thesession_statusfield is initialized to EIO, and that gets cleared bytlshd_start_tls_handshake()when the handshake is successful.The quic helpers return an int... maybe they should return void as well?
Yes, that's also my thought.
Quoted 7 lines
Quoted 7 lines
If we adopt your original patch (which kind of maps
GNUTLS_Evalues to errno and assigns them toparms->session_status) for QUIC, it would make the tlshd_quic_* functions diverge in behavior from the tlshd_tls13_* functions.
Quoted 6 lines
Quoted 3 lines
Or you think we should make this change in quic first and align tls13 later?
Sorry for the confusion.
Confusion is mostly because I don't remember how any of this works.
:D Thank you.