There is no time limit. The aircraft may be holding until the pilot requests a diversion, or declares an emergency, which they will do depending on fuel on board.
I know airliners are required to carry extra fuel in case of rerouting (including a safety margin).
Actually not really. The required fuel is calculated as fuel needed to fly to destination, abort approach there and fly to alternate, certain time holding at alternate, and final fuel reserve.
The contingency fuel, for cases of route changes and holding is at pilot discretion. These rules mean that once the contingency fuel is burnt, the aircraft shall divert to alternate unless it is clear they will be able to land soon.
The pilots are also supposed to declare fuel emergency when landing with the final fuel reserve still on board is no longer ensured with the distance left and any expected delay. And once that happens, the pilots can leave the hold at their discretion.
It should be noted that these days holding usually only occurs when there is some disruption like thunderstorms crossing the airport. In good conditions the flow control mostly takes care of releasing the aircraft for take-off so they arrive at approximately regular intervals and rate that the airport can handle.