lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 22 Jan 2007 21:13:17 +0100
From:	Johannes Stezenbach <js@...uxtv.org>
To:	Jeff Dike <jdike@...aya.com>
Cc:	user-mode-linux-devel@...ts.sourceforge.net,
	linux-kernel@...r.kernel.org, Andrew Morton <akpm@...l.org>
Subject: [PATCH] [UML] fix mknod

Hi,

I was playing with user-mode Linux and found that mknod creates
devices node in hostfs with wrong major/minor numbers.
The patch below fixes it for me.

Johannes


---
mknod() is broken on UML because userspace has differernt
dev_t size and encoding than kernel.

Signed-off-by: Johannes Stezenbach <js@...uxtv.org>


diff -rup linux-2.6.19.orig/fs/hostfs/hostfs.h linux-2.6.19/fs/hostfs/hostfs.h
--- linux-2.6.19.orig/fs/hostfs/hostfs.h	2006-11-29 22:57:37.000000000 +0100
+++ linux-2.6.19/fs/hostfs/hostfs.h	2007-01-22 20:53:23.000000000 +0100
@@ -76,7 +76,17 @@ extern int make_symlink(const char *from
 extern int unlink_file(const char *file);
 extern int do_mkdir(const char *file, int mode);
 extern int do_rmdir(const char *file);
-extern int do_mknod(const char *file, int mode, int dev);
+
+/* gnu_dev_makedev from glibc's sys/sysmacros.h */
+static inline unsigned long long makedev(unsigned int major, unsigned int minor)
+{
+	return ((minor & 0xff) | ((major & 0xfff) << 8)
+		| (((unsigned long long int) (minor & ~0xff)) << 12)
+		| (((unsigned long long int) (major & ~0xfff)) << 32));
+
+}
+
+extern int do_mknod(const char *file, int mode, unsigned long long dev);
 extern int link_file(const char *from, const char *to);
 extern int do_readlink(char *file, char *buf, int size);
 extern int rename_file(char *from, char *to);
diff -rup linux-2.6.19.orig/fs/hostfs/hostfs_kern.c linux-2.6.19/fs/hostfs/hostfs_kern.c
--- linux-2.6.19.orig/fs/hostfs/hostfs_kern.c	2006-11-29 22:57:37.000000000 +0100
+++ linux-2.6.19/fs/hostfs/hostfs_kern.c	2007-01-22 20:57:58.000000000 +0100
@@ -740,6 +740,7 @@ int hostfs_mknod(struct inode *dir, stru
 	struct inode *inode;
 	char *name;
 	int err = -ENOMEM;
+	unsigned long long udev;
 
 	inode = iget(dir->i_sb, 0);
 	if(inode == NULL)
@@ -755,7 +756,9 @@ int hostfs_mknod(struct inode *dir, stru
 		goto out_put;
 
 	init_special_inode(inode, mode, dev);
-	err = do_mknod(name, mode, dev);
+	/* userspace has different dev_t encoding than kernel... */
+	udev = makedev(MAJOR(dev), MINOR(dev));
+	err = do_mknod(name, mode, udev);
 	if(err)
 		goto out_free;
 
diff -rup linux-2.6.19.orig/fs/hostfs/hostfs_user.c linux-2.6.19/fs/hostfs/hostfs_user.c
--- linux-2.6.19.orig/fs/hostfs/hostfs_user.c	2006-11-29 22:57:37.000000000 +0100
+++ linux-2.6.19/fs/hostfs/hostfs_user.c	2007-01-22 20:54:37.000000000 +0100
@@ -295,7 +295,7 @@ int do_rmdir(const char *file)
 	return(0);
 }
 
-int do_mknod(const char *file, int mode, int dev)
+int do_mknod(const char *file, int mode, unsigned long long dev)
 {
 	int err;
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