태그 보관물: chown

chown

chown은 setuid 비트를 제거합니다 : 버그 또는 기능? 재현 단계 : germar@host:~$ cd

재현 단계 :

germar@host:~$ cd /tmp/
germar@host:/tmp$ touch test && chmod u+s test && ls -la test
-rwSr--r-- 1 germar germar 0 Nov  2 20:11 test
germar@host:/tmp$ chown germar:germar test && ls -la test
-rw-r--r-- 1 germar germar 0 Nov  2 20:11 test

데비안 스퀴즈와 우분투 12.04 테스트



답변

chown 문서에 따르면 버그가 아닙니다.

$ info coreutils 'chown invocation'

   The `chown' command sometimes clears the set-user-ID or set-group-ID
permission bits.  This behavior depends on the policy and functionality
of the underlying `chown' system call, which may make system-dependent
file mode modifications outside the control of the `chown' command.
For example, the `chown' command might not affect those bits when
invoked by a user with appropriate privileges, or when the bits signify
some function other than executable permission (e.g., mandatory
locking).  When in doubt, check the underlying system behavior.


답변

이것은 의도적으로 설계된 동작이며 표준 동작입니다. POSIX 표준 인용 :

적절한 권한을 가진 프로세스가 chown을 호출하지 않는 한 일반 파일의 set-user-ID 및 set-group-ID 비트는 성공적으로 완료되면 지워집니다. 다른 파일 형식의 set-user-ID 및 set-group-ID 비트가 지워질 수 있습니다.

( s그런데 끈적이지 않은 setuid (또는 그룹 열에서 setgid)입니다.)

이 동작은 기본 시스템 호출 의 동작을 따릅니다 (일부 시스템에서는 setxid 비트가 실행 파일에 대해서만 지워짐).

setuid 비트를 제거하는 이유는 소유자를 변경하면 프로세스의 효과적인 사용자 ID가 될 사용자도 변경하기 때문입니다. 특히, 사용자가 파일을 제공 할 수있는 시스템에서는 cp /bin/sh foo; chmod u+s foo; chown joe foo거대한 보안 허점 인 joe에 속하는 setuid 실행 파일 이 생성됩니다.


답변