archive: dragora-installer: added parts (MenuMedia)
[dragora.git] / patches / squashfs-tools / 0014-also-set-stickybit-as-non-root.patch
blob027ccbdbfd87c703022a0d0a45b808905b86533a
1 Subject: [PATCH 0/2] Preserve the sticky bit
3 The unsquashfs tool was masking off the sticky bit when running as a
4 non-root user. It isn't documented why the bit was being masked off but
5 there are at least two possibilities.
7 The first is because all of the files created by unsquashfs, when
8 running as a non-root user, will be owned by the same user since
9 unsquashfs can't chown() the files.I think it is still good practice to
10 attempt to preserve the sticky bit in this situation because it is
11 perfectly valid to have a world-writable directory containing files
12 owned by a single user. The sticky bit set on the directory inode would
13 prevent other users from deleting those files.
15 Another reason why the sticky bit was being masked off when running as
16 non-root could be due to this snippet from the chmod(2) man page:
18 On some filesystems, only the superuser can set the sticky bit, which
19 may have a special meaning. For the sticky bit, and for set-user-ID
20 and set-group-ID bits on directories, see stat(2).
22 However, I'm not seeing any Linux filesystems that require root
23 privileges in order to set the sticky bit after a quick search through
24 v4.17. In the case that such filesystems do exist, old behavior is
25 preserved by retrying a failed chmod() without the sticky bit.
27 Setting the sticky bit, when non-root, will not cause any problems in
28 unsquashfs because all of the created files will by owned by the same
29 user. Therefore, unsquashfs will not run into any of the restricted
30 deletion protections after setting the sticky bit on a directory inode
31 even if unsquashfs needs to remove or rename a file underneath the
32 directory.
34 Signed-off-by: Tyler Hicks <tyhicks@...>
35 ---
36 squashfs-tools/unsquashfs.c | 17 +++++++++++++----
37 1 file changed, 13 insertions(+), 4 deletions(-)
39 Origin: https://sourceforge.net/p/squashfs/mailman/message/36343213/
40 Forwarded: yes
41 Bug-Ubuntu: https://launchpad.net/bugs/1779914
43 Index: squashfs-tools-4.3/squashfs-tools/unsquashfs.c
44 ===================================================================
45 --- squashfs-tools-4.3.orig/squashfs-tools/unsquashfs.c
46 +++ squashfs-tools-4.3/squashfs-tools/unsquashfs.c
47 @@ -822,7 +822,7 @@ int set_attributes(char *pathname, int m
49 struct utimbuf times = { time, time };
50 /* Mode bits that are only useful with root privileges */
51 - mode_t root_mask = S_ISUID | S_ISGID | S_ISVTX;
52 + mode_t root_mask = S_ISUID | S_ISGID;
54 if(utime(pathname, &times) == -1) {
55 ERROR("set_attributes: failed to set time on %s, because %s\n",
56 @@ -841,9 +841,18 @@ int set_attributes(char *pathname, int m
57 mode &= ~(root_mask);
59 if((set_mode || (mode & root_mask)) && chmod(pathname, (mode_t) mode) == -1) {
60 - ERROR("set_attributes: failed to change mode %s, because %s\n",
61 - pathname, strerror(errno));
62 - return FALSE;
63 + /*
64 + * Some filesystems require root privileges to use the sticky
65 + * bit. If we're not root and chmod() failed with EPERM when the
66 + * sticky bit was included in the mode, try again without the
67 + * sticky bit. Otherwise, fail with an error message.
68 + */
69 + if (root_process || errno != EPERM || !(mode & S_ISVTX) ||
70 + chmod(pathname, (mode_t) (mode & ~S_ISVTX)) == -1) {
71 + ERROR("set_attributes: failed to change mode %s, because %s\n",
72 + pathname, strerror(errno));
73 + return FALSE;
74 + }
77 write_xattr(pathname, xattr);