Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:11:40+00:00 2026-05-27T12:11:40+00:00

This is a set-root-uid program $ls -l -rwsr-sr-x 1 root root 7406 2011-12-13 22:37

  • 0

This is a set-root-uid program

$ls -l
-rwsr-sr-x 1 root root 7406 2011-12-13 22:37 ./x*

The source code:

int main(void) {
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

seteuid(600);
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

setuid(1000);

    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

setuid(0); // HOW DOES THIS SUCCEED IN SETTING THE EUID BACK TO 0
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );

    return 0 ;       
}

OUTPUT

         UID           GID  
Real      1000  Real      1000  
Effective 0  Effective 0  
         UID           GID  
Real      1000  Real      1000  
Effective 600  Effective 0  
         UID           GID  
Real      1000  Real      1000  
Effective 1000  Effective 1000  
         UID           GID  
Real      1000  Real      1000  
Effective 0  Effective 1000  

My question

The man page states that setuid will change the real,saved and effective uid.
So after the calling setuid(1000), all three change to 1000.
How is that setuid(0) let’s me change euid to 0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:11:41+00:00Added an answer on May 27, 2026 at 12:11 pm

    There are two cases,

    1. You want to temporarily drop root privilege while executing setuid program
    2. You want to permanently drop root privilege while executing setuid program…
    • You can temporarily do it by setting the euid to the real user id and then changing the uid to anything you want.And later when you need the root privilege back you can setuid to root and the effective userid will change back to root. This is because the saved user id is not changed.
    • You can drop privilege permanently by changing the uid straight away to a lesser privileged user id. After this no matter what you cannot get back the root privilege.

    Case 1:

    After a setuid program starts executing

    1.seteuid(600);
    2.setuid(1000);
    3.setuid(0);
    

    For this case the root privilege can be gained back again.

                  +----+------+------------+
                  | uid|euid  |saved-uid   |
                  |----|------|------------|
                1.|1000| 0    | 0          |
                2.|1000| 600  | 0          |
                3.|1000| 1000 | 0          |
                4.|1000|  0   | 0          |
                  |    |      |            |
                  +------------------------+
    

    Case 2:

    After a setuid program starts executing,

    1.setuid(1000);
    2.setuid(0);
    
    
    
                   +----+------+------------+
                   | uid|euid  |saved-uid   |
                   |----|------|------------|
                 1.|1000|0     | 0          |
                 2.|1000|1000  | 1000       |
                   |    |      |            |
                   +------------------------+
    

    In this case you cannot get back the root privilege.
    This can be verified by the following command,

    cat /proc/PROCID/task/PROCID/status | less

    Uid:    1000    0       0       0
    Gid:    1000    0       0       0
    

    This command will display a Uid and Gid and it will have 4 fields( the first three fields are the one we are concerned with). Something like the above

    The three fields represent uid,euid and saved-user-id. You can introduce a pause (an input from user) in your setuid program and check for each step the cat /proc/PROCID/task/PROCID/status | less command. During each step you can check the saved uid getting changed as mentioned.

    If you’re euid is root and you change the uid, the privileges gets dropped permanently.If effective user id is not root then saved user id is never touched and you can regain the root privilege back anytime you want in your program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With this set of commands, what are the {} and \; characters for? find
We have this set of data that we need to get the average of
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I've completed this set up on a fair few IIS 6 boxes, but one
let's say I have this set of HTML-markup and CSS #CSS .inputhelp_text { background:
I want to insert a vector into a set like this: set<vector<prmEdge> > cammini;
How do i set up a subdomain w/o a TLD? i have this set
The default in Ruby on Rails is to have this set to false (in
I have a set of data, with columns x and y. This set contains
I have a java.util.Set<City> cities and I need to add cities to this set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.