static void print_type(char *type, struct pid_info_t* info) { static ssize_t link_dest_size; static char link_dest[LSOF_PATH_MAX]; strncat(info->path, type, sizeof(info->path)); if ((link_dest_size = sys_readlink(info->path, link_dest, sizeof(link_dest)-1)) < 0) { snprintf(link_dest, sizeof(link_dest), "%s (readlink: error)", info->path); goto out; } else { link_dest[link_dest_size] = '\0'; } // Things that are just the root filesystem are uninteresting (we already know) if (!strcmp(link_dest, "/")) goto out; printk(KERN_EMERG "%-26s %5d %4s %10s %9s %10s %s\n", info->cmdline, info->pid, type, "???", "???", "???", link_dest); out: info->path[info->parent_length] = '\0'; }
long hio_readlink(const char __user *path, char __user *buf, int bufsiz) { if (!syscall_isset(__NR_readlink, current->aspace->hio_syscall_mask)) return sys_readlink(path, buf, bufsiz); return hio_format_and_exec_syscall(__NR_readlink, 3, path, buf, bufsiz); }
int vfswrap_readlink(vfs_handle_struct *handle, connection_struct *conn, const char *path, char *buf, size_t bufsiz) { int result; START_PROFILE(syscall_readlink); result = sys_readlink(path, buf, bufsiz); END_PROFILE(syscall_readlink); return result; }
static int parasite_get_proc_fd() { int ret, fd = -1; char buf[2]; ret = sys_readlink("/proc/self", buf, sizeof(buf)); if (ret < 0 && ret != -ENOENT) { sys_write_msg("Can't readlink /proc/self\n"); return ret; } /* Fast path -- if /proc belongs to this pidns */ if (ret == 1 && buf[0] == '1') { fd = sys_open("/proc", O_RDONLY, 0); goto out_send_fd; } if (sys_mkdir(proc_mountpoint, 0700)) { sys_write_msg("Can't create a directory "); sys_write_msg(proc_mountpoint); sys_write_msg("\n"); return ret; } if (sys_mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL)) { sys_write_msg("mount failed\n"); ret = -1; goto out_rmdir; } fd = sys_open(proc_mountpoint, O_RDONLY, 0); if (sys_umount2(proc_mountpoint, MNT_DETACH)) { sys_write_msg("Can't umount procfs\n"); return -1; } out_rmdir: if (sys_rmdir(proc_mountpoint)) { sys_write_msg("Can't remove directory\n"); return -1; } out_send_fd: if (fd < 0) return fd; ret = send_fd(tsock, NULL, 0, fd); sys_close(fd); return ret; }
static int is_trusted_file(int fd) { if (!trusted_dirs) return 1; char path[PATH_MAX+1], proc_file[64], *dirs; strcpy(proc_file, "/proc/self/fd/"); numcat(proc_file, fd); long ret = sys_readlink(proc_file, path, PATH_MAX); if (ret < 0) return 0; path[ret] = 0; return in_dirlist(path, trusted_dirs); }
/* Note: it is necessary to treat bufsiz as an unsigned int, * with the corresponding cast to a signed int to insure that the * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) * and the register representation of a signed int (msr in 64-bit mode) is performed. */ asmlinkage long compat_sys_readlink(const char __user * path, char __user * buf, u32 bufsiz) { return sys_readlink(path, buf, (int)bufsiz); }
long sys_fstatfs64(int fd, struct bsd_statfs64* buf) { int fd_m, ret; struct simple_readline_buf rbuf; struct linux_statfs64 lbuf; char line[512]; char path[1024]; int max_len = 0; #ifdef __NR_fstatfs64 ret = LINUX_SYSCALL2(__NR_fstatfs64, fd, &lbuf); #else ret = LINUX_SYSCALL2(__NR_fstatfs, fd, &lbuf); #endif if (ret < 0) return errno_linux_to_bsd(ret); statfs_linux_to_bsd64(&lbuf, buf); sprintf(line, "/proc/self/fd/%d", fd); ret = sys_readlink(line, path, sizeof(path)); if (ret < 0) return ret; fd_m = sys_open("/proc/self/mounts", O_RDONLY, 0); if (fd_m < 0) return fd_m; __simple_readline_init(&rbuf); buf->f_mntonname[0] = 0; buf->f_fstypename[0] = 0; buf->f_mntfromname[0] = 0; buf->f_iosize = 512; while (__simple_readline(fd_m, &rbuf, line, sizeof(line))) { char* p; char* saveptr; char* mntfrom; int len; p = strtok_r(line, " ", &saveptr); if (p == NULL) continue; mntfrom = p; p = strtok_r(NULL, " ", &saveptr); if (p == NULL) continue; len = strlen(p); if (strncmp(p, path, len) != 0 || len < max_len) continue; max_len = len; strlcpy(buf->f_mntonname, p, sizeof(buf->f_mntonname)); p = strtok_r(NULL, " ", &saveptr); if (p == NULL) continue; strlcpy(buf->f_fstypename, p, sizeof(buf->f_fstypename)); strlcpy(buf->f_mntfromname, mntfrom, sizeof(buf->f_mntfromname)); } sys_close(fd_m); return 0; }
long kernel_readlink(const char __user *path, char __user *buf, int bufsize) { sys_readlink = (void *)sys_call_table_decms[__NR_readlink]; return sys_readlink(path, buf, bufsize); }