Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5027311

Attempt to setuid java process results in a hang

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • hotspot
    • x86
    • linux



      Name: dk106046 Date: 04/06/2004

      OPERATING SYSTEM(S): LinuxIA32, RHEL 2.1

      FULL JDK VERSION(S): SUN JDK 1.4.2,1.5 beta


      A small C program below uses seteuid to change the effective
      uid for the entire java process (the app runs the java command). The
      problem is that when Java is run this way, it hangs.

      Steps to reproduce:
      runuid -eu 500 java -version

      runuid.cpp:
      #include <stdio.h>
      #include <sys/types.h>
      #include <sys/wait.h>
      #include <unistd.h>
      #include <string.h>
      #include <stdlib.h>
      #include <errno.h>

      int main(int argc, char *argv[], char *envp[])
      {
        char **runArgs = &argv[1];
        char *pgm;
        uid_t id;
        int i;
        int verbose = 0;

        for (i=0; i<3; i++)
        {
          if (!strcmp(*runArgs, "-v"))
          {
            verbose = 1;
            runArgs++;
          }
          else if (!strcmp(*runArgs, "-u"))
          {
            runArgs++;
            id = atoi(*runArgs);
            if (verbose) printf("Setuid %d\n", id);
            if (setuid(id) == -1)
            {
              printf("ERROR: cannot setuid %d, reason: %s\n", id, strerror(errno));
              exit(1);
            }
            runArgs++;
          }
          else if (!strcmp(*runArgs, "-eu"))
          {
            runArgs++;
            id = atoi(*runArgs);
            if (verbose) printf("Seteuid %d\n", id);
            if (seteuid(id) == -1)
            {
              printf("ERROR: cannot seteuid %d, reason: %s\n", id, strerror(errno));
              exit(1);
            }
            runArgs++;
          }
          else if (!strcmp(*runArgs, "-g"))
          {
            runArgs++;
            id = atoi(*runArgs);
            if (verbose) printf("Setgid %d\n", id);
            if (setgid(id) == -1)
            {
              printf("ERROR: cannot setgid %d, reason: %s\n", id, strerror(errno));
              exit(1);
            }
            runArgs++;
          }
          else if (!strcmp(*runArgs, "-eg"))
          {
            runArgs++;
            id = atoi(*runArgs);
            if (verbose) printf("Setegid %d\n", id);
            if (setegid(id) == -1)
            {
              printf("ERROR: cannot setegid %d, reason: %s\n", id, strerror(errno));
              exit(1);
            }
            runArgs++;
          }
          else
            break;
        }
        pgm = *runArgs;
        runArgs;
        if (verbose)
        {
          printf("Execute %s\n", pgm);
          for ( i = 0; *(runArgs+i); i++ )
            printf("args %d=[%s]\n", i, *(runArgs+i));
          for ( i = 0; *(envp+i); i++ )
            printf("envs %d=[%s]\n", i, *(envp+i));
          fflush(stdout);
        }
        i = execvp(pgm, runArgs);
        if (i == -1)
        {
          printf("ERROR: cannot execute %s, reason %s\n", pgm, strerror(errno));
          exit(1);
        }
        return i;
      }


      ======================================================================

            hhuangsunw Hui Huang (Inactive)
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: