3

I've checked the manpages, the mount, the permissions ...

(edit: combined history into one sequence as requested. Starting to seem a not-simple problem. Nothing new since last edit, just bundled up all pretty)

~/sandbox/6$ editfunc doit
~/sandbox/6$ -x doit
+ doit
+ find
.
+ cp /bin/ln /bin/id .
+ sudo chown jthill:jthill id ln
+ chmod g+s id ln
+ mkdir protected
+ chmod 770 protected
+ touch data
+ set +xv
~/sandbox/6$ ls -A
data  id  ln  protected
~/sandbox/6$ ls -Al
total 92
-rw-r--r-- 1 jthill jthill     0 Nov  8 02:39 data
-rwxr-sr-x 1 jthill jthill 31432 Nov  8 02:39 id
-rwxr-sr-x 1 jthill jthill 56112 Nov  8 02:39 ln
drwxrwx--- 2 jthill jthill  4096 Nov  8 02:39 protected
~/sandbox/6$ sudo su nobody
[nobody@home 6]$ ./id
uid=619(nobody) gid=617(nobody) egid=1000(jthill) groups=617(nobody)
[nobody@home 6]$ ./ln ln protected
./ln: failed to create hard link ‘protected/ln’ => ‘ln’: Operation not permitted
[nobody@home 6]$ ./ln data protected
./ln: failed to create hard link ‘protected/data’ => ‘data’: Operation not permitted
[nobody@home 6]$ ln ln protected
ln: failed to create hard link ‘protected/ln’ => ‘ln’: Permission denied
[nobody@home 6]$ ln data protected
ln: failed to create hard link ‘protected/data’ => ‘data’: Permission denied
[nobody@home 6]$ exit
~/sandbox/6$ 
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
jthill
  • 2,671
  • 12
  • 15

1 Answers1

2

Found it:

  • If sysctl fs/protected_hardlinks is set,
  • hard links by someone not the owner (and without CAP_FOWNER), must be:
    • not special
    • not setuid
    • not executable setgid
    • both readable and writable

according to fs/namei.c. Some guy on SO wanted to have a dropbox folder people could add to but not see into (I think that's a Windows feature), I figured this was one of the few places a setgid would be good and the smoketest drove me here.

Thanks to all and especially Anthon who suggested checking the source.

(edit: sysctl spelling)

jthill
  • 2,671
  • 12
  • 15