Marlene (leader of the Fireflies) claims it's okay to kill Ellie for science because "Ellie would have said yes"[...] Moreover, if Marlene is so sure that Ellie would say "yes", then she should have just asked her
Marlene is not the leader of the fireflies: she called the shots in Boston, but in Salt Lake City she clearly defers to others: more likely, she was willing to ask Ellie but was overruled by her superiors and did not dare challenging them, which would be thematically relevant: to fight the post-apocalyptic junta, the fireflies became increasingly military in their organization, to the point of mimicking their enemies' worst vice: gaze at the abyss for too long...
***
And here is where the Fireflies excuse of "ends justify the means" comes back to bite them. If they can kill Ellie because the life of one innocent girl is less valuable than the lives of all of humanity, then someone in Joel's position would be justified in wiping them all out for trying to stupidly waste the one immune test subject on bad science.
There's another aspect to take into account: the reunion between Joel and Tommy serves to show that contrary to the Boston and Pittsburgh chapters hinted, it's the quarantine system which is on its last leg, not civilization nor humanity as a whole: the choice is most definitely not between sacrificing Ellie to get a cure and mankind's extinction: it's between the unhinged self-righteous survivors of a failed revolution taking a long shot and choosing the longer, harder, but much more likely to be successful path of not treating the cordyceps' eradication as the obligatory first steps toward rebuilding society.
My pet theory is that the surviving fireflies' goals got perverted along the way, from wanting to restore he rule of law to wanting to be hailed as civilization's saviors: this change drove away the more level-headed members like Tommy, leaving only the more radicals members who kept reinforcing their self-righteousness by retreating in their own insular epistemic bubble.
***
At best, he did the right thing for the wrong reason.
I think that's were the real ambiguity of the story lies: it's not whether rescuing Ellie was the right thing to do, but whether Joel's motive were honorable or selfish. In a way, it boils down to how one perceive Joel.
Personally I see him as a man who's furious at the universe his life was destroyed despite the fact that he'd done all he could to be an upright citizen and good father, so he's going to make sure he causes to others more pain than he, himself, suffered... but he's not self-conscious enough to admit it to himself and looking for an excuse, any excuse to let his rage lose and inflict his wrath upon other people.
Ellie is thus the perfect rationalization: Joel can kill, maim, torture people left and right while pretending that he still is a decent man because he's doing it all for her.