Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 77915 - openssh: permanently_set_uid: was able to restore old [e]gid
Summary: openssh: permanently_set_uid: was able to restore old [e]gid
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-13 17:58 UTC by Chris Smith
Modified: 2006-04-11 13:58 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Smith 2005-01-13 17:58:09 UTC
I have finally figured out why my backups stopped working -- I upgraded ssh.
When I run it as root under (the equivalent of) sudo, it exits without doing
anything, saying

  permanently_set_uid: was able to restore old [e]gid

This may be somebody's idea of a good idea, but it is not mine.  I need to
use ssh because NFS is too flaky.  If you can't fix ssh, at least I urge you
to fix that horrible error message.  And add "ssh:" to its errors.  And make
it not blat hundreds of lines of garbage to the system log about whatever this
garbage is about.

  Jan 13 18:45:31 stoneboro PAM-env[4425]: Unknown PAM_ITEM: <DISPLAY>
  Jan 13 18:45:31 stoneboro sshd[4425]: PAM pam_putenv: delete non-existent entry; DISPLAY
  Jan 13 18:45:31 stoneboro PAM-env[4425]: Unknown PAM_ITEM: <XAUTHORITY>
  Jan 13 18:45:31 stoneboro sshd[4425]: PAM pam_putenv: delete non-existent entry; XAUTHORITY



Reproducible: Always
Steps to Reproduce:
1. sudo ssh machine echo a
2.
3.

Actual Results:  
permanently_set_uid: was able to restore old [e]gid

Expected Results:  
a
Comment 1 SpanKY gentoo-dev 2005-01-13 18:13:02 UTC
the PAM stuff is COMPLETELY unrelated to ssh, it's a pam bug (search bugzilla)
Comment 2 SpanKY gentoo-dev 2005-01-13 18:14:14 UTC
so for now, lets punt this bug until you provide information

you neglected to provide `emerge info` like the bug report page told you to

what version of openssh ?

wtf are you doing exactly ?  `sudo scp` ?
Comment 3 Chris Smith 2005-01-13 18:26:09 UTC
openssh-3.9_p1-r1, I think.  x86 stable of about 3 days ago.  I've unmerged it.

Upgrading to openssh-3.7_p2-r1 has fixed my problem.  I will probably eventually
upgrade all the way to rcp.  Please tell the genius who broke ssh how clever he
really is.

What I'm doing exactly is: in a sudo shell, ssh foo "cat > file", or any
other command, including echo a.

emerge info:
Portage 2.0.51-r3 (default-linux/x86/2004.0, gcc-3.3.4, glibc-2.3.4.20040808-r1, 2.4.25 i686)
=================================================================
System uname: 2.4.25 i686 Pentium II (Deschutes)
Gentoo Base System version 1.4.16
Autoconf: sys-devel/autoconf-2.59-r5
Automake: sys-devel/automake-1.8.5-r1
Binutils: sys-devel/binutils-2.15.90.0.1.1-r3
Headers:  sys-kernel/linux-headers-2.4.19-r1,sys-kernel/linux-headers-2.4.21-r1
Libtools: sys-devel/libtool-1.5.2-r7,sys-devel/libtool-1.4.3-r4
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CFLAGS="-O2 -march=i686 -fomit-frame-pointer -pipe"
CHOST="i686-pc-linux-gnu"
COMPILER=""
CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3/share/config /usr/lib/mozilla/defaults/pref /usr/share/config /usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/qmail/alias /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-O2 -march=i686 -fomit-frame-pointer -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms userpriv usersandbox"
GENTOO_MIRRORS="http://open-systems.ufl.edu/mirrors/gentoo ftp://gentoo.ccccom.com http://mirrors.tds.net/gentoo http://cudlug.cudenver.edu/gentoo/"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="x86 X arts avi berkdb bitmap-fonts cdr crypt cups doc emacs encode foomaticdb fortran gdbm gif gpm gtk gtk2 ipv6 java jpeg libwww mad maildir mikmod motif mozilla mpeg ncurses oggvorbis opengl oss pam pdflib perl png python quicktime readline sdl slang spell ssl svga tcltk tcpd tetex tiff truetype xml2 xmms xv zlib"
Comment 4 SpanKY gentoo-dev 2005-01-13 18:41:31 UTC
stop with the useless snide remarks, it only serves to piss us off and mark you as a waste of time

