Commit 9f176a96 authored by Ashutosh Mehra's avatar Ashutosh Mehra Committed by Andrei Vagin

Access pathname relative to root of mntns

Use faccessat() in check_path_remap() to check if the file (relative
to root of mnt ns) is accessible or not.
Signed-off-by: 's avatarAshutosh Mehra <asmehra1@in.ibm.com>
parent 31f3a6a7
...@@ -1137,6 +1137,9 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, ...@@ -1137,6 +1137,9 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms,
*/ */
if (pid != 0) { if (pid != 0) {
bool is_dead = strip_deleted(link); bool is_dead = strip_deleted(link);
mntns_root = mntns_get_root_fd(nsid);
if (mntns_root < 0)
return -1;
/* /proc/<pid> will be "/proc/1 (deleted)" when it is /* /proc/<pid> will be "/proc/1 (deleted)" when it is
* dead, but a path like /proc/1/mountinfo won't have * dead, but a path like /proc/1/mountinfo won't have
...@@ -1148,7 +1151,7 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms, ...@@ -1148,7 +1151,7 @@ static int check_path_remap(struct fd_link *link, const struct fd_parms *parms,
*/ */
if (!is_dead) { if (!is_dead) {
*end = 0; *end = 0;
is_dead = access(rpath, F_OK); is_dead = faccessat(mntns_root, rpath, F_OK, 0);
*end = '/'; *end = '/';
} }
......
...@@ -209,6 +209,7 @@ TST_NOFILE := \ ...@@ -209,6 +209,7 @@ TST_NOFILE := \
unlink_multiple_largefiles \ unlink_multiple_largefiles \
config_inotify_irmap \ config_inotify_irmap \
thp_disable \ thp_disable \
pid_file \
# jobctl00 \ # jobctl00 \
ifneq ($(SRCARCH),arm) ifneq ($(SRCARCH),arm)
......
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "zdtmtst.h"
const char *test_doc = "Check that environment didn't change";
const char *test_author = "Andrei Vagin <avagin@gmail.com>";
int main(int argc, char **argv)
{
int fd, fd2;
struct stat st, st2;
test_init(argc, argv);
fd = open("/proc/1/status", O_RDONLY);
if (fd < 0) {
pr_perror("Unable to open /proc/1/status");
return 1;
}
test_daemon();
test_waitsig();
fd2 = open("/proc/1/status", O_RDONLY);
if (fd2 < 0) {
pr_perror("Unable to open /proc/1/status");
return 1;
}
if (fstat(fd, &st)) {
pr_perror("fstat");
return 1;
}
if (fstat(fd2, &st2)) {
pr_perror("fstat");
return 1;
}
close(fd);
close(fd2);
if (st.st_ino != st2.st_ino) {
fail("inode numbers mismatch");
return 1;
}
pass();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment