The talmud in Rosh Hashana 17a lists some sins which warrant eternal gehinom.
Is this to be taken literally? Or perhaps it means a very long time or until the end of this world?
It seems clear that the Sefer HaIkkarim (4:36) understood it literally. He writes that since God lasts infinitely, it is appropriate that one who sins against him be punished infinitely as well. And he notes that the passage in Rosh Hashana is consistent with this:
אחר שהיתה כונתו לזלזל בכבודו של מלך ראוי שיהיה נענש כפי כונתו לא כפי הפעל המגיע ממנו בלבד, ולזה ראוי שיהיה העונש המגיע לרשע נצחי כמו שהשם יתברך נצחי ובלתי בעל תכלית
וכן יראה שהוא דעת רבותינו ז"ל שיש עונש נצחי מגיע לרשעים על פעל זמניי, אמרו במסכת ראש השנה (י"ז ע"א) על קצת הרשעים שיורדים לגיהנם ונדונים בה לדורי דורות, שיראה מזה שיש עונש נצחי
Given that his intent was to degrade the honour of the king, it is appropriate that he be punished according to his intent, and not according to the result of his deed alone, and therefore it is appropriate that the punishment coming to man be eternal just as God is eternal and without limit.
And this appears to be the opinion of our rabbis OBM; that there is eternal punishment for the wicked based on their temporally finite actions. They said in Tracteate Rosh Hashana (17a) regarding a portion of the wicked who descend to hell and are punished there for generation after generation, that it appears that there is eternal punishment.
This is also clearly the understanding of R. Meir Abulafia who writes (Iggerot Ramah #46) that one shouldn't think that those who will be resurected at the resurection of the dead, will die again, since then their reward wouldnt be eternal. Indeed, the punishment of the wicked is eternal, as we see in the passage in Rosh HaShana, so a fortiori the reward of the righteous must be as well.
ואין לומר שאחרי חיות הגופות לעוה"ב ימותו שנית... שהרי אמרו חכמים לענין פרעון שלהרשעים שהוא לעוה"ב בגוף וגויה שאין לו הפסק, כמאמרם (ר"ה שם) יורדים לגיהנם ונדונים בה לדורי דורות...והדבר ידוע (סנ' ק' רע"ב וש"נ) שמדת הטובה מרובה ממדת הפורענות
Evidently, he understands that the punishment is literally eternal.
Similarly, a very similar passage in Genesis Rabba (ed. Albeck Parashat Vayechi: 97) is even more clearly talking about actual eternity than the passage in Rosh Hashana:
באותה שעה יפרע הקדוש ברוך הוא מאומות העולם פורענות גדולה שאין לה הפסק ואין לה קץ ומורידן לגיהינם ונידונין בה לדורי דורות שנ' ויצאו וראו בפגרי )האנשים (שם /ישעיהו/ סו כד
Rabbi Yonasan Hirtz, rabbi of Utopia Jewish Center, in Queens, lectured once that the rabbis' explanations of what happens after death is pure speculation. "No one knows what happens after death because anyone who knows is dead," he said. The purpose of the speculation, like many midrashim, is to help us prioritize our values. One might believe that the rabbis' views were traditional teachings that Moses received at Mount Sinai and passed on as part of the oral tradition. But I think not. The Gemara at Rosh Hashana 17a (and the discussion before and after that page) do not specifically cite to such a tradition (although they do not always say), but rather use references to the words of the prophets to support their points.
For example, the Gemara at Rosh Hashana 16a makes reference to a prophecy in Malachai 3:21 ("And you shall crush the wicked, for they will be as ash under the soles of your feet on the day that I will prepare, says the Lord of Hosts") to support the position that the souls of the wicked are sent to Gehinom (Hell) for 12 months after death and then reduced to ashes in the flames, scattered in the wind, then becoming the dust that the righteous walk upon.
The Rambam (Hilchos Teshuva 3:6) seems pretty unequivocal that this is indeed an eternal punishment. Other rishonim such as the Ritva appear to distinguish between some of the members listed in this passage and indicate that heretics and apostates will remain in Gehinnom until Moshiach comes, at which point they will be brought about to witness the fulfillment of the things that they sought to deny.
... the children of Avraham are promised that they are going to be saved from Gehinnom. Avraham himself comes down into Gehinnom and pulucks his children out from there.
However, sometimes, Avraahm must leave some of his children in Gehinnom. Those are some Jewish men who sin by having relations with an Aramis [non-Jew], the Gemara says. Avraham cannot help them. He only helps those who have a bris kodesh, who have kept holy the convenant sealed in their flesh. [...] Avraham tries his best to take Jewish sinners out of Gehinnom, but there are some sinners even he can't save.