The Highway Code says you shouldn't do it unless you're in slow moving traffic. RAC article here:
https://www.rac.co.uk/drive/advice/legal/undertaking/The problem with undertaking for me is that it reduces options when you need them the most.
If I'm in the middle lane doing 70mph and thinking "I can't pull into the inside because that car is only 30 foot off my bumper", that driver deciding to keep up with me at 70mph or undertaking reduces my outs in the event of a tyre blowout or other incident (e.g. a broken down car or debris in the middle lane ahead).
Where there is a dynamic hard shoulder or all-lane running, options become fewer still and the chance of a problem even higher.
And then there are the lorries on the inside of a 50mph average speed check contraflow undertaking in narrow lanes at 0.25mph more than the outside lane - that's just an accident waiting to happen.
I've also been on the outside lane overtaking somebody who was doing 65mph in the middle lane with an empty inside lane who as I moved to overtake sped up. Not undertaking: just blocking me from moving past and back into the middle lane.
I then had a boy racer come in behind me at 90mph and have to throw the anchor out whilst flashing his lights at me, and my options are basically "hope for the best". We were on a relatively tight corner for a motorway (it's that horrid section of the M60 that runs through Stockport), so deciding to accelerate to get out of this would have meant potentially losing control of the car, and the guy in the middle lane was likely going to pin me there anyway...
For me then - especially in the narrow lanes of UK motorways - it is not just about using middle and outside lanes for passing only, there is a responsibility of the drivers on the inside to allow that to happen and give those around them enough options if they need them, and not doing so should be considered just as much a case of careless driving as undertaking in most other scenarios.