I develop a model in which banks finance the purchase of risky assets by borrowing against the assets as collateral through repurchase agreements (repos). Due to limited liability, banks with impaired balance sheets have incentives to build up leveraged positions that generate positive default risk. Averse to the risk of counterparty default, lenders set the amount of repo funding to deter banks from taking excessive leverage. Consequently, the amount of repo funding depends not only on the uncertainty in collateral value but also on the borrower's balance sheet strength. The model generates positive feedback between asset price and repo funding: a decrease in asset price caused by an initial tightening of the funding market can further depress repo funding through increasing banks' incentives for taking excessive leverage. As a result, a small deterioration of banks' balance sheets can generate large decreases in repo funding and asset prices. According to the model, a countercyclical capital buffer can increase the stability of repo funding, whereas a minimum margin requirement can be ineffective in reducing the risk of a market-wide funding squeeze.