Accessibility of swap files
Hi *,
I think, measures can|should be taken, which reduce the probability of having a swap file inadvertently run with too open permissions.
As a first idea, it looks, as if such may be implemented, eg. by
letting swapon [and fstab-based "mounting"] by default not enable a swap
file, if it has non-root access permissions
|| letting mkswap by default ignore too open settings of umask and create the
swap file mod 0600 instead
.
In both cases, an explicit switch|parameter could enable the present, non-restrictive behaviour.
Best regards,
Markus
PS: I'm speaking as of util-linux-ng version 2.17.2.
Quoted 9 lines · On November 6, 2012 at 4:06 PM [email protected] wrote:
Hi *,
I think, measures can|should be taken, which reduce the probability of having a
swap file inadvertently run with too open permissions.As a first idea, it looks, as if such may be implemented, eg. by
letting swapon [and fstab-based "mounting"] by default not enable a swap
file, if it has non-root access permissions
Did you know?
The swapon utility issues a warning diagnostic with --verbose:
# ls -l /tmp/swapfile -rw-r--r-- 1 berny users 134217728 Nov 6 17:03 /tmp/swapfile
# sbin/swapon -v /tmp/swapfile swapon /tmp/swapfile swapon: /tmp/swapfile: insecure permissions 0644, 0600 suggested. swapon: /tmp/swapfile: insecure file owner 1000, 0 (root) suggested. swapon: /tmp/swapfile: found swap signature: version 1, page-size 4, same byte order swapon: /tmp/swapfile: pagesize=4096, swapsize=134217728, devsize=134217728
BTW: the check for the owner has been added in 2.19 (in commit v2.18-88-g306c1df).
I don't know if refusing to swapon insecure swap files is a good idea (see below).
Quoted 3 lines
|| letting mkswap by default ignore too open settings of umask and create
the
swap file mod 0600 instead.
You don't need root privs to run mkswap. Furthermore, mkswap doesn't create the swap file (in terms of calling creat()). Instead, it just writes to it.
Nevertheless, I think a warning would be enough/nice at this stage.
Quoted 2 lines
In both cases, an explicit switch|parameter could enable the present, non-restrictive behaviour.
Changing behavior is not always a good idea for compatibility reasons, and therefore deserves *good* arguments.
Let Karel decide.
Quoted 1 line
PS: I'm speaking as of util-linux-ng version 2.17.2.
I'm speaking about the latest version in Git. ;-)
Have a nice day,
Berny
Karel Zak
maintainerQuoted 6 lines · Bernhard Voelker
Quoted 5 lines · On November 6, 2012 at 4:06 PM [email protected] wrote:
Hi *,
I think, measures can|should be taken, which reduce the probability of having a
swap file inadvertently run with too open permissions.
well, you need root permissions to use swapon, the swap devices and files are defined in /etc/fstan which is writable by root only.
I have doubts that we have to make the system so paranoid and resistant to admin's bugs. And if you really need this level of paranoia then use SELinux (or so) rather than expect hardcoded rules in swapon(8).
Quoted 10 lines
Quoted 3 lines
As a first idea, it looks, as if such may be implemented, eg. by
letting swapon [and fstab-based "mounting"] by default not enable a swap
file, if it has non-root access permissionsDid you know?
The swapon utility issues a warning diagnostic with --verbose:# ls -l /tmp/swapfile -rw-r--r-- 1 berny users 134217728 Nov 6 17:03 /tmp/swapfile
Quoted 7 lines
# sbin/swapon -v /tmp/swapfile swapon /tmp/swapfile swapon: /tmp/swapfile: insecure permissions 0644, 0600 suggested. swapon: /tmp/swapfile: insecure file owner 1000, 0 (root) suggested. swapon: /tmp/swapfile: found swap signature: version 1, page-size 4, same byte order swapon: /tmp/swapfile: pagesize=4096, swapsize=134217728, devsize=134217728
this waring is there since year 1999.. so it's really nothing new.
Quoted 9 lines
BTW: the check for the owner has been added in 2.19 (in commit v2.18-88-g306c1df).
I don't know if refusing to swapon insecure swap files is a good idea (see below).
Quoted 3 lines
|| letting mkswap by default ignore too open settings of umask and create
the
swap file mod 0600 instead.
sorry, this is nonsense
Quoted 2 lines
You don't need root privs to run mkswap. Furthermore, mkswap doesn't create the swap file (in terms of calling
creat()).
yep, you can use cp(1) or dd(1) to create the file as a copy...
Quoted 8 lines
Instead, it just writes to it.
Nevertheless, I think a warning would be enough/nice at this stage.Quoted 2 lines
In both cases, an explicit switch|parameter could enable the present, non-restrictive behaviour.
Changing behavior is not always a good idea for compatibility reasons, and therefore deserves *good* arguments.
Yes, I don't see good arguments.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 20 lines · Karel Zak
Quoted 11 lines · Bernhard Voelker
Quoted 3 lines · On November 6, 2012 at 4:06 PM [email protected] wrote:
As a first idea, it looks, as if such may be implemented, eg. by
letting swapon [and fstab-based "mounting"] by default not enable a swap
file, if it has non-root access permissionsDid you know?
The swapon utility issues a warning diagnostic with --verbose:# ls -l /tmp/swapfile -rw-r--r-- 1 berny users 134217728 Nov 6 17:03 /tmp/swapfileQuoted 7 lines
# sbin/swapon -v /tmp/swapfile swapon /tmp/swapfile swapon: /tmp/swapfile: insecure permissions 0644, 0600 suggested. swapon: /tmp/swapfile: insecure file owner 1000, 0 (root) suggested. swapon: /tmp/swapfile: found swap signature: version 1, page-size 4, same byte order swapon: /tmp/swapfile: pagesize=4096, swapsize=134217728, devsize=134217728
Quoted 1 line
this waring is there since year 1999.. so it's really nothing new.
I wonder would be be too noisy to make insecurity warnings enabled by default, and add --quiet option to thous who do not want to hear system complaining about things they know.
Karel Zak
maintainerQuoted 21 lines · Sami Kerola
Quoted 20 lines · Karel Zak
Quoted 18 lines · Bernhard Voelker
Quoted 3 lines · On November 6, 2012 at 4:06 PM [email protected] wrote:
As a first idea, it looks, as if such may be implemented, eg. by
letting swapon [and fstab-based "mounting"] by default not enable a swap
file, if it has non-root access permissionsDid you know?
The swapon utility issues a warning diagnostic with --verbose:# ls -l /tmp/swapfile -rw-r--r-- 1 berny users 134217728 Nov 6 17:03 /tmp/swapfile# sbin/swapon -v /tmp/swapfile swapon /tmp/swapfile swapon: /tmp/swapfile: insecure permissions 0644, 0600 suggested. swapon: /tmp/swapfile: insecure file owner 1000, 0 (root) suggested. swapon: /tmp/swapfile: found swap signature: version 1, page-size 4, same byte order swapon: /tmp/swapfile: pagesize=4096, swapsize=134217728, devsize=134217728
Quoted 6 lines
Quoted 1 line
this waring is there since year 1999.. so it's really nothing new.
I wonder would be be too noisy to make insecurity warnings enabled by default, and add --quiet option to thous who do not want to hear system complaining about things they know.
since util-linux 2.9t:
/* people generally dislike this warning - now it is printed
only when `verbose' is set */
:-)
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com