All of lore.kernel.org
 help / color / mirror / Atom feed
* bug in fchownat in n32 and 64 ABIs
@ 2011-10-27 19:07 Bruno Haible
  2011-10-27 19:26 ` David Daney
  0 siblings, 1 reply; 5+ messages in thread
From: Bruno Haible @ 2011-10-27 19:07 UTC (permalink / raw)
  To: bug-gnulib, linux-mips

Hi Linux/MIPS folks,

Found this bug by running the gnulib POSIX test suite: In the fchownat()
call, an uid_t or gid_t of value (uid_t)-1 or (gid_t)-1 means no change.
See <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchownat.html>.
This value is correctly recognized on all Unices, _except_ Linux/MIPS
in n32 and 64 ABIs.

How to reproduce:
==================================== foo.c ====================================
#define _GNU_SOURCE 1
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int
main ()
{
  const char *filename = "foo.c";
  struct stat statbuf;
  int ret;
  int result = 0;

  ret = stat (filename, &statbuf);
  if (ret < 0)
    {
      perror ("stat");
      return 1;
    }
  else
    {
      ret = fchownat (AT_FDCWD, filename, (uid_t)-1, statbuf.st_gid, 0);
      if (ret < 0)
        {
          perror ("fchownat");
          result |= 2;
        }
      ret = fchownat (AT_FDCWD, filename, statbuf.st_uid, (gid_t)-1, 0);
      if (ret < 0)
        {
          perror ("fchownat");
          result |= 4;
        }
      ret = fchownat (AT_FDCWD, filename, (uid_t)-1, (gid_t)-1, 0);
      if (ret < 0)
        {
          perror ("fchownat");
          result |= 8;
        }
    }
  return result;
}
===============================================================================
$ gcc -Wall -mabi=64 foo.c
$ ./a.out ; echo $?
fchownat: Operation not permitted
fchownat: Operation not permitted
fchownat: Operation not permitted
14
$ gcc -Wall -mabi=n32 foo.c
$ ./a.out ; echo $?
fchownat: Operation not permitted
fchownat: Operation not permitted
fchownat: Operation not permitted
14
$ gcc -Wall -mabi=32 foo.c
$ ./a.out ; echo $?

Other relevant data:
- kernel version is 2.6.27.1
- glibc version is 2.7
- gcc version is 4.3.2 (Debian).

'strace' of this program shows that the system call that returns with -1/EPERM
is a call to SYS_6254 (in n32 ABI) or SYS_5250 (in 64 ABI).

Bruno
-- 
In memoriam Helmuth Hübener <http://en.wikipedia.org/wiki/Helmuth_Hübener>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-10-28  0:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-27 19:07 bug in fchownat in n32 and 64 ABIs Bruno Haible
2011-10-27 19:26 ` David Daney
2011-10-27 21:29   ` David Daney
2011-10-27 23:59   ` Bruno Haible
2011-10-28  0:26     ` David Daney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.