Skip to content

Commit

Permalink
ruleset: detect integer overflow of the ID and bail out
Browse files Browse the repository at this point in the history
The check is semantically correct, because some IDs are reserved. Here,
we exploit the fact that the LastID is defined to be max_int-2, so when
we increment _id_next often enough, we will eventually reach the
reserved LastID. If that ID is reached, we bail out to prevent further
damage.

The daemon logs the exception and keeps running. But it appears
dysfunctional, i.e. does not notice new device let alone authorise any.
  • Loading branch information
muelli authored and radosroka committed Jun 3, 2024
1 parent 8ec94ff commit 3672e9f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Library/public/usbguard/RuleSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ namespace usbguard

uint32_t RuleSet::assignID()
{
return _id_next++;
const auto next_id = _id_next + 1;
if (next_id >= Rule::LastID) [[unlikely]]
{
throw std::out_of_range("Rule ID too high");
}
_id_next = next_id;
return next_id;
}

void RuleSet::setWritable()
Expand Down

0 comments on commit 3672e9f

Please sign in to comment.