* [uml-devel] [patch] 2.4 hostfs no longer mounts specified directory
2004-04-24 10:14 [uml-devel] 2.4 hostfs no longer mounts specified directoryy Henrik Nordstrom
@ 2004-04-24 11:21 ` Henrik Nordstrom
2004-05-04 21:36 ` Jeff Dike
0 siblings, 1 reply; 4+ messages in thread
From: Henrik Nordstrom @ 2004-04-24 11:21 UTC (permalink / raw)
To: user-mode-linux-devel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1254 bytes --]
The attached patch fixes a number of hostfs problems in the current 2.4
tree. With this patch hostfs again has the same capabilities as before the
addition of humfs.
* Use the specified host directory like was done earlier, not hardcoded
to "/"
* Allocate the root directory name. The mount flags is freed by the
kernel.
* host_file.c was missing #include <string.h> (uses strlen, memcpy
etc..) (gcc warnings)
* make all hostfs files owned by root (uid=0), not file owner on the
host.
Todo:
- Give hostfs a real mount structure in the kernel superblock like humfs
has, allowing for storage of various mount flags and not only a root path.
- uid= mount flag to specify what uid the filesystem should be mounted
as inside the uml. [depends on the above]
- use "nobody" as uid if the host file uid is different from the host
uid running the uml. [almost a oneliner, independent of the above but
touches the same area]
Notes:
- The hostfs "jail" option is not very secure in combination with the
ability to specify a root path. One can easily use .. or symlinks to
subvert this. The ability to specify a root path should maybe be disabled
if a jail path is specified. Chrooting would be a much better option.
Regards
Henrik
[-- Attachment #2: Type: TEXT/PLAIN, Size: 6368 bytes --]
Index: arch/um/fs/hostfs/host_file.c
===================================================================
RCS file: /cvsroot/user-mode-linux/linux/arch/um/fs/hostfs/host_file.c,v
retrieving revision 1.1
diff -u -p -r1.1 host_file.c
--- arch/um/fs/hostfs/host_file.c 7 Apr 2004 20:44:01 -0000 1.1
+++ arch/um/fs/hostfs/host_file.c 24 Apr 2004 10:56:19 -0000
@@ -11,6 +11,7 @@
#include <dirent.h>
#include <utime.h>
#include <sys/vfs.h>
+#include <string.h>
#include "os.h"
#include "user.h"
#include "hostfs.h"
Index: arch/um/fs/hostfs/hostfs_user.c
===================================================================
RCS file: /cvsroot/user-mode-linux/linux/arch/um/fs/hostfs/hostfs_user.c,v
retrieving revision 1.23
diff -u -p -r1.23 hostfs_user.c
--- arch/um/fs/hostfs/hostfs_user.c 7 Apr 2004 20:44:02 -0000 1.23
+++ arch/um/fs/hostfs/hostfs_user.c 24 Apr 2004 10:56:19 -0000
@@ -62,7 +62,7 @@ __uml_setup("hostfs=", hostfs_args,
static int access_file(char *file, int uid, int gid, int r, int w, int x,
void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
char tmp[HOSTFS_BUFSIZE];
int err, mode = 0;
@@ -88,7 +88,7 @@ static int mk_nod(const char *file, int
int gr, int gw, int gx, int or, int ow, int ox,
int type, int dev, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
char tmp[HOSTFS_BUFSIZE];
int err = -ENOMEM;
int mode = 0;
@@ -127,30 +127,32 @@ static int stat_file(const char *file, v
unsigned long *ctime_out, int *blksize_out,
unsigned long long *blocks_out)
{
- const char *path[] = { jail_dir, file, NULL };
-
+ const char *path[] = { jail_dir, mount, file, NULL };
+ int uid;
+ *uid_out = 0; /* This should use a mount option */
return(host_stat_file(path, dev_out, inode_out, mode_out, nlink_out,
- uid_out, gid_out, size_out, atime_out, mtime_out,
+ &uid, gid_out, size_out, atime_out, mtime_out,
ctime_out, blksize_out, blocks_out));
+
}
static int file_type(const char *file, int *rdev, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_file_type(path, rdev));
}
static int open_file(char *file, int uid, int gid, int r, int w, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_open_file(path, r, w));
}
static void *open_dir(char *file, int uid, int gid, int *err_out, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_open_dir(path, err_out));
}
@@ -170,7 +172,7 @@ static int file_create(char *file, int u
int gr, int gw, int gx, int or, int ow, int ox,
void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_file_create(path, ur, uw, ux, gr, gw, gx, or, ow, ox));
}
@@ -178,7 +180,7 @@ static int file_create(char *file, int u
static int set_attr(const char *file, struct hostfs_iattr *attrs,
void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_set_attr(path, attrs));
}
@@ -186,28 +188,28 @@ static int set_attr(const char *file, st
static int make_symlink(const char *from, const char *to, int uid, int gid,
void *mount)
{
- const char *path[] = { jail_dir, from, NULL };
+ const char *path[] = { jail_dir, mount, from, NULL };
return(host_make_symlink(path, to));
}
static int unlink_file(const char *file, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_unlink_file(path));
}
static int mk_dir(const char *file, int mode, int uid, int gid, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_mkdir(path, mode));
}
static int rm_dir(const char *file, int uid, int gid, void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_rmdir(path));
}
@@ -215,8 +217,8 @@ static int rm_dir(const char *file, int
static int link_file(const char *to, const char *from, int uid, int gid,
void *mount)
{
- const char *to_path[] = { jail_dir, to, NULL };
- const char *from_path[] = { jail_dir, from, NULL };
+ const char *to_path[] = { jail_dir, mount, to, NULL };
+ const char *from_path[] = { jail_dir, mount, from, NULL };
return(host_link_file(to_path, from_path));
}
@@ -224,15 +226,15 @@ static int link_file(const char *to, con
static int read_link(char *file, int uid, int gid, char *buf, int size,
void *mount)
{
- const char *path[] = { jail_dir, file, NULL };
+ const char *path[] = { jail_dir, mount, file, NULL };
return(host_readlink(path, buf, size));
}
static int rename_file(char *from, char *to, void *mount)
{
- const char *to_path[] = { jail_dir, to, NULL };
- const char *from_path[] = { jail_dir, from, NULL };
+ const char *to_path[] = { jail_dir, mount, to, NULL };
+ const char *from_path[] = { jail_dir, mount, from, NULL };
return(host_rename_file(to_path, from_path));
}
@@ -243,7 +245,7 @@ static int stat_fs(long *bsize_out, long
void *fsid_out, int fsid_size, long *namelen_out,
long *spare_out, void *mount)
{
- const char *path[] = { jail_dir, mount, NULL };
+ const char *path[] = { jail_dir, mount, mount, NULL };
return(host_statfs(path, bsize_out, blocks_out, bfree_out, bavail_out,
files_out, ffree_out, fsid_out, fsid_size,
@@ -279,8 +281,11 @@ static struct externfs_file_ops hostfs_f
static struct externfs_file_ops *mount_fs(char *mount_arg,
void **mount_data_out)
{
- if(host_root_filename(mount_arg, mount_data_out))
+ char *root;
+ if(host_root_filename(mount_arg, &root))
return(NULL);
+
+ *mount_data_out = uml_strdup(root);
return(&hostfs_file_ops);
}
^ permalink raw reply [flat|nested] 4+ messages in thread