 According to Ahmad ibn Hanbal, it is permissible for prisoners, travellers and for men and women who have difficulty in finding a lawful spouse.Zahiri Imam Ibn Hazm regards masturbation as permissible.Any sexual engagement outside marriage including masturbation is a major sin altogether in the Shi'a Islam.