Re: Bug in set/gethostname.

Ton Hospel (
17 May 1998 22:07:55 GMT

In article <>,
Linus Torvalds <> writes:
> On Sun, 17 May 1998, Alan Cox wrote:
>> Both single and SMP sethostname/gethostname have a problem. If you get a page
>> fault during the copy in a gethostname can return a corrupt nodename. If it
>> has overwritten the previous 0 byte you can get a lot of crap in theory
>> but I've never seen it do that
>> If you do two sethostnames and one of them sleeps you can get a mixed up
>> or shortened hostname.
>> sethostname/sys_newuname/sys_gethostname/sys_setdomainname need a reader/writer
>> lock on them.
> Alan, why?
> It's not a security risk, and it's not a real problem as far as I can see.
> It's something you can only see if you write a completely unrealistic
> program, and even when you see it the worst that happens is that you get a
> crap return to a crap program.
> Crap programs are _supposed_ to return crap.
> End even then you actually have to be root to get the bad behaviour. If
> you're root, you can do some _really_ bad things, so I don't see the point
> in changing this, adding code that sounds completely unnecessary unless
> you give a real-world example.
> Usually you set the hostname once, at bootup. Or maybe you're doing system
> administration and playing around with it, but when you do so you'd better
> be fairly quiescent anyway and restart all your networking deamons etc
> after having done so - so we're talking about something that isn't done on
> a whim.
> In short, give a better reason, because as it stands, this "bug" is not a
> bug, but just a case of "let's not add code to take care of a case we
> shouldn't care about anyway". It's a "bug" in the same sense as it's a
> "bug" that root can write to /dev/kmem and make the system unstable.
> Linus

I at least once changed the hostname on a running server system that
should NOT go down (or to be more specific, the server program on it
should not go down). If that program would have happened to do
a gethostname() at that moment, you say I deserve to be screwed ?
Why ? I did something completely normal (though rare), and the
program would have been doing something completely normal.

For an OS that is supposed to be able to be up for years, it's not strange
for administration to get different ideas about computer names. And I
wouldn't want e.g. a mail job started from inetd at that moment just doing
a gethostname() to crash or give nonsense.

And is it even so much of a problem giving sethostname even a global lock ?
Calling sethostname() often, now THAT would be weird. So the price to make
sethostname() an atomic writer seems negliable. Or am I missing something ?

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to