Section 506(a) and 506(d) of the Bankruptcy Code states that a lien is only secured to the extent there is value in the collateral to which the lien attaches. This means that the portion of the lien that exceeds the value of the collateral is considered unsecured. Basically, when a home is “upside down," there is no equity for the second mortgage to attach to.
Under the current laws, bankruptcy judges are not allowed to modify the terms of your mortgage. For example, a judge is not able to carve out or bifurcate your mortgage or HELOC into a secured portion and an unsecured portion and then discharge the unsecured portion.
However, if the value of the house is less than the 1st mortgage, the judge can re-characterize the 2nd mortgage (or other junior lien) as unsecured, thereby allowing you to discharge it in a Chapter 13. For example, if your house is worth $100,000 and you owe $110,000 on the 1st mortgage and have a HELOC/2nd mortgage of any amount, there is no equity for the junior lien to attach to. The holder of the junior would receive nothing in a foreclosure sale.
A Chapter 13 will allow you to re-characterize the junior lien as unsecured and discharge it in your bankruptcy through an adversary proceeding. During the pendency of your Chapter 13 plan, you would not make any payments to the junior lien holder. The junior lien holder would be treated as a general unsecured creditor for the duration of plan and would only receive a pro rata share of any payments the trustee makes to unsecured creditors. Keep in mind that your plan payment is determined by your disposable income rather than the amount of your debt.