Commit 7d3a8997 authored by Pavel Emelyanov's avatar Pavel Emelyanov

dump: Check for regfile path being accessible

A file pointed by an fd should be not unlinked
and be open-able with the provided path (overmounts
and/or renames coupled with links can screw it up).
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1f9999a8
......@@ -126,6 +126,32 @@ static int collect_fds(pid_t pid, int *fd, int *nr_fd)
return 0;
}
static int path_accessible(char *path, const struct stat *ost)
{
int ret;
struct stat pst;
if (ost->st_nlink == 0) {
pr_err("Unlinked file opened, can't dump\n");
return 0;
}
ret = stat(path, &pst);
if (ret < 0) {
pr_perror("Can't stat path");
return 0;
}
if ((pst.st_ino != ost->st_ino) || (pst.st_dev != ost->st_dev)) {
pr_err("Unaccessible path opened %u:%u, need %u:%u\n",
(int)pst.st_dev, (int)pst.st_ino,
(int)ost->st_dev, (int)ost->st_ino);
return 0;
}
return 1;
}
static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
{
char fd_str[128];
......@@ -143,6 +169,10 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
pr_info("Dumping path for %lx fd via self %d [%s]\n",
p->fd_name, lfd, big_buffer);
if (p->type == FDINFO_REG &&
!path_accessible(big_buffer, &p->stat))
return -1;
rfe.len = len;
rfe.flags = p->flags;
rfe.pos = p->pos;
......
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