i'm not quite sure i can reproduce this ... here's what i've tried:
$ ssh vapier@hake
$ sudo ssh vapier@dolphin "echo blah > somefile"
$ logout
$ ssh vapier@dolphin
$ cat blah
somefile
Comment 5 Chris Smith 2005-01-13 20:25:01 UTC
Huh.  I entered a (contrite) comment and tried to change this bug to WORKSFORME.
Guess it didn't work.

My problem was using (the equivalent of) sudo instead of real sudo.  It changes
my uid/gid from 525/525 to 0/525 rather than sudo's 0/0.

This code in uidswap.c function permanently_set_uid()

	/* Try restoration of GID if changed (test clearing of saved gid) */
	if (old_gid != pw->pw_gid &&
	    (setgid(old_gid) != -1 || setegid(old_gid) != -1))
		fatal("%s: was able to restore old [e]gid", __func__);

is attempting to verify that it has dropped setuid/setgid privs.  There should
be no case where a correctly configured ssh hits that error.  But it assumes
it's going from 0/0 to 525/525, not (as in my case) 0/525 to 0/525.  I have
old_gid = 525, pw->gid = 0, old and new uid = 0 so setgid() succeeds.

Whether that's a bug I don't know.  They certainly didn't deliberately break
setuid ssh.
Comment 6 Chris Smith 2005-01-15 11:54:31 UTC
uidswap.c (permanently_set_uid):

	if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0)
	    fatal("setresgid %u: %.100s", (u_int)pw->pw_gid, strerror(errno));
	...
	/* Try restoration of GID if changed (test clearing of saved gid) */
	if (old_gid != pw->pw_gid &&
	    (setgid(old_gid) != -1 || setegid(old_gid) != -1))
		fatal("%s: was able to restore old [e]gid", __func__);

The thinking is: We want to check that we have successfully changed the
saved gid to pw->pw_gid.  There is getgid() and getegid() -- and it uses
them to test those gid's -- but no portable getsgid().  So we assume if the
saved gid is set to something wrong, it is set to old_gid.  The setgid()
and setegid() will succeed in that case.

The flaw is: setgid() will succeed for root even if old_gid does not
match the saved gid.

A fix is:

	/* Try restoration of GID if changed (test clearing of saved gid) */
	if (old_gid != pw->pw_gid && getuid() != 0 &&
	    (setgid(old_gid) != -1 || setegid(old_gid) != -1))
		fatal("%s: was able to restore old [e]gid", __func__);

The setgid()/setegid() tests will never detect anything useful for uid 0.

The analagous test for uid

	/* Try restoration of UID if changed (test clearing of saved uid) */
	if (old_uid != pw->pw_uid &&
	    (setuid(old_uid) != -1 || seteuid(old_uid) != -1))
		fatal("%s: was able to restore old [e]uid", __func__);

never finds old_uid != pw->pw_uid since pw is

	original_real_uid = getuid();
	pw = getpwuid(original_real_uid);
	...
	uid_t old_uid = getuid();

initialized with pw->pw_uid == old_uid.  It has the bug too, but will never
hit it.  But it too should check getuid() != 0, since the second line is
nonsense without it.

Comment 7 Chris Smith 2005-01-16 08:50:24 UTC
That should be geteuid() != 0
Comment 8 Jakub Moc (RETIRED) gentoo-dev 2005-11-11 09:37:51 UTC
Re-assign.
Comment 9 SpanKY gentoo-dev 2006-02-07 21:26:27 UTC
you havent by chance filed a bug upstream have you ?

http://www.openssh.org/report.html
Comment 10 Chris Smith 2006-04-11 13:58:42 UTC
(In reply to comment #9)
> you havent by chance filed a bug upstream have you ?
> 
> http://www.openssh.org/report.html

Afraid not, but I have now done so, sort of.