-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syscalls/{f,l,}chown: Don't pass undocumented flags to open and chmod #671
Open
mkow
wants to merge
3
commits into
linux-test-project:master
Choose a base branch
from
mkow:mkow/fix-invalid-open-mode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
/chmod05 | ||
/chmod06 | ||
/chmod07 | ||
/chmod08 |
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,62 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later | ||
* Copyright (C) 2020 Invisible Things Lab | ||
* Michał Kowalczyk <[email protected]> | ||
*/ | ||
|
||
/* | ||
* DESCRIPTION | ||
* Changes file access permissions using `chmod` with bits outside of 07777 in | ||
* `mode` set and verifies if they were ignored. | ||
* | ||
* WARNING | ||
* The fact that these bits are ignored is not documented (at the time of | ||
* writing). Failure of this test doesn't necessarily mean that a regression | ||
* in Linux was introduced, its intention is to catch accidental interface | ||
* changes and warn kernel developers if that happens. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
|
||
#include "tst_test.h" | ||
|
||
#define OPEN_MODE 0644 | ||
#define CHMOD_MODE (0777 | ~07777) | ||
#define TESTFILE "testfile" | ||
|
||
static void test_chmod(void) | ||
{ | ||
struct stat stat_buf; | ||
|
||
TEST(chmod(TESTFILE, CHMOD_MODE)); | ||
if (TST_RET == -1) { | ||
tst_res(TFAIL | TTERRNO, "chmod(%s, %#o) failed", TESTFILE, CHMOD_MODE); | ||
return; | ||
} | ||
|
||
SAFE_STAT(TESTFILE, &stat_buf); | ||
|
||
mode_t expected = S_IFREG | (CHMOD_MODE & 07777); | ||
if (stat_buf.st_mode != expected) { | ||
tst_res(TFAIL, "%s: Incorrect mode 0%04o, expected 0%04o", | ||
TESTFILE, stat_buf.st_mode, expected); | ||
return; | ||
} | ||
tst_res(TPASS, "Unknown mode bits were ignored as expected"); | ||
} | ||
|
||
static void setup(void) | ||
{ | ||
int fd; | ||
|
||
fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, OPEN_MODE); | ||
SAFE_CLOSE(fd); | ||
} | ||
|
||
static struct tst_test test = { | ||
.needs_tmpdir = 1, | ||
.setup = setup, | ||
.test_all = test_chmod, | ||
}; |
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
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
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
/open12_child | ||
/open13 | ||
/open14 | ||
/open15 |
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,53 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later | ||
* Copyright (C) 2020 Invisible Things Lab | ||
* Michał Kowalczyk <[email protected]> | ||
*/ | ||
|
||
/* | ||
* DESCRIPTION | ||
* Creates a file using `open` with bits outside of 07777 in `mode` set and | ||
* verifies if they were ignored. | ||
* | ||
* WARNING | ||
* The fact that these bits are ignored is not documented (at the time of | ||
* writing). Failure of this test doesn't necessarily mean that a regression | ||
* in Linux was introduced, its intention is to catch accidental interface | ||
* changes and warn kernel developers if that happens. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sys/types.h> | ||
|
||
#include "tst_test.h" | ||
|
||
#define TEST_FILE "testfile" | ||
|
||
static struct tcase { | ||
char *filename; | ||
int flags; | ||
mode_t mode; | ||
} tcases[] = { | ||
{TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777}, | ||
{TEST_FILE, 0, ~07777}, | ||
}; | ||
|
||
static void verify_open(unsigned int n) | ||
{ | ||
struct tcase *tc = &tcases[n]; | ||
|
||
TEST(open(tc->filename, tc->flags, tc->mode)); | ||
int fd = TST_RET; | ||
if (fd == -1) { | ||
tst_res(TFAIL | TTERRNO, "Cannot open the file"); | ||
return; | ||
} | ||
tst_res(TPASS, "Unknown mode bits were ignored as expected"); | ||
SAFE_CLOSE(fd); | ||
} | ||
|
||
static struct tst_test test = { | ||
.tcnt = ARRAY_SIZE(tcases), | ||
.needs_tmpdir = 1, | ||
.test = verify_open, | ||
}; |
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 @@ | |
/openat02 | ||
/openat02_child | ||
/openat03 | ||
/openat04 |
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,53 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later | ||
* Copyright (C) 2020 Invisible Things Lab | ||
* Michał Kowalczyk <[email protected]> | ||
*/ | ||
|
||
/* | ||
* DESCRIPTION | ||
* Creates a file using `openat` with bits outside of 07777 in `mode` set and | ||
* verifies if they were ignored. | ||
* | ||
* WARNING | ||
* The fact that these bits are ignored is not documented (at the time of | ||
* writing). Failure of this test doesn't necessarily mean that a regression | ||
* in Linux was introduced, its intention is to catch accidental interface | ||
* changes and warn kernel developers if that happens. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sys/types.h> | ||
|
||
#include "tst_test.h" | ||
|
||
#define TEST_FILE "testfile" | ||
|
||
static struct tcase { | ||
char *filename; | ||
int flags; | ||
mode_t mode; | ||
} tcases[] = { | ||
{TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777}, | ||
{TEST_FILE, 0, ~07777}, | ||
}; | ||
|
||
static void verify_open(unsigned int n) | ||
{ | ||
struct tcase *tc = &tcases[n]; | ||
|
||
TEST(openat(AT_FDCWD, tc->filename, tc->flags, tc->mode)); | ||
int fd = TST_RET; | ||
if (fd == -1) { | ||
tst_res(TFAIL | TTERRNO, "Cannot open the file"); | ||
return; | ||
} | ||
tst_res(TPASS, "Unknown mode bits were ignored as expected"); | ||
SAFE_CLOSE(fd); | ||
} | ||
|
||
static struct tst_test test = { | ||
.tcnt = ARRAY_SIZE(tcases), | ||
.needs_tmpdir = 1, | ||
.test = verify_open, | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openat201 | ||
openat202 | ||
openat203 | ||
/openat201 | ||
/openat202 | ||
/openat203 | ||
/openat204 |
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,60 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later | ||
* Copyright (C) 2020 Invisible Things Lab | ||
* Michał Kowalczyk <[email protected]> | ||
*/ | ||
|
||
/* | ||
* DESCRIPTION | ||
* Creates a file using `openat2` with bits outside of 07777 in `mode` set and | ||
* verifies if they were ignored. | ||
* | ||
* WARNING | ||
* The fact that these bits are ignored is not documented (at the time of | ||
* writing). Failure of this test doesn't necessarily mean that a regression | ||
* in Linux was introduced, its intention is to catch accidental interface | ||
* changes and warn kernel developers if that happens. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sys/types.h> | ||
|
||
#include "tst_test.h" | ||
#include "lapi/openat2.h" | ||
|
||
#define TEST_FILE "testfile" | ||
|
||
static struct tcase { | ||
char *filename; | ||
uint64_t flags; | ||
uint64_t mode; | ||
uint64_t resolve; | ||
} tcases[] = { | ||
{TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777, 0}, | ||
{TEST_FILE, 0, ~07777, 0}, | ||
}; | ||
|
||
static void verify_open(unsigned int n) | ||
{ | ||
struct tcase *tc = &tcases[n]; | ||
struct open_how how = { | ||
.flags = tc->flags, | ||
.mode = tc->mode, | ||
.resolve = tc->resolve, | ||
}; | ||
|
||
TEST(openat2(AT_FDCWD, tc->filename, &how, sizeof(how))); | ||
int fd = TST_RET; | ||
if (fd == -1) { | ||
tst_res(TFAIL | TTERRNO, "Cannot open the file"); | ||
return; | ||
} | ||
tst_res(TPASS, "Unknown mode bits were ignored as expected"); | ||
SAFE_CLOSE(fd); | ||
} | ||
|
||
static struct tst_test test = { | ||
.tcnt = ARRAY_SIZE(tcases), | ||
.needs_tmpdir = 1, | ||
.test = verify_open, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have a safe macros to simplify error handling. So this if () could be replaced and is equivalent to just:
SAFE_STAT(TESTFILE, &stat_buf);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Should I also use
SAFE_CHMOD
above? From what I see these macros are used only for things which shouldn't fail / are unrelated to the test itself, because they useTBROK
instead ofTFAIL
. So, I guess the answer is "no"?