forked from linux-test-project/ltp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify that statmount() raises EPERM when mount point is not accessible. Signed-off-by: Andrea Cervesato <[email protected]>
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ statmount04 | |
statmount05 | ||
statmount06 | ||
statmount07 | ||
statmount08 |
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,63 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> | ||
*/ | ||
|
||
/*\ | ||
* [Description] | ||
* | ||
* Verify that statmount() raises EPERM when mount point is not accessible. | ||
*/ | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include <pwd.h> | ||
#include "statmount.h" | ||
#include "lapi/stat.h" | ||
|
||
#define MNTPOINT "mntpoint" | ||
|
||
static struct statmount *st_mount; | ||
static uint64_t root_id; | ||
|
||
static void run(void) | ||
{ | ||
if (SAFE_FORK()) | ||
return; | ||
|
||
struct passwd *pw; | ||
|
||
pw = SAFE_GETPWNAM("nobody"); | ||
SAFE_SETEGID(pw->pw_gid); | ||
SAFE_SETEUID(pw->pw_uid); | ||
|
||
memset(st_mount, 0, sizeof(struct statmount)); | ||
|
||
TST_EXP_FAIL(statmount(root_id, STATMOUNT_SB_BASIC, st_mount, | ||
sizeof(struct statmount), 0), EPERM); | ||
|
||
exit(0); | ||
} | ||
|
||
|
||
static void setup(void) | ||
{ | ||
struct ltp_statx sx; | ||
|
||
SAFE_UNSHARE(CLONE_NEWNS); | ||
|
||
SAFE_STATX(AT_FDCWD, "/", 0, STATX_MNT_ID_UNIQUE, &sx); | ||
root_id = sx.data.stx_mnt_id; | ||
} | ||
|
||
static struct tst_test test = { | ||
.test_all = run, | ||
.setup = setup, | ||
.needs_root = 1, | ||
.forks_child = 1, | ||
.min_kver = "6.8", | ||
.bufs = (struct tst_buffers []) { | ||
{&st_mount, .size = sizeof(struct statmount)}, | ||
{} | ||
} | ||
}; |