Yes, until you are actually foreclosed upon, you can legally list and sell your home. You will have to disclose the fact that you are in default and foreclosure may be pending to any potential buyers, however; otherwise, you will be committing fraud, since you will not be disclosing a material or important issue affecting the property and ownership of it, which fraud could let them rescind (undo) the sale and/or sue you for monetary compensation. And if the proceeds of the sale do not fully pay off your mortgage (e.g. it is a "short sale"), the lender could sue you for the balance.