Bug 108020 - comsat(8) does not verify return values of getpwnam and setuid
Summary: comsat(8) does not verify return values of getpwnam and setuid
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 6.2-PRERELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-16 21:50 UTC by Bjoern Voigt
Modified: 2017-12-31 22:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bjoern Voigt 2007-01-16 21:50:21 UTC
I reviewed the code of comsat (/usr/src/libexec/comsat/comsat.c).

There are two potential problems in function jkfprintf():

[...]
        /* Set effective uid to user in case mail drop is on nfs */
        if ((p = getpwnam(user)) != NULL)
                (void) setuid(p->pw_uid);
[...]

1) If getpwnam() fails the function is continued without dropping privileges.
2) The return value of setuid() is not checked. The manual page says that
   setuid() could only fail for non-root. Anyway, it's no good style to
   ignore the result of setuid().

Fix: 

getpwnam problem:
I suggest to return function jkfprintf() if getpwnam() fails.

setuid problem:
I suggest to return function jkfprintf() if getpwnam() fails and if getuid()
returns 0 (root). The check for user root may not be necessary since normal
users can not really switch the uid with setuid() if the program is not
installed with set-uid (as far as I know).

I could help with a patch and with testing.
How-To-Repeat: Faked comsat requests could be generated with "nc" (netcat). A "bad" user
could send non-existing user names (getpwnam() will fail and setuid() will
not be called). He could also send file names which should not be readable
by the user with receives the biff messages. 

netcat could be used this way (tested with netcat from ports collection):

$ /usr/local/bin/nc -u localhost 512
user@0:/some/file
Control-c
(Mail for "user", offset byte 0, mailbox "/some/file")
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:44 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped