From 7bc0560be9c85e92b0643954ce29e25db8255cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 3 Oct 2024 14:42:29 +0100 Subject: [PATCH 1/3] qgs: add space between program name & first arg in usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel P. Berrangé --- QuoteGeneration/quote_wrapper/qgs/server_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QuoteGeneration/quote_wrapper/qgs/server_main.cpp b/QuoteGeneration/quote_wrapper/qgs/server_main.cpp index 478dbfe0..3618b5ad 100644 --- a/QuoteGeneration/quote_wrapper/qgs/server_main.cpp +++ b/QuoteGeneration/quote_wrapper/qgs/server_main.cpp @@ -75,7 +75,7 @@ int main(int argc, const char* argv[]) unsigned long int num_threads = 0; char *endptr = NULL; if (argc > 4) { - cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-n=number_threads]" + cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads]" << endl; exit(1); } @@ -114,7 +114,7 @@ int main(int argc, const char* argv[]) cout << "thread number [" << num_threads << "] found in cmdline" << endl; continue; } else { - cout << "Usage: " << argv[0] << "[--no-daemon] [-p=port_number] [-n=number_threads]" + cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads]" << endl; exit(1); } From fb78693dd58719ce6511ae0902001ef50df93cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Fri, 4 Oct 2024 09:43:17 +0100 Subject: [PATCH 2/3] qgs: protect against format strings in QL log messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sgx_proc_log_report() method takes a format string and var-args. It is unsafe to accept a non-const string from the QL library and pass it to sgx_proc_log_report(), as the log message may contain format strings from user data. Signed-off-by: Daniel P. Berrangé --- QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp b/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp index 77838c31..1e97b586 100644 --- a/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp +++ b/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp @@ -50,10 +50,10 @@ typedef quote3_error_t (*sgx_ql_set_logging_callback_t)(sgx_ql_logging_callback_ void sgx_ql_logging_callback(sgx_ql_log_level_t level, const char *message) { if (level == SGX_QL_LOG_ERROR) { - sgx_proc_log_report(1, message); + sgx_proc_log_report(1, "%s", message); } else if (level == SGX_QL_LOG_INFO) { - sgx_proc_log_report(3, message); + sgx_proc_log_report(3, "%s", message); } } From 7696fbfefd4daf46ff92801530c92e49df6619ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 3 Oct 2024 16:57:35 +0100 Subject: [PATCH 3/3] qgs: add --verbose & --debug parameters to control logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently qgs prints all log messages to syslog or stderr unconditionally, even those at QGS_LOG_LEVEL_INFO. At the same time it hardcodes SGX_QL_LOG_ERROR for the quote provider library making it impossible to debug that part of the code. This adds --verbose and --debug parameters to QGS with the following behaviour * Messages from QGS code at QGS_LOG_LEVEL_INFO are discarded unless --verbose is set. This makes QGS quiet by default, only printing warnings/errors. * Messages from the quote provider library are requested at SGX_QL_LOG_INFO instead of SGX_QL_LOG_ERROR if --debug is set. This output is very volumous, dumping HTTP request and response info, hence putting it behind --debug, instead of enabling it with the former --verbose flag. * Enabling --debug will imply --verbose, so setting both is redundant, albeit harmless Signed-off-by: Daniel P. Berrangé --- QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp | 5 +++++ QuoteGeneration/quote_wrapper/qgs/qgs_log.h | 2 ++ QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp | 8 ++++---- QuoteGeneration/quote_wrapper/qgs/server_main.cpp | 10 ++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp b/QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp index 1cf1e40b..4fdbac34 100644 --- a/QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp +++ b/QuoteGeneration/quote_wrapper/qgs/qgs_log.cpp @@ -36,6 +36,8 @@ #include "qgs_log.h" static bool _nosyslog = false; +bool qgs_debug = false; +bool qgs_verbose = false; void qgs_log_init(void) { @@ -68,6 +70,9 @@ void sgx_proc_log_report(int level, const char *format, ...) // so we can always add newline if (!format || !(*format)) return;//ignore + if (!qgs_verbose && + level == QGS_LOG_LEVEL_INFO) + return;//ignore va_start(ap, format); switch(level){ case QGS_LOG_LEVEL_FATAL: diff --git a/QuoteGeneration/quote_wrapper/qgs/qgs_log.h b/QuoteGeneration/quote_wrapper/qgs/qgs_log.h index 1d7fd747..05d41a44 100644 --- a/QuoteGeneration/quote_wrapper/qgs/qgs_log.h +++ b/QuoteGeneration/quote_wrapper/qgs/qgs_log.h @@ -40,6 +40,8 @@ #ifdef __cplusplus extern "C" { #endif/*__cplusplus*/ + extern bool qgs_debug; + extern bool qgs_verbose; void qgs_log_init(void); void qgs_log_init_ex(bool nosyslog); void qgs_log_fini(void); diff --git a/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp b/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp index 1e97b586..db642f70 100644 --- a/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp +++ b/QuoteGeneration/quote_wrapper/qgs/qgs_ql_logic.cpp @@ -113,8 +113,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs { sgx_ql_set_logging_callback_t ql_set_logging_callback = (sgx_ql_set_logging_callback_t)dlsym(p_handle, "sgx_ql_set_logging_callback"); if (dlerror() == NULL && ql_set_logging_callback) { - // Set log level to SGX_QL_LOG_ERROR - ql_set_logging_callback(sgx_ql_logging_callback, SGX_QL_LOG_ERROR); + ql_set_logging_callback(sgx_ql_logging_callback, + qgs_debug ? SGX_QL_LOG_INFO : SGX_QL_LOG_ERROR); } else { QGS_LOG_WARN("Failed to set logging callback for the quote provider library.\n"); } @@ -355,8 +355,8 @@ namespace intel { namespace sgx { namespace dcap { namespace qgs { sgx_ql_set_logging_callback_t ql_set_logging_callback = (sgx_ql_set_logging_callback_t)dlsym(p_handle, "sgx_ql_set_logging_callback"); if (dlerror() == NULL && ql_set_logging_callback) { - // Set log level to SGX_QL_LOG_ERROR - ql_set_logging_callback(sgx_ql_logging_callback, SGX_QL_LOG_ERROR); + ql_set_logging_callback(sgx_ql_logging_callback, + qgs_debug ? SGX_QL_LOG_INFO : SGX_QL_LOG_ERROR); } else { QGS_LOG_WARN("Failed to set logging callback for the quote provider library.\n"); } diff --git a/QuoteGeneration/quote_wrapper/qgs/server_main.cpp b/QuoteGeneration/quote_wrapper/qgs/server_main.cpp index 3618b5ad..47f6c264 100644 --- a/QuoteGeneration/quote_wrapper/qgs/server_main.cpp +++ b/QuoteGeneration/quote_wrapper/qgs/server_main.cpp @@ -75,7 +75,7 @@ int main(int argc, const char* argv[]) unsigned long int num_threads = 0; char *endptr = NULL; if (argc > 4) { - cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads]" + cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads] [--verbose] [--debug]" << endl; exit(1); } @@ -87,6 +87,12 @@ int main(int argc, const char* argv[]) << endl; no_daemon = true; continue; + } else if (strcmp(argv[i], "--debug") == 0) { + qgs_verbose = qgs_debug = true; + continue; + } else if (strcmp(argv[i], "--verbose") == 0) { + qgs_verbose = true; + continue; } else if (strncmp(argv[i], "-p=", 3 ) == 0) { if (strspn(argv[i] + 3, "0123456789") != strlen(argv[i] + 3)) { cout << "Please input valid port number" << endl; @@ -114,7 +120,7 @@ int main(int argc, const char* argv[]) cout << "thread number [" << num_threads << "] found in cmdline" << endl; continue; } else { - cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads]" + cout << "Usage: " << argv[0] << " [--no-daemon] [-p=port_number] [-n=number_threads] [--verbose] [--debug]" << endl; exit(1); }