LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-18-2011, 05:50 PM   #1
Marcelo Andrade
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Rep: Reputation: 0
setgid + execute unix flag and files


Heya.

I'm writing this about a peculiarity of the activation of both SETGID bit plus EXECUTE bit as unix permissions on FILES (not directories).

It's well known that setting setgid bit on executable programs make that program to be run with the program's gid as effective gid, instead of the user who executed. Allright, no discussion here.

But that also makes the files with those specific permission set 'protected' against copying something that overwrites them, or even simple editing.

I believe you can reproduce this easily on any Linux:
File teste, with unix permissions set as 2770, group owner vboxusers:
Code:
# ls -lan
-rwxrws--- 1 root vboxusers 0 2011-03-17 20:05 teste
I'll use the user USUARIO for this test, which is part of vboxusers group:
Code:
# id USUARIO
uid=USUARIO(123) gid=888(grupo),131(vboxusers)

# su USUARIO
If I try to overwrite the file, or copy something else over it, I get errors:
Code:
$ echo 'texto' > teste
teste: Operation not permited

$ cp /tmp/teste ./
cp: not possible to create common file `./teste': Operation not permited
I can remove the file normally if I want:
Code:
$ rm -v teste
removed `teste'
I believe since of the innate 'danger' of setuid/setgid, this is some kind of colateral 'protection' on the setgid files.

Question is: who implements this? In the system call? Also: is this a well known behaviour? Because I very much looked everywhere and I see no mention to this. Of course I'm not english native, so maybe I'm looking for the wrong keywords. But anyways, anyone ever seen this?
 
Old 03-20-2011, 03:14 AM   #2
bhaslinux
Member
 
Registered: Oct 2003
Location: UnitedKingdom
Distribution: Debian Bullseye
Posts: 357

Rep: Reputation: 49
Although you belong to the vboxusers group, you still are not running as that group.
Can you try
$ newgrp vobxusers

and then repeat your test ?
 
Old 03-21-2011, 07:08 AM   #3
Marcelo Andrade
LQ Newbie
 
Registered: Feb 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bhaslinux View Post
Although you belong to the vboxusers group, you still are not running as that group.
Can you try
$ newgrp vobxusers

and then repeat your test ?
I take you mean by the su. But yeah, this is just a simulation on what happened.

Anyways, I did it as you asked, using newgrp, and still same result.

Just as a sidenote: I'm not trying to 'fix' it, since to be able to overwrite the file all I have to do is to chmod g-s file and it goes back into working as intended. Just trying to figure out what's happening.

For instance, an strace of the copy command trying to overwrite the file gives me the following:
Code:
# strace cp something file
...
open("teste", O_WRONLY|O_TRUNC|O_LARGEFILE) = -1 EPERM (Operation not permitted)
...

Last edited by Marcelo Andrade; 03-21-2011 at 07:30 AM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Samba adds execute flag to all new files the3kgt2 Linux - Server 3 10-20-2011 12:52 PM
Execute Disable Bit (nx flag) alan_ri Linux - Hardware 2 12-17-2010 03:35 AM
Do all these files really need setuid/setgid? jenhu Linux - Security 4 08-03-2008 04:49 AM
setuid + setgid files... jd32 Linux - Security 2 10-16-2004 11:10 AM
newgrp setgid on website files komox Linux - Security 1 09-04-2004 07:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:16 PM.

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
Open Source Consulting | Domain Registration