When does chmod fail?
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
Under what circumstances will chmod
fail?
I looked at the man page but it only specifies usage and doesn't go into details about what circumstances it won't work in.
I'd assume chmod
will work if:
- you're root
- you own the target file (and are setting a mundane mode bit i.e. not sticky bit, others)
Can users use chmod
to change permissions on a file they have group access for? Is it related to read/write access?
ubuntu permissions chmod access-control
add a comment |Â
up vote
8
down vote
favorite
Under what circumstances will chmod
fail?
I looked at the man page but it only specifies usage and doesn't go into details about what circumstances it won't work in.
I'd assume chmod
will work if:
- you're root
- you own the target file (and are setting a mundane mode bit i.e. not sticky bit, others)
Can users use chmod
to change permissions on a file they have group access for? Is it related to read/write access?
ubuntu permissions chmod access-control
2
It will fail if the inode can't be modified, eg the filesystem is read only.
â jordanm
Oct 22 '12 at 4:00
Related: Can I allow users to chmod a file not owned by them?
â Palec
Feb 22 '15 at 22:59
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Under what circumstances will chmod
fail?
I looked at the man page but it only specifies usage and doesn't go into details about what circumstances it won't work in.
I'd assume chmod
will work if:
- you're root
- you own the target file (and are setting a mundane mode bit i.e. not sticky bit, others)
Can users use chmod
to change permissions on a file they have group access for? Is it related to read/write access?
ubuntu permissions chmod access-control
Under what circumstances will chmod
fail?
I looked at the man page but it only specifies usage and doesn't go into details about what circumstances it won't work in.
I'd assume chmod
will work if:
- you're root
- you own the target file (and are setting a mundane mode bit i.e. not sticky bit, others)
Can users use chmod
to change permissions on a file they have group access for? Is it related to read/write access?
ubuntu permissions chmod access-control
ubuntu permissions chmod access-control
edited Aug 3 '16 at 21:28
clk
1,5541821
1,5541821
asked Oct 22 '12 at 1:26
Wug
148116
148116
2
It will fail if the inode can't be modified, eg the filesystem is read only.
â jordanm
Oct 22 '12 at 4:00
Related: Can I allow users to chmod a file not owned by them?
â Palec
Feb 22 '15 at 22:59
add a comment |Â
2
It will fail if the inode can't be modified, eg the filesystem is read only.
â jordanm
Oct 22 '12 at 4:00
Related: Can I allow users to chmod a file not owned by them?
â Palec
Feb 22 '15 at 22:59
2
2
It will fail if the inode can't be modified, eg the filesystem is read only.
â jordanm
Oct 22 '12 at 4:00
It will fail if the inode can't be modified, eg the filesystem is read only.
â jordanm
Oct 22 '12 at 4:00
Related: Can I allow users to chmod a file not owned by them?
â Palec
Feb 22 '15 at 22:59
Related: Can I allow users to chmod a file not owned by them?
â Palec
Feb 22 '15 at 22:59
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
3
down vote
Only the owner of the file, or the root user, may change a file's permissions. The current permissions on the file or on its parent directory are irrelevantù. This is specified in POSIX:
The application shall ensure that the effective user ID of the process matches the owner of the file or the process has appropriate privileges in order to do this.
On most unices, âÂÂappropriate privilegesâ means running as root. If these conditions are not met, chmod
usually fails with EPERM
, though other behaviors such as aborting the program due to a security violation are permitted.
In addition, some unix variants have system-specific ways of authorizing or forbidding chmod
. For example, Linux has a capability (CAP_FOWNER
) that allows processes to change a file's permissions and other metadata regardless of its owner.
There are other reasons chmod
might fail even though the file exists, is accessible and has the appropriate owner. Common ones include a read-only filesystem or a filesystem that does not support permissions such as FAT. Less common ones include system-specific restrictions such as the immutable attribute on Linux's ext2 filesystem and successors.
ù Except insofar as he process running chmod
must be able to access the file, so it must have execute permission on the directory containing the file and any other directory that it traverses to do so.
add a comment |Â
up vote
2
down vote
The details you want are in the manual page for the chmod() system call. Instead of man chmod
use man 2 chmod
. man chattr
and man 2 setxattr
will interest you as well; the file attributes that chattr/setxattr() set augment the behavior of the traditional Unix permissions set by chmod.
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
add a comment |Â
up vote
1
down vote
According to the UNIX standard, "The effective user ID of the process must match the owner of the file or the process must have appropriate privileges in order to do this."
The bit about appropriate privileges needs some explanation. On traditional systems, chmod is allowed on all files when the effective UID (on Linux the filesystem UID, but see below) of the process is 0 [i.e. root].
Linux has a system called capabilities, and the CAP_FOWNER
bit controls the ability to use chmod
on all files. By default, all capabilities are granted when an execve()
call creates a root process (either by executing a setuid binary or when the real UID is 0) or when the effective UID is set to 0 (and removed when it is set to a nonzero value), and a set of capabilities including CAP_FOWNER
are enabled when the filesystem UID is set to 0 (and disabled when it is set to a nonzero value). Read the manpage for more details.
You mentioned the sticky bit, but omitted the fact that users also may not set the setgid bit on a file when they are not in the group that is assigned to the file. The setuid or setgid bit may also be ignored in additional implementation-defined circumstances.
add a comment |Â
up vote
0
down vote
Can users use chmod to change permissions on a file they have group access for?
Why don't you just try and see?
$ touch foo
$ sudo install -o root -g $(id -gn) -m660 foo bar
$ ls -la bar
-rw-rw---- 1 root staff 0 Oct 21 21:33 bar
$ chmod g-w bar
chmod: bar: Operation not permitted
$ chmod g+x bar
chmod: bar: Operation not permitted
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
If you're worried about an edge case, you can (at least to minimize risks) do thechmod
, and then check the permissions on it. If you're feeling paranoid, do anfsync
before checking.
â hexafraction
Oct 22 '12 at 10:32
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Only the owner of the file, or the root user, may change a file's permissions. The current permissions on the file or on its parent directory are irrelevantù. This is specified in POSIX:
The application shall ensure that the effective user ID of the process matches the owner of the file or the process has appropriate privileges in order to do this.
On most unices, âÂÂappropriate privilegesâ means running as root. If these conditions are not met, chmod
usually fails with EPERM
, though other behaviors such as aborting the program due to a security violation are permitted.
In addition, some unix variants have system-specific ways of authorizing or forbidding chmod
. For example, Linux has a capability (CAP_FOWNER
) that allows processes to change a file's permissions and other metadata regardless of its owner.
There are other reasons chmod
might fail even though the file exists, is accessible and has the appropriate owner. Common ones include a read-only filesystem or a filesystem that does not support permissions such as FAT. Less common ones include system-specific restrictions such as the immutable attribute on Linux's ext2 filesystem and successors.
ù Except insofar as he process running chmod
must be able to access the file, so it must have execute permission on the directory containing the file and any other directory that it traverses to do so.
add a comment |Â
up vote
3
down vote
Only the owner of the file, or the root user, may change a file's permissions. The current permissions on the file or on its parent directory are irrelevantù. This is specified in POSIX:
The application shall ensure that the effective user ID of the process matches the owner of the file or the process has appropriate privileges in order to do this.
On most unices, âÂÂappropriate privilegesâ means running as root. If these conditions are not met, chmod
usually fails with EPERM
, though other behaviors such as aborting the program due to a security violation are permitted.
In addition, some unix variants have system-specific ways of authorizing or forbidding chmod
. For example, Linux has a capability (CAP_FOWNER
) that allows processes to change a file's permissions and other metadata regardless of its owner.
There are other reasons chmod
might fail even though the file exists, is accessible and has the appropriate owner. Common ones include a read-only filesystem or a filesystem that does not support permissions such as FAT. Less common ones include system-specific restrictions such as the immutable attribute on Linux's ext2 filesystem and successors.
ù Except insofar as he process running chmod
must be able to access the file, so it must have execute permission on the directory containing the file and any other directory that it traverses to do so.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Only the owner of the file, or the root user, may change a file's permissions. The current permissions on the file or on its parent directory are irrelevantù. This is specified in POSIX:
The application shall ensure that the effective user ID of the process matches the owner of the file or the process has appropriate privileges in order to do this.
On most unices, âÂÂappropriate privilegesâ means running as root. If these conditions are not met, chmod
usually fails with EPERM
, though other behaviors such as aborting the program due to a security violation are permitted.
In addition, some unix variants have system-specific ways of authorizing or forbidding chmod
. For example, Linux has a capability (CAP_FOWNER
) that allows processes to change a file's permissions and other metadata regardless of its owner.
There are other reasons chmod
might fail even though the file exists, is accessible and has the appropriate owner. Common ones include a read-only filesystem or a filesystem that does not support permissions such as FAT. Less common ones include system-specific restrictions such as the immutable attribute on Linux's ext2 filesystem and successors.
ù Except insofar as he process running chmod
must be able to access the file, so it must have execute permission on the directory containing the file and any other directory that it traverses to do so.
Only the owner of the file, or the root user, may change a file's permissions. The current permissions on the file or on its parent directory are irrelevantù. This is specified in POSIX:
The application shall ensure that the effective user ID of the process matches the owner of the file or the process has appropriate privileges in order to do this.
On most unices, âÂÂappropriate privilegesâ means running as root. If these conditions are not met, chmod
usually fails with EPERM
, though other behaviors such as aborting the program due to a security violation are permitted.
In addition, some unix variants have system-specific ways of authorizing or forbidding chmod
. For example, Linux has a capability (CAP_FOWNER
) that allows processes to change a file's permissions and other metadata regardless of its owner.
There are other reasons chmod
might fail even though the file exists, is accessible and has the appropriate owner. Common ones include a read-only filesystem or a filesystem that does not support permissions such as FAT. Less common ones include system-specific restrictions such as the immutable attribute on Linux's ext2 filesystem and successors.
ù Except insofar as he process running chmod
must be able to access the file, so it must have execute permission on the directory containing the file and any other directory that it traverses to do so.
answered Oct 23 '12 at 0:07
Gilles
513k12010161548
513k12010161548
add a comment |Â
add a comment |Â
up vote
2
down vote
The details you want are in the manual page for the chmod() system call. Instead of man chmod
use man 2 chmod
. man chattr
and man 2 setxattr
will interest you as well; the file attributes that chattr/setxattr() set augment the behavior of the traditional Unix permissions set by chmod.
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
add a comment |Â
up vote
2
down vote
The details you want are in the manual page for the chmod() system call. Instead of man chmod
use man 2 chmod
. man chattr
and man 2 setxattr
will interest you as well; the file attributes that chattr/setxattr() set augment the behavior of the traditional Unix permissions set by chmod.
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The details you want are in the manual page for the chmod() system call. Instead of man chmod
use man 2 chmod
. man chattr
and man 2 setxattr
will interest you as well; the file attributes that chattr/setxattr() set augment the behavior of the traditional Unix permissions set by chmod.
The details you want are in the manual page for the chmod() system call. Instead of man chmod
use man 2 chmod
. man chattr
and man 2 setxattr
will interest you as well; the file attributes that chattr/setxattr() set augment the behavior of the traditional Unix permissions set by chmod.
answered Oct 22 '12 at 4:37
Kyle Jones
11.3k13048
11.3k13048
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
add a comment |Â
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
I'll try this when I get out of work.
â Wug
Oct 22 '12 at 12:58
add a comment |Â
up vote
1
down vote
According to the UNIX standard, "The effective user ID of the process must match the owner of the file or the process must have appropriate privileges in order to do this."
The bit about appropriate privileges needs some explanation. On traditional systems, chmod is allowed on all files when the effective UID (on Linux the filesystem UID, but see below) of the process is 0 [i.e. root].
Linux has a system called capabilities, and the CAP_FOWNER
bit controls the ability to use chmod
on all files. By default, all capabilities are granted when an execve()
call creates a root process (either by executing a setuid binary or when the real UID is 0) or when the effective UID is set to 0 (and removed when it is set to a nonzero value), and a set of capabilities including CAP_FOWNER
are enabled when the filesystem UID is set to 0 (and disabled when it is set to a nonzero value). Read the manpage for more details.
You mentioned the sticky bit, but omitted the fact that users also may not set the setgid bit on a file when they are not in the group that is assigned to the file. The setuid or setgid bit may also be ignored in additional implementation-defined circumstances.
add a comment |Â
up vote
1
down vote
According to the UNIX standard, "The effective user ID of the process must match the owner of the file or the process must have appropriate privileges in order to do this."
The bit about appropriate privileges needs some explanation. On traditional systems, chmod is allowed on all files when the effective UID (on Linux the filesystem UID, but see below) of the process is 0 [i.e. root].
Linux has a system called capabilities, and the CAP_FOWNER
bit controls the ability to use chmod
on all files. By default, all capabilities are granted when an execve()
call creates a root process (either by executing a setuid binary or when the real UID is 0) or when the effective UID is set to 0 (and removed when it is set to a nonzero value), and a set of capabilities including CAP_FOWNER
are enabled when the filesystem UID is set to 0 (and disabled when it is set to a nonzero value). Read the manpage for more details.
You mentioned the sticky bit, but omitted the fact that users also may not set the setgid bit on a file when they are not in the group that is assigned to the file. The setuid or setgid bit may also be ignored in additional implementation-defined circumstances.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
According to the UNIX standard, "The effective user ID of the process must match the owner of the file or the process must have appropriate privileges in order to do this."
The bit about appropriate privileges needs some explanation. On traditional systems, chmod is allowed on all files when the effective UID (on Linux the filesystem UID, but see below) of the process is 0 [i.e. root].
Linux has a system called capabilities, and the CAP_FOWNER
bit controls the ability to use chmod
on all files. By default, all capabilities are granted when an execve()
call creates a root process (either by executing a setuid binary or when the real UID is 0) or when the effective UID is set to 0 (and removed when it is set to a nonzero value), and a set of capabilities including CAP_FOWNER
are enabled when the filesystem UID is set to 0 (and disabled when it is set to a nonzero value). Read the manpage for more details.
You mentioned the sticky bit, but omitted the fact that users also may not set the setgid bit on a file when they are not in the group that is assigned to the file. The setuid or setgid bit may also be ignored in additional implementation-defined circumstances.
According to the UNIX standard, "The effective user ID of the process must match the owner of the file or the process must have appropriate privileges in order to do this."
The bit about appropriate privileges needs some explanation. On traditional systems, chmod is allowed on all files when the effective UID (on Linux the filesystem UID, but see below) of the process is 0 [i.e. root].
Linux has a system called capabilities, and the CAP_FOWNER
bit controls the ability to use chmod
on all files. By default, all capabilities are granted when an execve()
call creates a root process (either by executing a setuid binary or when the real UID is 0) or when the effective UID is set to 0 (and removed when it is set to a nonzero value), and a set of capabilities including CAP_FOWNER
are enabled when the filesystem UID is set to 0 (and disabled when it is set to a nonzero value). Read the manpage for more details.
You mentioned the sticky bit, but omitted the fact that users also may not set the setgid bit on a file when they are not in the group that is assigned to the file. The setuid or setgid bit may also be ignored in additional implementation-defined circumstances.
edited Oct 22 '12 at 17:22
answered Oct 22 '12 at 17:15
Random832
8,36012235
8,36012235
add a comment |Â
add a comment |Â
up vote
0
down vote
Can users use chmod to change permissions on a file they have group access for?
Why don't you just try and see?
$ touch foo
$ sudo install -o root -g $(id -gn) -m660 foo bar
$ ls -la bar
-rw-rw---- 1 root staff 0 Oct 21 21:33 bar
$ chmod g-w bar
chmod: bar: Operation not permitted
$ chmod g+x bar
chmod: bar: Operation not permitted
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
If you're worried about an edge case, you can (at least to minimize risks) do thechmod
, and then check the permissions on it. If you're feeling paranoid, do anfsync
before checking.
â hexafraction
Oct 22 '12 at 10:32
add a comment |Â
up vote
0
down vote
Can users use chmod to change permissions on a file they have group access for?
Why don't you just try and see?
$ touch foo
$ sudo install -o root -g $(id -gn) -m660 foo bar
$ ls -la bar
-rw-rw---- 1 root staff 0 Oct 21 21:33 bar
$ chmod g-w bar
chmod: bar: Operation not permitted
$ chmod g+x bar
chmod: bar: Operation not permitted
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
If you're worried about an edge case, you can (at least to minimize risks) do thechmod
, and then check the permissions on it. If you're feeling paranoid, do anfsync
before checking.
â hexafraction
Oct 22 '12 at 10:32
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Can users use chmod to change permissions on a file they have group access for?
Why don't you just try and see?
$ touch foo
$ sudo install -o root -g $(id -gn) -m660 foo bar
$ ls -la bar
-rw-rw---- 1 root staff 0 Oct 21 21:33 bar
$ chmod g-w bar
chmod: bar: Operation not permitted
$ chmod g+x bar
chmod: bar: Operation not permitted
Can users use chmod to change permissions on a file they have group access for?
Why don't you just try and see?
$ touch foo
$ sudo install -o root -g $(id -gn) -m660 foo bar
$ ls -la bar
-rw-rw---- 1 root staff 0 Oct 21 21:33 bar
$ chmod g-w bar
chmod: bar: Operation not permitted
$ chmod g+x bar
chmod: bar: Operation not permitted
answered Oct 22 '12 at 1:36
dubiousjim
1,9581223
1,9581223
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
If you're worried about an edge case, you can (at least to minimize risks) do thechmod
, and then check the permissions on it. If you're feeling paranoid, do anfsync
before checking.
â hexafraction
Oct 22 '12 at 10:32
add a comment |Â
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
If you're worried about an edge case, you can (at least to minimize risks) do thechmod
, and then check the permissions on it. If you're feeling paranoid, do anfsync
before checking.
â hexafraction
Oct 22 '12 at 10:32
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
I have been poking at it, but this is security related and I don't want to accidentally miss an edge case.
â Wug
Oct 22 '12 at 2:43
If you're worried about an edge case, you can (at least to minimize risks) do the
chmod
, and then check the permissions on it. If you're feeling paranoid, do an fsync
before checking.â hexafraction
Oct 22 '12 at 10:32
If you're worried about an edge case, you can (at least to minimize risks) do the
chmod
, and then check the permissions on it. If you're feeling paranoid, do an fsync
before checking.â hexafraction
Oct 22 '12 at 10:32
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f52519%2fwhen-does-chmod-fail%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
It will fail if the inode can't be modified, eg the filesystem is read only.
â jordanm
Oct 22 '12 at 4:00
Related: Can I allow users to chmod a file not owned by them?
â Palec
Feb 22 '15 at 22:59