Bug 1433

Summary: sshd.pid has permissions of 666
Product: Portable OpenSSH Reporter: leanne <njleanne>
Component: sshdAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: security CC: dtucker
Priority: P2    
Version: 4.7p1   
Hardware: HPPA   
OS: HP-UX   
Bug Depends on:    
Bug Blocks: 1452    
Attachments:
Description Flags
set umask for PidFile
none
for fixing the permission of sshd.pid in the source code
none
Ensure sshd's umaske disallows at least group and world write. none

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