My understanding of the Fed is that it must keeps its books balanced as follows:
value of securities held at central bank = amount of central bank money.
If the value of the securities rise, then the Fed needs to increase the amount of central bank money, which it does by passing its "profits" to the US treasury. Normally, the securities held at the Fed are US Treasury Notes, but starting with the Great Recession, the Fed began accumulating mortgage backed securities as well. Ultimately, these securities gave a profit, and these were passed on to the US treasury like always. However, what if that was not the case? What if these securities defaulted, and the Fed incurred a "loss"? Would it have to pass the loss onto the US Treasury as well? What would that look like? Would the US treasury simply give the Fed US Treasury Notes without getting central bank money in return?
The following FEDS Note by Bonis, Fiesthumel, and Noonan (2018) provides detailed answers to your questions: https://www.federalreserve.gov/econres/notes/feds-notes/somas-unrealized-loss-what-does-it-mean-20180813.htm
In short, in the unlikely event the Federal Reserve encounters a realized overall net income loss, the Fed will stop remittances to the Treasury, record such loss as a "deferred asset" (this asset would represent a claim on the Fed's future net earnings), and not resume remittances to the Treasury until the Fed accumulates enough net earnings to offset the value of this asset. There is no mechanism for the Fed to pass any loss directly to the Treasury, or for the Treasury to directly give securities to the Fed.