new_to_non_X86 wrote:PaulBredbury wrote:the bug is obviously in the nethack code
wolf31o2 wrote:This *is* 100% a bug in nethack
nethack code or not
the way gentoo handle games must be fixed
but we can temporaly patch nethack.while working on resloving this issue
it's like if there were a bug inside selinux,pax or something equivalent...of course the problem is ALSO in the aplication that isn't well written...
but what if you run binary games?
i don't only mean commercial games but certain games such as cube use binaries in order to prevent cheating(or if not why gentoo also install the default binary?)
genericaly protecting gentoo against this problem is not a bad idea...because we won't be able to search(and find) bugs and fix all games
*mabe we should be able to do the folowing(not very usefull because high risk still exist):
knowin that sudo is not safe we won't use it
we could instead use su and a hack that permit us to have an environement such as when we are loged natively(that means that we must be able to run things un /usr/bin and give acess to $HOME to all programs running inside this environement) and run games from that environement
but we must be carefull and look if it can compromise or not the normal user acount(for the hack giving acess to /usr/* )
mabe also chroot or jail?
the problem is that the atacker WILL be able to control this system...so it's a bad idea(usefull only for a quick and dirty fix)
This proposed solution is far too complicated, and I doubt you are ready to contribute code or patches for this idea.
It is also unnecessary. The solution is already in place; gentoo took the liberty of removing it.
The way BSD does it works fine, it has been in place since the 80's. A small explanation:
Games are granted setgid permissions of the games group. This means that when somebody executes the game, they are temporarily a part of the games group during the execution of the game, allowing them to modify the scorefile, or place saved games in the save/ directories.
The result is, the user can only modify the scorefile and saved games through the program itself. The program itself has checks to limit the user to modifying only her savefile, and the scorefile only when appropriate (win, death).
The savefile cannot be created by the user outside of the game, as it only has +w permissions for the games group.
The scorefile can only be modified by the game, during the game.
The way gentoo does this is ridiculous. A small explanation:
All of the games are +x only for the games group. The games are not setgid, and are run under the user's normal permissions. This means that to allow the user to write to the scoreboard and save games directory, she must have +rw access to these.
The result in gentoo:
You can save a nethack game, uncompress it, hexedit it to increase your stats, place it back into the directory (that you have rw access to), and re-load the saved game. Complete the game until you win or die, and receive a very high score.
But why go through the trouble? Just edit the scorefile, you have the permissions to.
So now the scorefile is no longer authoritative. But it can get much, much worse.
Edit the scorefile, or somebody else's saved game, or make a saved game for somebody else (though nethack and most others will verify that the saved game has the player's attributes). Find a buffer with bad bounds checking, and insert a small snippet of code that will make a copy of /bin/sh somewhere sneaky and setuid for the user executing the code.
The user will see nethack crash, shrug it off, thinking that the saved game was corrupt, and start a new game. The attacker will run the copy of /bin/sh the victim created and be the effective user of the victim
and go on reading her mail, stealing ssh keys, etc. etc.
In Gentoo, the game is being executed in the context of the user who played it, even root may take a load off with a quick game of nethack, with severe repercussions.
The _only_ reasoning I can see for gentoo doing this is the purpose of selectively allowing particular users to run games.
On non-gentoo/BSD:
You cannot modify even your own saved game. You can make a copy of it and hexedit it, but only replace it using sudo or root access. Nobody (as in !everybody) is in the games group. The same attack could not happen unless you found a way to overflow a buffer in-game. Making a corrupt save file outside of the game will do you no good, as you will not be able to load it. Making a corrupt savefile in-game will also not do you any good, because it is loaded only for you. Corrupting the scorefile in-game would be QUITE the feat, and I would be even more difficult. In fact, it is nearly impossible as the avenues of input in-game are very limited.
The games do not need to be fixed; gentoo's non-standard handling of the games do. Buffer overflows are non-issue outside of gentoo.