If your passport expires while you are in the UK with a visitor Visa, you will need to apply for a new passport from your home country's embassy or consulate in the UK. You will also need to transfer your valid visitor Visa from your old passport to your new passport by applying for a biometric residence permit (BRP). You can find more information on how to do this on this link