Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bach states the following:

mkdir is a typical setuid program. Only a process with Effective UID root can create a folder. (Section 7.6, Page 229)

I checked the permissions on it on Ubuntu 12.04, the setuid bit isn't set.

-rwxr-xr-x 1 root root 42624 Oct  2 08:55 mkdir

Then I checked other programs which are supposed to have this set, like ping and su and they have it set.

-rwsr-xr-x 1 root root 34740 Nov  8  2011 ping
   ^---there it is 

So, how does mkdir work? Have things changed since Bach wrote that?

share|improve this question

migrated from Dec 16 '12 at 21:29

This question came from our site for professional and enthusiast programmers.

That may be the case, but it isn't a programming question either. – Hasturkun Dec 16 '12 at 17:20
IIRC, at the time Bach wrote that, there were no separate system calls for directories, open() and read() and write() worked also for directory inodes. With possible diasastrous effects. – wildplasser Dec 16 '12 at 17:46
up vote 5 down vote accepted

The mkdir() call has been around since BSD 4.2. It was later added to SYSV 3.0. See:

BSD 4.2 came out in 1984:

If access to a kernel mode entry point in UNIX via a syscall is permitted from user mode without restriction, what duskwuff indicates, then setuid is not required.

share|improve this answer
Wow, thanks for the links, and the timeline. The older version of mkdir.c you have linked doesn't seem to make the setuid() system call. Is it definitely the right one? – Anirudh Ramanathan Dec 16 '12 at 17:56
That version of mkdir was relatively modern -- it uses mkdir(). – duskwuff Dec 16 '12 at 22:39

It's no longer necessary to have root privileges to create a folder. There's now instead a mkdir() system call which any process can use to create a directory.

share|improve this answer

Have things changed since Bach wrote that?

Exactly. The permission to create a directory is nowadays based on the write permission to the parent directory or the t bit (for /tmp-like directories where everybody can create a directory but you can only delete files owned by you).

share|improve this answer
I agree, but this is regarding permissions on the mkdir executable, not the destination folder. – Anirudh Ramanathan Dec 16 '12 at 17:39
Well, this is exactly what has changed. The permission check hash moved from checking the mkdir executable's setuid bit to the parent dirs write bit for the effective user. – Jens Dec 16 '12 at 17:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .