Use haram profits to pay interest debt

Salaam, I invested into a stock which was initially shariah compliant but now is not. I understand I need to give away profits however am I able to pay off my interest bearing student loan using this profit? Would that be allowed.

Thanks.
Wajeeh