For the reasons you outline above (among others), undertaking in itself is not considered an offence under the Road Traffic Act.
Motorway undertaking is actually not illegal, there is no longer an offense called "undertaking". It is a practice that is advised against only under the Highway Code, but do not confuse the highway code with the Road Traffic Act. If you can undertake safely, with proper lane discipline you are not breaking any laws. The only law you could potentially break when "undertaking" is if you do it in a dangerous or aggressive fashion, such as moving from lane 3 to lane 1 to undertake, then moving back to lane 3. In this case a driver would be prosecuted for careless driving under section 3 of the 1988 Road Traffic Act.
I found this out a few years ago. I was driving on a 2 lane motorway at 70mph in lane 1. It was late evening and I had another car sitting a safe distance behind me in the same lane. We are safely moving to lane 2 to overtake slower vehicles and moving back to lane 1 when safe to do so. Eventually I came up to a Jaguar XF doing 55mph in lane 2, nothing wrong with this as it was overtaking a slower car in lane 1. I slowed down to 55 mph at a safe distance in lane 2, expecting the Jag to move to lane 1 when it was empty. Lo and behold this idiot decided to sit in lane 2 at 55 mph for about a minute, even though lane 1 was now completely clear. When I realised this moron was never going to move over, I moved into lane 1 and sped up to 70mph to undertake them.
After I got past the Jag, the car behind me, which was still in lane 2 started flashing all blue blights. It was an unmarked police car. My heart ended up in my throat and I indicated and began slowing down expecting to be given a ticket for "undertaking". So the Jaguar goes past me still doing 55mph and I swear the woman driving it was looking at me and laughing. Then the unmarked police car went past me with his lights still flashing. By this stage I am completely confused and think the police are pulling us both over. All three of us stop on the hard shoulder, the Jag in front, then the police car and me at the back.
One of the policemen walks to my car and I fumble to look for my driving licence, while the other officer goes to the idiot woman in the Jaguar. The policeman came up to my passenger side window so I open it, and asks me why I stopped. I explained I thought I was being done for undertaking and he looks all exasperated and said, "no sir, you have done nothing wrong, drive on please".
I couldn't resist giving the woman driving the Jaguar driver a smug look and a smile as I drove past. A quick Google on the internet when I got home revealed that undertaking is not an actual offence. It is the act of driving dangerously that is the offence and if you do undertake in a safe fashion then you are not breaking any laws under the Road Traffic Act. The lane hogging slow driver on the other hand is breaking the law.