It's fairly simple to resolve. The ref indicates to the 4th official every time a team is time-wasting. The 4th official adds time into their 'pot'. When we've played 90 mins plus the non-time-wasting time added on, the match ends unless either manager indicates that he wants to use his pot, at which point it is DOUBLED. He can then halt it at any point (for example if his team scores a winning goal). The game ends when both managers use up their pot (or decide not to).
It may sound complicated, but it doesn't have to - the 4th offical just needs two time boards to hold up after he's held up the normal time added board, one for each team. He just then needs to communicate with the ref if a manager wants to use his pot (which will be obvious in most cases - if you're losing, you'll use it. It's only if the team's are drawing that it might be arguable).
It would soon become meaningless anyway - no manager is going to tell their players to waste time if they know the opposition have the CHOICE to add UP TO DOUBLE that amount of time at the end, and can STOP it whenever they want during that time.
Also, imagine how exciting a winning goal in that time would be! In most cases it would literally be the last kick of the game!