Should Dame Judi decide well in advance that she wants to give up the role of M, I think that there would be a perfect opportunity for the scripters to plot her assassination in her last Bond movie.
The whole 00 section is assigned, after a tipoff of some sort, to find this mysterious would-be assassin before he/she gets to her.
Does she survive? Does she get killed?
Half way through the movie she IS assassinated! Shock value to the max.
MI6 is in disarray, Tanner steps in temporarily but is unsure of himself.
Time for Bond to kick

.
The hunt steps into warp speed mode to get the assassin.
As I'm not a huge follower of Bond fan fiction, I apologise if this scenario resembles an already existing premise. Someone can elaborate on this as I am also not very imaginative, literally speaking.
But, what an opportunity for the Bond series.