tpm2-software / tpm2-tools

The source repository for the Trusted Platform Module (TPM2.0) tools
https://tpm2-software.github.io
725 stars 379 forks source link

Tests with master tpm2-tss are failing #2808

Closed gotthardp closed 3 years ago

gotthardp commented 3 years ago

You probably seen master-tss-build-test failing. Based on my investigation it's (at least) due to the test/integration/fapi/fapi-nv-extend.sh, which hangs indefinitely in the first tss2 nvextend so the tests then timeout. The first commit that starts failing seems to be https://github.com/tpm2-software/tpm2-tss/commit/ee241a1a6ea5db3e1187e4cb7ccf0347a3aa7c63, but it's surprisingly quite unrelated to the NVM.

Is anybody hunting this problem, please?

williamcroberts commented 3 years ago

I need to start looking at this. @gotthardp are you seeing this when you run the local test suite or is this only on the CI?

FYI @idesai

gotthardp commented 3 years ago

Both. I see the CI failing and my local test suite is failing too. The investigation I did was based on my local tests. I just assume it may the the same problem as in the CI because the fapi-nv-extend is not listed in the tests executed before the CI timeout.

williamcroberts commented 3 years ago

FYI im on this, hopefully will be resolved shortly

williamcroberts commented 3 years ago

So the stack is:

So for command:

nvextend --nvPath=/nv/Owner/NvExtend --data=/home/wcrobert/workspace/tpm2-tss/extend.data --logData=/home/wcrobert/workspace/tpm2-tss/log.data

It hangs JSON tokenizing the log data

Thread #1 [tss2] 109005 [core: 0] (Suspended : Signal : SIGINT:Interrupt)   
    ifapi_parse_json() at tpm_json_deserialize.c:42 0x7ffff7f55c39  
    ifapi_json_IFAPI_TSS_EVENT_serialize() at ifapi_json_serialize.c:721 0x7ffff7f28b2c 
    ifapi_json_IFAPI_EVENT_UNION_serialize() at ifapi_json_serialize.c:783 0x7ffff7f28e7d   
    ifapi_json_IFAPI_EVENT_serialize() at ifapi_json_serialize.c:826 0x7ffff7f291c8 
    Fapi_NvExtend_Finish() at Fapi_NvExtend.c:420 0x7ffff7ed9e8a    
    Fapi_NvExtend() at Fapi_NvExtend.c:107 0x7ffff7ed863a   
    tss2_tool_onrun() at tss2_nvextend.c:83 0x55555555f3d8  
    main() at tss2_template.c:552 0x55555555a494    
json_object*
ifapi_parse_json(const char *jstring) {
    json_object *jso = NULL;
    enum json_tokener_error jerr;
    struct json_tokener* tok = json_tokener_new();
    int line = 1;
    int line_offset = 0;
    int char_pos;
    jso = json_tokener_parse_ex(tok, jstring, strlen(jstring));
    while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue);
    if (jerr != json_tokener_success) {
        for (char_pos = 0; char_pos <= tok->char_offset; char_pos++) {
            if (jstring[char_pos] == '\n') {
                line++;
                line_offset = 0;
            } else {
                line_offset++;
            }
        }
        LOG_ERROR("Invalid JSON at line %i column %i: %s.", line, line_offset,
                  json_tokener_error_desc(jerr));
        json_tokener_free(tok);
        return NULL;
    } else {
        json_tokener_free(tok);
        return jso;
    }
}

So json_tokener_parse_ex is returning NULL and the json_tokener_get_error is continue, so it's just sitting in that loop.

So I see a few things, the loop should call the json_tokener_parse_ex routine to update the tok object. Additionally, im seeing behavior differences between:

json_tokener_parse_ex: (nil)
json_tokener_parse: 0x55613efeb1f0

Here's a sample program:

#include <stdio.h>
#include <string.h>

#include <json-c/json.h>
#include <json-c/json_tokener.h>
#include <json-c/json_util.h>

int main ()
{
    json_object *jso = NULL;
    struct json_tokener* tok = json_tokener_new();
    const char *jstring = "98765432109876543210";
    jso = json_tokener_parse_ex(tok, jstring, strlen(jstring));
    printf("json_tokener_parse_ex: %p\n", jso);

    jso = json_tokener_parse(jstring);
    printf("json_tokener_parse: %p\n", jso);

    return 0;
}
gcc -o go a.c -ljson-c

So I need to understand why the difference....

williamcroberts commented 3 years ago

If i call json_tokener_parse_ex with -1, it seems to be fine... I wonder if it needs to look at the null byte....

williamcroberts commented 3 years ago

I think I got it fixed:

gotthardp commented 3 years ago

Thank you very much! This solves the issue on my end.

gotthardp commented 3 years ago

And also all tpm2-tools tests are green again with https://github.com/tpm2-software/tpm2-tss/commit/7e3b6a9ec590a0290a512d289cc84062f296acbd.