Bug 1433 - sshd.pid has permissions of 666
Summary: sshd.pid has permissions of 666
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 4.7p1
Hardware: HPPA HP-UX
: P2 security
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_5_1
  Show dependency treegraph
 
Reported: 2008-01-28 13:56 AEDT by leanne
Modified: 2008-07-22 12:20 AEST (History)
1 user (show)

See Also:


Attachments
set umask for PidFile (832 bytes, patch)
2008-01-28 16:24 AEDT, Darren Tucker
no flags Details | Diff
for fixing the permission of sshd.pid in the source code (452 bytes, patch)
2008-01-28 17:03 AEDT, leanne
no flags Details | Diff
Ensure sshd's umaske disallows at least group and world write. (813 bytes, patch)
2008-06-15 03:34 AEST, Darren Tucker
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description leanne 2008-01-28 13:56:23 AEDT
The sshd.pid under /var/run has the permission of 666, which we think is a security bug.
we can see that:
# ps -ef |grep sshd
    root  9341     1  0  Jan 25  ?         0:02 /opt/ssh/sbin/sshd
    root   640   482  0 10:17:10 pts/ta    0:00 grep sshd
# kill 9341
# umask
022
# umask 00
# /opt/ssh/sbin/sshd
# ll /var/run/sshd.pid
-rw-rw-rw-   1 root       sys              4 Jan 28 10:17 sshd.pid

so we change the openssh source code as this, pls see the attachment.
Comment 1 Darren Tucker 2008-01-28 16:24:37 AEDT
Created attachment 1448 [details]
set umask for PidFile

The other thing you can to do mitigate this is to set your umask to something other the "0".
Comment 2 leanne 2008-01-28 17:03:12 AEDT
Created attachment 1449 [details]
for fixing the permission of sshd.pid in the source code
Comment 3 leanne 2008-01-28 17:07:19 AEDT
This is a patch made by us, and we have tested it on all the hp-ux platform for 11.11, 11.23 and 11.31, it's ok. we just change the permission of pid file to 644, what do you think the patch

(In reply to comment #2)
> Created an attachment (id=1449) [details]
> for fixing the permission of sshd.pid in the source code
Comment 4 Darren Tucker 2008-01-28 17:28:22 AEDT
Comment on attachment 1449 [details]
for fixing the permission of sshd.pid in the source code 

>                                fprintf(f, "%ld\n", (long) getpid());
>                                fclose(f);
>+                               if (chmod(options.pid_file,0644) == -1)
>+                                       logit("chmod pid file failed");

This is not the best way to handle this as it's racy (ie there's a period between the write and the chmod where the content of the file could be changed).
Comment 5 Darren Tucker 2008-06-15 03:34:35 AEST
Created attachment 1522 [details]
Ensure sshd's umaske disallows at least group and world write.

This patch has been applied and will be in the next (5.1) release.

Thanks.
Comment 6 Damien Miller 2008-07-22 12:20:46 AEST
Mass update RESOLVED->CLOSED after release of openssh-5.1