Extend dupfrom(2) into copyfd(2)

This single function allows copying file descriptors from and to
processes, and closing a previously copied remote file descriptor.
This function replaces the five FD-related UDS backcalls. While it
limits the total number of in-flight file descriptors to OPEN_MAX,
this change greatly improves crash recovery support of UDS, since all
in-flight file descriptors will be closed instead of keeping them
open indefinitely (causing VFS to crash on system shutdown). With the
new copyfd call, UDS becomes simpler, and the concept of filps is no
longer exposed outside of VFS.

This patch also moves the checkperms(2) stub into libminlib, thus
fully abstracting away message details of VFS communication from UDS.

Change-Id: Idd32ad390a566143c8ef66955e5ae2c221cff966
This commit is contained in:
David van Moolenbroek
2013-10-05 16:31:35 +02:00
committed by Lionel Sambuc
parent 50685cbec3
commit e5cc85fdc4
20 changed files with 194 additions and 531 deletions

View File

@@ -44,7 +44,8 @@ int mapdriver(char *label, int major, int style, int flags);
pid_t getnpid(endpoint_t proc_ep);
uid_t getnuid(endpoint_t proc_ep);
gid_t getngid(endpoint_t proc_ep);
int dupfrom(endpoint_t endpt, int fd);
int checkperms(endpoint_t endpt, char *path, size_t size);
int copyfd(endpoint_t endpt, int fd, int what);
ssize_t pread64(int fd, void *buf, size_t count, u64_t where);
ssize_t pwrite64(int fd, const void *buf, size_t count, u64_t where);

View File

@@ -1,4 +1,4 @@
#define NCALLS 130 /* number of system calls allowed */
#define NCALLS 125 /* number of system calls allowed */
/* In case it isn't obvious enough: this list is sorted numerically. */
#define EXIT 1
@@ -47,7 +47,7 @@
#define FSTAT 52
#define LSTAT 53
#define IOCTL 54
#define DUPFROM 56
#define COPYFD 56
#define FS_READY 57
#define PIPE2 58
#define EXEC 59
@@ -112,9 +112,4 @@
#define MAPDRIVER 122 /* to VFS, map a device */
#define GETRUSAGE 123 /* to PM, VFS */
#define VFS_UDS_CHECK_PERMS 124 /* to VFS */
#define VFS_UDS_VERIFY_FD 125 /* to VFS */
#define VFS_UDS_SET_FILP 126 /* to VFS */
#define VFS_UDS_COPY_FILP 127 /* to VFS */
#define VFS_UDS_PUT_FILP 128 /* to VFS */
#define VFS_UDS_CANCEL_FD 129 /* to VFS */
#define VFS_CHECKPERMS 124 /* to VFS */

View File

@@ -882,16 +882,18 @@
#define VFS_IOCTL_REQ m2_i3
#define VFS_IOCTL_ARG m2_p1
/* Field names for the UDS backcalls to VFS. */
#define VFS_UDS_ENDPT m2_i1
#define VFS_UDS_GRANT m2_i2
#define VFS_UDS_COUNT m2_i3
#define VFS_UDS_FD m2_i3
#define VFS_UDS_FILP m2_p1
/* Field names for the checkperms(2) call. */
#define VFS_CHECKPERMS_ENDPT m2_i1
#define VFS_CHECKPERMS_GRANT m2_i2
#define VFS_CHECKPERMS_COUNT m2_i3
/* Field names for the dupfrom(2) call. */
#define VFS_DUPFROM_ENDPT m1_i1
#define VFS_DUPFROM_FD m1_i2
/* Field names for the copyfd(2) call. */
#define VFS_COPYFD_ENDPT m1_i1
#define VFS_COPYFD_FD m1_i2
#define VFS_COPYFD_WHAT m1_i3
# define COPYFD_FROM 0 /* copy file descriptor from remote process */
# define COPYFD_TO 1 /* copy file descriptor to remote process */
# define COPYFD_CLOSE 2 /* close file descriptor in remote process */
/* Field names for GETRUSAGE related calls */
#define RU_ENDPT m1_i1 /* indicates a process for sys_getrusage */