Bug 136 - setgid() deemed to fail for non-suid ssh client on linux if using other than primary group
Summary: setgid() deemed to fail for non-suid ssh client on linux if using other than ...
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: -current
Hardware: ix86 Linux
: P2 normal
Assignee: Kevin Steves
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-08 03:16 AEDT by Daniel Müller
Modified: 2004-04-14 12:24 AEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Müller 2002-03-08 03:16:10 AEDT
On Linux (at least -- I don´t know about BSD), trying to use a
non-suid-root ssh client while having switched to a group other than
the calling user's primary group (by sg or newgrp) fails with an error
message: setgid <primary group>: Operation not permitted

Looking for the reason of the failure, I found it in the function
permanently_set_uid() in uidswap.c: It tries to set the gid to the
value from /etc/passwd, which (at least on Linux) can only succeed if
either the process has superuser privileges (the binary is installed
suid root) or the real or effective gid is already that value. If a
user is currently using a gid of a group that she is member of but
which isn't her primary group from /etc/passwd, setgid() fails.

A solution could be either 
- to do nothing in permanently_set_uid() when euid != 0 (this is
  similar to the behaviour of temporarily_use_uid()). I'll append the
  short patch for this; I'm using it as a quick solution.
- or to set the uid/gid to the real uid/gid, thereby dropping any
  privileges that a suid-non-root binary might have. This might be a
  bit cleaner and needs a little more changing (I haven't done this
  yet, but can do on demand).

Regards,
Daniel Müller

--- uidswap.c~	Thu Aug 16 01:17:22 2001
+++ uidswap.c	Thu Mar  7 16:12:25 2002
@@ -147,6 +147,7 @@
 {
 	if (temporarily_use_uid_effective)
 		fatal("restore_uid: temporarily_use_uid effective");
+	if (geteuid() != 0) return;
 	if (setgid(pw->pw_gid) < 0)
 		fatal("setgid %u: %.100s", (u_int) pw->pw_gid, strerror(errno)); 	if
(setuid(pw->pw_uid) < 0)
Comment 1 Kevin Steves 2002-03-31 06:38:23 AEST
i will look at this.
Comment 2 Doug Chimento 2002-05-23 02:32:13 AEST
This occurs on Solaris 2.6 and 2.8 as well.
Furthermore, in the function restore_uid would 

if (geteuid() != 0) return;
     make more sense then 
if (!privileged) return ; 

just a thought. 

Thanks 
Comment 3 Kevin Steves 2002-06-23 04:57:09 AEST
fixed in OpenSSH 3.3
Comment 4 Damien Miller 2004-04-14 12:24:18 AEST
Mass change of RESOLVED bugs to CLOSED