[systemd-devel] Help debugging the access to a hashmap object

Felix Rubio felix at kngnt.org
Fri Jul 14 08:30:57 UTC 2023


Hi everybody,

I am kind of lost, and after some hours giving a look at the issue... 
maybe somebody can give me a hand? I am working on the PR 
https://github.com/systemd/systemd/pull/28339, to provide a way to 
specify literals for the PCRs. As part of this PR I am creating a 
hashmap of hashmaps, in which keys are strings (for the container 
hashmap, the banks: e.g., "sha256", and for the contained hashmap the 
pcr index: e.g., "11").

My problem is that in my test I populate PCR idx 11 and I get the 
following debugging output from hashmap_get (which I call right after 
storing it):

         HM: 0x55b0b5524c88 11 1 1

In which 0x55bc13fc0c88 is the pointer to the bank, 11 is the pcr_idx, 
and 1 and 1 are respectively the hash and idx as found by _hashmap_get  
in hashmap.c:1359 in my branch.

Should I use either a parameter pointer for "11" or a constant, there is 
no difference: it works as expected. So far so good. Now, should I call 
it from another method (in this case, a method I use to generate the 
mask out of all the keys in the map), what I get is quite different:

         HM: 0x55b0b5524c88 11 1 4294967295

in which the idx is 4294967295 ==> IDX_NIL. In both cases, I am calling 
hashmap_get like this:

         TPM2B_DIGEST *v2 = hashmap_get(bank, "11");

First I thought that somehow the value was being deleted, so then I 
decided to print all the keys for that hashmap (expecting to find none, 
as I only set one entry). In this case, what I run, right after setting 
the element and on the other function, is:

         int *k;
         TPM2B_DIGEST *v;
         HASHMAP_FOREACH_KEY(v, k, bank) {
                 _cleanup_free_ char *hex = NULL;
                 hex = hexmem(v->buffer, v->size);
                 fprintf(stderr, "%p %d %s\n", bank, *k, hex);
         }

and what I obtained is:
         IN : 0x55b0b5524c88 1526739249 
3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969
         OUT: 0x55b0b5524c88 892625971 
3d458cfe55cc03ea1f443f1562beec8df51c75e14a9fcf9a7234a13f198e7969

So: I am getting the same pointer for the bank, the hex value for the 
PCR is correct, but the key is different: the entry is not lost, just 
seems to be relocated? How is this possible?

Thank you in advance, if anybody can point out what am I doing wrong... 
:-/.


More information about the systemd-devel mailing list