Bug 2329 - [rs]etres[gu]id have misordered arguments
Summary: [rs]etres[gu]id have misordered arguments
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: hurd (show other bugs)
Version: 2.3.6
: P2 normal
Target Milestone: ---
Assignee: Roland McGrath
URL:
Keywords:
Depends on:
Blocks: libc237
  Show dependency treegraph
 
Reported: 2006-02-12 12:33 UTC by Samuel Thibault
Modified: 2016-05-12 15:04 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2006-02-21 02:29:04
fweimer: security+


Attachments
fix order of parameters of hurd's getresuid() (293 bytes, patch)
2006-02-12 12:34 UTC, Samuel Thibault
Details | Diff
[rs]etres[gu]id.patch (1.83 KB, patch)
2006-02-15 16:28 UTC, Thomas Schwinge
Details | Diff
Testcase for getresuid (151 bytes, text/plain)
2006-02-15 18:28 UTC, Samuel Thibault
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Thibault 2006-02-12 12:33:45 UTC
Hi,

When calling getresuid() from a setuid program, ruid and uid are exchanged. This can make setuid program set the effective uid as real uid too, so that the user that launched the program can't kill it any more...

I'll attach an obvious fix.

Regards,
Samuel
Comment 1 Samuel Thibault 2006-02-12 12:34:29 UTC
Created attachment 863 [details]
fix order of parameters of hurd's getresuid()
Comment 2 Thomas Schwinge 2006-02-15 16:24:57 UTC
I'll attach a complete patch.
Comment 3 Thomas Schwinge 2006-02-15 16:28:06 UTC
Created attachment 866 [details]
[rs]etres[gu]id.patch
Comment 4 Thomas Schwinge 2006-02-15 16:29:39 UTC
Please apply [rs]etres[gu]id.patch to both the trunk and glibc-2_3-branch.
Comment 5 Dwayne Grant McConnell 2006-02-15 18:22:03 UTC
Do you have a small testcase to demonstrate the problem?
Comment 6 Samuel Thibault 2006-02-15 18:28:13 UTC
Created attachment 867 [details]
Testcase for getresuid

Fails on the Hurd. Fixed by attached patch.
Comment 7 Samuel Thibault 2006-02-15 18:43:51 UTC
Comment on attachment 867 [details]
Testcase for getresuid

I forgot to say: set the binary setuid root. The output will then be something
like 1000 0 0 1000 0 while it should be 1000 0 1000 0 0
Comment 8 Thomas Schwinge 2006-02-15 20:22:11 UTC
(In reply to comment #5)
> Do you have a small testcase to demonstrate the problem?

Just have a look at the corresponding Linux code, which is where these functions
come from as I understand it.

[glibc]/sysdeps/unix/sysv/linux/i386/getresuid.c
#v+
[...]
int
__getresuid (uid_t *ruid, uid_t *euid, uid_t *suid)
{
# if __ASSUME_32BITUIDS > 0
  return INLINE_SYSCALL (getresuid32, 3, CHECK_1 (ruid),
                         CHECK_1 (euid), CHECK_1 (suid));
# else
[...]
  result = INLINE_SYSCALL (getresuid, 3, __ptrvalue (&k_ruid),
                           __ptrvalue (&k_euid), __ptrvalue (&k_suid));

  if (result == 0)
    {
      *ruid = (uid_t) k_ruid;
      *euid = (uid_t) k_euid;
      *suid = (uid_t) k_suid;
    }

  return result;
# endif
}
[...]
#v-

The syscall looks like this:
[linux]/kernel/sys.c
#v+
[...]
asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t
__user *suid)
{
        int retval;

        if (!(retval = put_user(current->uid, ruid)) &&
            !(retval = put_user(current->euid, euid)))
                retval = put_user(current->suid, suid);

        return retval;
}
[...]
#v-
Comment 9 Dmitry V. Levin 2006-02-15 20:25:30 UTC
2decimal: you need GNU Hurd to reproduce the bug.

This is a grave security issue on hurd, glibc on other kernels seems to be
unaffected.
Comment 10 Sourceware Commits 2006-02-21 02:28:32 UTC
Subject: Bug 2329

CVSROOT:	/cvs/glibc
Module name:	libc
Changes by:	roland@sources.redhat.com	2006-02-21 02:28:30

Modified files:
	posix          : unistd.h getresgid.c setresuid.c getresuid.c 
	                 setresgid.c 
	sysdeps/mach/hurd: getresgid.c setresuid.c getresuid.c 
	                   setresgid.c 
	include        : unistd.h 

Log message:
	2006-02-15  Thomas Schwinge  <tschwinge@gnu.org>
	
	[BZ #2329]
	* include/unistd.h (__getresuid, __getresgid, __setresuid)
	(__setresgid): Fix argument name order in prototypes.
	* posix/unistd.h (getresuid, getresgid, setresuid, setresgid):
	Likewise.
	* posix/getresuid.c (__getresuid): Fix argument order in definition.
	* posix/getresgid.c (__getresgid): Likewise.
	* posix/setresuid.c (__setresuid): Likewise.
	* posix/setresgid.c (__setresgid): Likewise.
	* sysdeps/mach/hurd/getresuid.c (__getresuid): Likewise.
	* sysdeps/mach/hurd/getresgid.c (__getresgid): Likewise.
	* sysdeps/mach/hurd/setresuid.c (__setresuid): Likewise.
	* sysdeps/mach/hurd/setresgid.c (__setresgid): Likewise.
	Reported by Samuel Thibault <samuel.thibault@ens-lyon.org>.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/unistd.h.diff?cvsroot=glibc&r1=1.143&r2=1.144
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/getresgid.c.diff?cvsroot=glibc&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/setresuid.c.diff?cvsroot=glibc&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/getresuid.c.diff?cvsroot=glibc&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/setresgid.c.diff?cvsroot=glibc&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/mach/hurd/getresgid.c.diff?cvsroot=glibc&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/mach/hurd/setresuid.c.diff?cvsroot=glibc&r1=1.2&r2=1.3
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/mach/hurd/getresuid.c.diff?cvsroot=glibc&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/mach/hurd/setresgid.c.diff?cvsroot=glibc&r1=1.2&r2=1.3
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/include/unistd.h.diff?cvsroot=glibc&r1=1.45&r2=1.46

Comment 11 Roland McGrath 2006-02-21 02:29:04 UTC
Committed on the trunk.  Needed on 2.3 as well.
Comment 12 Samuel Thibault 2007-07-21 20:29:26 UTC
Fixed in head, 2.3 doesn't really matter these days.
Comment 13 Florian Weimer 2016-05-12 15:04:08 UTC
This is subtle enough that it could lead to security issues in applications.  But it is Hurd-specific.