LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-24-2018, 11:56 AM   #1
ranshalit
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Rep: Reputation: 0
“ls” shows group owner as “root”, but real gid is different


Hello,

I use both setuid and setgid in a custom init application, for changing uuio and gid. I then create a new filr and write into the file:

The custom init looks something like this:

int main()
{
setuid(101);
setgid(101);
printf("new ownership uid %d gid %d",getuid(),getgid()); **<<-- prints: 101,101 !**
//in the next line we open a file and write into it.
}
Then I checked the files owner, and was surprised to see that: uid = 101 gid = root

On checking the file permissions and owners with "ls" command, I see that the owner group id is "root" (which is the original init ownership), but I was expecting it to be changed to 101 after calling these function!

I also verified with getgid that the new gid is 101 (and also uid is 101, as verified with getuid) , so I don't understand why the file gid as shown by "ls" command shows that the group owner is root (the uid with ls shows 101).

What is the reason that the group ownership is root ?

Thank you for any idea,
ranran

Last edited by ranshalit; 11-24-2018 at 11:58 AM.
 
Old 11-24-2018, 01:16 PM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,286

Rep: Reputation: 218Reputation: 218Reputation: 218
root is uid=gid=0 on my system. What does
Code:
ls -ln
return?
 
Old 11-24-2018, 02:35 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,298

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
If the directory where that file is created has the SETGID bit set in the directory permissions, then the file will inherit the GID of the directory. There is a mount option to suppress that (nogrpid or sysvgroups), but my guess is that's what is happening.
 
Old 11-24-2018, 03:11 PM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,444

Rep: Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902
Quote:
Originally Posted by ranshalit View Post
//in the next line we open a file and write into it.
It is not clear if you create a new file or open an existing one. If it’s the latter, note that opening and writing to an existing file doesn’t change ownership or permissions.
 
  


Reply

Tags
security


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
change of owner and group owner of a file belongs to diff user ? somorg Linux - Newbie 3 06-14-2015 09:11 AM
change of owner and group owner of a file belongs to diff user ? somorg Linux - General 2 06-12-2015 10:40 AM
[SOLVED] Most convenient owner:group owner for directories in /home/regular_user? stf92 Slackware 2 10-26-2014 08:12 AM
Force owner, owner group, permissions... leamassiot Linux - General 8 03-13-2014 04:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration