-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't fail to apply umask for O_TMPFILE files
Apply umask to `mode` which will eventually be applied to inode. This is needed since VFS doesn't apply umask for O_TMPFILE files. (Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();` only when POSIX ACL is used.) Signed-off-by: Tomohiro Kusumi <[email protected]>
- Loading branch information
Showing
5 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/tmpfile_001_pos | ||
/tmpfile_002_pos | ||
/tmpfile_003_pos | ||
/tmpfile_stat_mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
tests/zfs-tests/tests/functional/tmpfile/tmpfile_stat_mode.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
|
||
/* backward compat in case it's not defined */ | ||
#ifndef O_TMPFILE | ||
#define O_TMPFILE (020000000|O_DIRECTORY) | ||
#endif | ||
|
||
/* | ||
* DESCRIPTION: | ||
* Verify stat(2) for O_TMPFILE file considers umask. | ||
* | ||
* STRATEGY: | ||
* 1. open(2) with O_TMPFILE. | ||
* 2. linkat(2). | ||
* 3. fstat(2)/stat(2) and verify .st_mode value. | ||
*/ | ||
|
||
static void | ||
test_stat(mode_t mask) | ||
{ | ||
struct stat st, fst; | ||
int i, fd; | ||
char spath[1024], dpath[1024]; | ||
char *penv[] = {"TESTDIR", "TESTFILE0"}; | ||
mode_t masked = 0777 & ~mask; | ||
mode_t mode; | ||
|
||
/* | ||
* Get the environment variable values. | ||
*/ | ||
for (i = 0; i < sizeof (penv) / sizeof (char *); i++) { | ||
if ((penv[i] = getenv(penv[i])) == NULL) { | ||
fprintf(stderr, "getenv(penv[%d])\n", i); | ||
exit(1); | ||
} | ||
} | ||
|
||
umask(mask); | ||
fd = open(penv[0], O_RDWR|O_TMPFILE, 0666); | ||
if (fd == -1) { | ||
perror("open"); | ||
exit(2); | ||
} | ||
|
||
if (fstat(fd, &fst) == -1) { | ||
perror("fstat"); | ||
close(fd); | ||
exit(3); | ||
} | ||
|
||
snprintf(spath, sizeof (spath), "/proc/self/fd/%d", fd); | ||
snprintf(dpath, sizeof (dpath), "%s/%s", penv[0], penv[1]); | ||
|
||
unlink(dpath); | ||
if (linkat(AT_FDCWD, spath, AT_FDCWD, dpath, AT_SYMLINK_FOLLOW) == -1) { | ||
perror("linkat"); | ||
close(fd); | ||
exit(4); | ||
} | ||
close(fd); | ||
|
||
if (stat(dpath, &st) == -1) { | ||
perror("stat"); | ||
exit(5); | ||
} | ||
unlink(dpath); | ||
|
||
/* Verify fstat(2) result */ | ||
mode = fst.st_mode & 0777; | ||
if (mode != masked) { | ||
fprintf(stderr, "fstat(2) %o != %o\n", mode, masked); | ||
exit(6); | ||
} | ||
|
||
/* Verify stat(2) result */ | ||
mode = st.st_mode & 0777; | ||
if (mode != masked) { | ||
fprintf(stderr, "stat(2) %o != %o\n", mode, masked); | ||
exit(7); | ||
} | ||
} | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
fprintf(stdout, "Verify stat(2) for O_TMPFILE file considers umask.\n"); | ||
|
||
test_stat(0022); | ||
test_stat(0077); | ||
|
||
return (0); | ||
} |