From 469fece141384e766739f88b4f4ddced6d927a51 Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 13 Jun 2018 12:22:54 +0200 Subject: [PATCH] OpenCL Kernels: Abort session if kernel self-test failed --- docs/changes.txt | 6 ++++++ include/types.h | 10 ++++++++++ src/hashcat.c | 23 +++++++++++++++++++++++ src/selftest.c | 15 +++++++++++++-- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7929e696a..7c9519c38 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -1,5 +1,11 @@ * changes v4.1.0 -> v4.1.1 +## +## Improvements +## + +- OpenCL Kernels: Abort session if kernel self-test failed + ## ## Bugs ## diff --git a/include/types.h b/include/types.h index fc589a1a9..1a5f23ecb 100644 --- a/include/types.h +++ b/include/types.h @@ -155,6 +155,14 @@ typedef enum vendor_id } vendor_id_t; +typedef enum st_status_rc +{ + ST_STATUS_PASSED = 0, + ST_STATUS_FAILED = 1, + ST_STATUS_IGNORED = 2, + +} st_status_t; + typedef enum status_rc { STATUS_INIT = 0, @@ -914,6 +922,8 @@ typedef struct hc_device_param bool skipped; bool skipped_temp; + st_status_t st_status; + u32 sm_major; u32 sm_minor; u32 kernel_exec_timeout; diff --git a/src/hashcat.c b/src/hashcat.c index d7bd672ba..728600443 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -727,6 +727,29 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) hcfree (selftest_threads); + // check for any selftest failures + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + if (opencl_ctx->enabled == false) continue; + + if (user_options->self_test_disable == true) continue; + + hc_device_param_t *device_param = opencl_ctx->devices_param + device_id; + + if (device_param->skipped == true) continue; + + if (device_param->st_status == ST_STATUS_FAILED) + { + event_log_error (hashcat_ctx, "Aborting session due to kernel self-test failure."); + + event_log_warning (hashcat_ctx, "You can use --self-test-disable to override this, but do not report related errors."); + event_log_warning (hashcat_ctx, NULL); + + return -1; + } + } + status_ctx->devices_status = STATUS_INIT; EVENT (EVENT_SELFTEST_FINISHED); diff --git a/src/selftest.c b/src/selftest.c index 43d034541..b76c276f2 100644 --- a/src/selftest.c +++ b/src/selftest.c @@ -519,9 +519,20 @@ void *thread_selftest (void *p) const int rc_selftest = selftest (hashcat_ctx, device_param); - if (rc_selftest == -1) + if (user_options->benchmark == true) { - // we should do something here, tell hashcat main that selftest failed to abort + device_param->st_status = ST_STATUS_IGNORED; + } + else + { + if (rc_selftest == 0) + { + device_param->st_status = ST_STATUS_PASSED; + } + else + { + device_param->st_status = ST_STATUS_FAILED; + } } return NULL;