Skip to content

Commit df38f54

Browse files
committed
Fix formatting of cpuid
1 parent f6a03bb commit df38f54

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"configurations": [
33
{
44
"name": "Linux",
5-
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
5+
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
6+
"includePath": ["${workspaceFolder}/include", "${workspaceFolder}/src"]
67
}
78
],
89
"version": 4

include/ccf/pal/attestation_sev_snp.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ QPHfbkH0CyPfhl1jWhJFZasCAwEAAQ==
282282
bool operator==(const CPUID&) const = default;
283283
std::string hex_str() const
284284
{
285-
auto begin = reinterpret_cast<const uint8_t*>(this);
286-
return ccf::ds::to_hex(begin, begin + sizeof(CPUID));
285+
uint8_t buf[sizeof(CPUID)];
286+
memcpy(buf, this, sizeof(CPUID));
287+
std::reverse(buf, buf + sizeof(CPUID)); // fix little endianness of AMD
288+
return ccf::ds::to_hex(buf, buf + sizeof(CPUID));
287289
}
288290
inline uint8_t get_family_id() const
289291
{
@@ -300,6 +302,15 @@ QPHfbkH0CyPfhl1jWhJFZasCAwEAAQ==
300302
CPUID, stepping, base_model, base_family, extended_model, extended_family);
301303
static_assert(
302304
sizeof(CPUID) == sizeof(uint32_t), "Can't cast CPUID to uint32_t");
305+
static CPUID cpuid_from_hex(const std::string& hex_str)
306+
{
307+
CPUID ret;
308+
auto buf_ptr = reinterpret_cast<uint8_t*>(&ret);
309+
ccf::ds::from_hex(
310+
hex_str, buf_ptr, buf_ptr + sizeof(CPUID));
311+
std::reverse(buf_ptr, buf_ptr + sizeof(CPUID)); //fix little endianness of AMD
312+
return ret;
313+
}
303314

304315
union UnionedCPUID
305316
{
@@ -331,13 +342,7 @@ namespace ccf::kv::serialisers
331342

332343
static ccf::pal::snp::CPUID from_serialised(const SerialisedEntry& data)
333344
{
334-
ccf::pal::snp::CPUID ret;
335-
auto buf_ptr = reinterpret_cast<uint8_t*>(&ret);
336-
ccf::ds::from_hex(
337-
std::string(data.data(), data.end()),
338-
buf_ptr,
339-
buf_ptr + sizeof(ccf::pal::snp::CPUID));
340-
return ret;
345+
return ccf::pal::snp::cpuid_from_hex(std::string(data.data(), data.end()));
341346
}
342347
};
343348
}

samples/constitutions/default/actions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,9 @@ const actions = new Map([
11921192
},
11931193
function (args) {
11941194
const cpuid = hexStrToBuf(args.cpuid);
1195-
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].delete(cpuid);
1195+
if ( ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].has(cpuid)) {
1196+
ccf.kv["public:ccf.gov.nodes.snp.tcb_versions"].delete(cpuid);
1197+
}
11961198
},
11971199
),
11981200
],

src/node/rpc/node_frontend.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,8 +1621,6 @@ namespace ccf
16211621
ctx.tx, in.measurement, in.quote_info.format);
16221622
}
16231623

1624-
InternalTablesAccess::trust_static_snp_tcb_version(ctx.tx);
1625-
16261624
switch (in.quote_info.format)
16271625
{
16281626
case QuoteFormat::insecure_virtual:

0 commit comments

Comments
 (0)