Skip to content

Commit

Permalink
mctpd: Cope with devices that don't support Get Endpoint UUID
Browse files Browse the repository at this point in the history
It turns out that we don't allocate peer->uuid in the initial peer setup
path if `Get Endpoint UUID` fails:

https://github.com/CodeConstruct/mctp/blob/858d20362329069ec29dc39011f8b960ed56f8ba/src/mctpd.c#L1918-L1923

That behaviour invalidates the assumption that peer->uuid was always
valid if the peer was valid. For the case where peer->uuid is not valid,
take the path of treating it as an unrecognised device.

Fixes: 7ec2f8d ("mctpd: Add support for endpoint recovery")
Signed-off-by: Andrew Jeffery <[email protected]>
  • Loading branch information
amboar committed Jan 12, 2024
1 parent 3a75f27 commit 60dcd12
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2281,27 +2281,17 @@ peer_endpoint_recover(sd_event_source *s, uint64_t usec, void *userdata)
*/
if (peer->recovery.eid != peer->eid) {
static const uint8_t nil_uuid[16] = {0};
bool uuid_matches_peer = false;
bool uuid_matches_nil = false;
uint8_t uuid[16] = {0};
bool uuid_matches_peer;
bool uuid_matches_nil;
mctp_eid_t new_eid;

rc = query_get_peer_uuid_by_phys(ctx, &peer->phys, uuid);

static_assert(sizeof(uuid) == sizeof(nil_uuid), "Unsynchronized UUID sizes");

/*
* The peer must be published for .Recover to be called, so peer->uuid must
* be valid
*/
assert(peer->uuid != NULL);

/*
* The memory is always valid so the memcmp() isn't unsafe, but they are only
* meaningful if query_get_peer_uuid_by_phys() succeeds
*/
uuid_matches_peer = memcmp(uuid, peer->uuid, sizeof(uuid)) == 0;
uuid_matches_nil = memcmp(uuid, nil_uuid, sizeof(uuid)) == 0;
if (!rc && peer->uuid) {
static_assert(sizeof(uuid) == sizeof(nil_uuid), "Unsynchronized UUID sizes");
uuid_matches_peer = memcmp(uuid, peer->uuid, sizeof(uuid)) == 0;
uuid_matches_nil = memcmp(uuid, nil_uuid, sizeof(uuid)) == 0;
}

if (rc || !uuid_matches_peer ||
(uuid_matches_nil && !MCTPD_RECOVER_NIL_UUID)) {
Expand Down

0 comments on commit 60dcd12

Please sign in to comment.