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

  • Home
  • SEARCH
  • 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 7614769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:29:16+00:00 2026-05-31T02:29:16+00:00

Assume I have a process with PID 1234 running in the background under user

  • 0

Assume I have a process with PID 1234 running in the background under user A.

If I run the following program as user A, it succeeds. If I run it as user B, it fails with open: Permission denied.

This makes sense, as the environ file is owned by user A and has read permission only for A.
But if I make the program set-user-ID for user A and run it as user B, it fails with read: Permission denied. This doesn’t seem to happen with a regular file having the same permissions. It also doesn’t happen if A is root.

Any ideas why? Is there any other way to get the environment of another process that works around this issue?

#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, const char *argv[])
{
    unsigned char ch = 0;
    int fd = -1;
    int read_result = -1;

    setresuid(geteuid(), geteuid(), geteuid());

    fd = open("/proc/1234/environ", O_RDONLY);
    if (-1 == fd) {
        perror("open");
        return EXIT_FAILURE;
    }

    read_result = read(fd, &ch, 1);
    if (-1 == read_result) {
        perror("read");
        return EXIT_FAILURE;
    }

    close(fd);

    return EXIT_SUCCESS;
}
  • 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-31T02:29:17+00:00Added an answer on May 31, 2026 at 2:29 am

    As you can see, if your program run without SETUID, open(2) gives you Permission denied, whereas if you run the program with SETUID, open(2) works ok, but read(2) causes the same error. This happens because of additional permission check during each file operation on /proc/* inodes. Looks like this additional permission check uses something other than EUID of the running process. If you run GNU/Linux, for more details see NOTE at the beginning of the code in <kernel_source>/fs/proc/base.c and environ_read() function in the same file.

    One of the possible quick solutions:

    • set owner of the program file to root
    • set owner group to some special group
    • add user that should run the program (user B) to that special group
    • set mode bits to 4550 (r-sr-x—)
    • call setuid(getuid()) to drop priveleges as soon as possible, i.e. right after reading environ file

    In this case any user from the given group could read /proc/*/environ of any other user.

    If you want to reduce the permissions of your program to allow only read environ files of the specific user (user A), you probably should think of some other tricks. For example config file, containing the user(s) whose environ file(s) could be read.

    Always be careful with extra permissions. Especially with root permissions. Do necessary privileged operations and drop permissions as soon as possible.

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

Sidebar

Related Questions

Assume I have a program that uses argparse to process command line arguments/options. The
Assume I have an executable called 'exe' which spawns a child process. This child
I have been working on AIX and see some of the process ID's running
Let's assume we have following models: from django.db import models class Foo(models.Model): name =
Operating System question: Say we have a process running in a paged memory system,
Assume I have an application, where user can provide script written in JavaScript to
Let's assume we have the following generic scenario: An RDBMS as a data source,
Assume I have simple program (executable compiled from a C program)that provides text information
I have a somewhat large server process written in .net-3.5, that is, running in
Assume I have a class foo, and wish to use a std::map to store

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.