LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] [UML] fix mknod
@ 2007-01-22 20:13 Johannes Stezenbach
  2007-01-23  8:02 ` [uml-devel] " Blaisorblade
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Stezenbach @ 2007-01-22 20:13 UTC (permalink / raw)
  To: Jeff Dike; +Cc: user-mode-linux-devel, linux-kernel, Andrew Morton

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@linuxtv.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;
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [uml-devel] [PATCH] [UML] fix mknod
  2007-01-22 20:13 [PATCH] [UML] fix mknod Johannes Stezenbach
@ 2007-01-23  8:02 ` Blaisorblade
  2007-01-23 13:17   ` Johannes Stezenbach
  0 siblings, 1 reply; 6+ messages in thread
From: Blaisorblade @ 2007-01-23  8:02 UTC (permalink / raw)
  To: user-mode-linux-devel
  Cc: Johannes Stezenbach, Jeff Dike, Andrew Morton, linux-kernel

On Monday 22 January 2007 21:13, Johannes Stezenbach wrote:
> 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

Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.

It should be hostfs_user.c to take major and minor and to combine them 
correctly - it can use libc's macros.

> Signed-off-by: Johannes Stezenbach <js@linuxtv.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;
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> User-mode-linux-devel mailing list
> User-mode-linux-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

-- 
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [uml-devel] [PATCH] [UML] fix mknod
  2007-01-23  8:02 ` [uml-devel] " Blaisorblade
@ 2007-01-23 13:17   ` Johannes Stezenbach
  2007-01-23 22:33     ` Blaisorblade
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Stezenbach @ 2007-01-23 13:17 UTC (permalink / raw)
  To: Blaisorblade
  Cc: user-mode-linux-devel, Jeff Dike, Andrew Morton, linux-kernel

On Tue, Jan 23, 2007 at 09:02:30AM +0100, Blaisorblade wrote:
> On Monday 22 January 2007 21:13, Johannes Stezenbach wrote:
> >
> > 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.
> 
> Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
> 
> It should be hostfs_user.c to take major and minor and to combine them 
> correctly - it can use libc's macros.

Right, below is a better patch.


Thanks,
Johannes

---
Fix UML hostfs mknod(): userspace has differernt
dev_t size and encoding than kernel, so extract major/minor
and reencode using glibc makedev() macro.

Signed-off-by: Johannes Stezenbach <js@linuxtv.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-23 14:11:03.000000000 +0100
@@ -76,7 +76,7 @@ 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);
+extern int do_mknod(const char *file, int mode, unsigned int major, unsigned int minor);
 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-23 14:11:20.000000000 +0100
@@ -755,7 +755,7 @@ int hostfs_mknod(struct inode *dir, stru
 		goto out_put;
 
 	init_special_inode(inode, mode, dev);
-	err = do_mknod(name, mode, dev);
+	err = do_mknod(name, mode, MAJOR(dev), MINOR(dev));
 	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-23 14:11:39.000000000 +0100
@@ -295,11 +295,11 @@ 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 int major, unsigned int minor)
 {
 	int err;
 
-	err = mknod(file, mode, dev);
+	err = mknod(file, mode, makedev(major, minor));
 	if(err) return(-errno);
 	return(0);
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [uml-devel] [PATCH] [UML] fix mknod
  2007-01-23 13:17   ` Johannes Stezenbach
@ 2007-01-23 22:33     ` Blaisorblade
  2007-01-25  4:31       ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: Blaisorblade @ 2007-01-23 22:33 UTC (permalink / raw)
  To: Johannes Stezenbach
  Cc: user-mode-linux-devel, Jeff Dike, Andrew Morton, linux-kernel

On Tuesday 23 January 2007 14:17, Johannes Stezenbach wrote:
> On Tue, Jan 23, 2007 at 09:02:30AM +0100, Blaisorblade wrote:
> > On Monday 22 January 2007 21:13, Johannes Stezenbach wrote:
> > > 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.
> >
> > Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.

I've now seen - we never fixed this one, we fixed the analogous problem 
on 'ls' output and friends (in init_inode, which is used in many places).

> > It should be hostfs_user.c to take major and minor and to combine them
> > correctly - it can use libc's macros.
>
> Right, below is a better patch.

Exactly what I meant, thanks!
I'd say:
Acked-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
This can go to 2.6.20, and possibly even to -stable (after either me or Jeff 
tests it once).

> ---
> Fix UML hostfs mknod(): userspace has differernt
> dev_t size and encoding than kernel, so extract major/minor
> and reencode using glibc makedev() macro.
>
> Signed-off-by: Johannes Stezenbach <js@linuxtv.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-23 14:11:03.000000000 +0100 @@
> -76,7 +76,7 @@ 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);
> +extern int do_mknod(const char *file, int mode, unsigned int major,
> unsigned int minor);
> 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-23
> 14:11:20.000000000 +0100 @@ -755,7 +755,7 @@ int hostfs_mknod(struct inode
> *dir, stru
>  		goto out_put;
>
>  	init_special_inode(inode, mode, dev);
> -	err = do_mknod(name, mode, dev);
> +	err = do_mknod(name, mode, MAJOR(dev), MINOR(dev));
>  	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-23
> 14:11:39.000000000 +0100 @@ -295,11 +295,11 @@ 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 int major, unsigned int
> minor) {
>  	int err;
>
> -	err = mknod(file, mode, dev);
> +	err = mknod(file, mode, makedev(major, minor));
>  	if(err) return(-errno);
>  	return(0);
>  }

-- 
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [uml-devel] [PATCH] [UML] fix mknod
  2007-01-23 22:33     ` Blaisorblade
@ 2007-01-25  4:31       ` Andrew Morton
  2007-01-26 18:49         ` Blaisorblade
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2007-01-25  4:31 UTC (permalink / raw)
  To: Blaisorblade
  Cc: Johannes Stezenbach, user-mode-linux-devel, Jeff Dike, linux-kernel

On Tue, 23 Jan 2007 23:33:29 +0100
Blaisorblade <blaisorblade@yahoo.it> wrote:

> On Tuesday 23 January 2007 14:17, Johannes Stezenbach wrote:
> > On Tue, Jan 23, 2007 at 09:02:30AM +0100, Blaisorblade wrote:
> > > On Monday 22 January 2007 21:13, Johannes Stezenbach wrote:
> > > > 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.
> > >
> > > Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
> 
> I've now seen - we never fixed this one, we fixed the analogous problem 
> on 'ls' output and friends (in init_inode, which is used in many places).
> 
> > > It should be hostfs_user.c to take major and minor and to combine them
> > > correctly - it can use libc's macros.
> >
> > Right, below is a better patch.
> 
> Exactly what I meant, thanks!
> I'd say:
> Acked-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
> This can go to 2.6.20, and possibly even to -stable (after either me or Jeff 
> tests it once).

So..  did you test it?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [uml-devel] [PATCH] [UML] fix mknod
  2007-01-25  4:31       ` Andrew Morton
@ 2007-01-26 18:49         ` Blaisorblade
  0 siblings, 0 replies; 6+ messages in thread
From: Blaisorblade @ 2007-01-26 18:49 UTC (permalink / raw)
  To: user-mode-linux-devel
  Cc: Andrew Morton, Jeff Dike, Johannes Stezenbach, linux-kernel

On Thursday 25 January 2007 05:31, Andrew Morton wrote:
> On Tue, 23 Jan 2007 23:33:29 +0100
>
> Blaisorblade <blaisorblade@yahoo.it> wrote:
> > On Tuesday 23 January 2007 14:17, Johannes Stezenbach wrote:
> > > On Tue, Jan 23, 2007 at 09:02:30AM +0100, Blaisorblade wrote:
> > > > On Monday 22 January 2007 21:13, Johannes Stezenbach wrote:
> > > > > 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.
> > > >
> > > > Hmpf. Still having this bug on hostfs is quite bad. Thanks for
> > > > reporting.
> >
> > I've now seen - we never fixed this one, we fixed the analogous problem
> > on 'ls' output and friends (in init_inode, which is used in many places).
> >
> > > > It should be hostfs_user.c to take major and minor and to combine
> > > > them correctly - it can use libc's macros.
> > >
> > > Right, below is a better patch.
> >
> > Exactly what I meant, thanks!
> > I'd say:
> > Acked-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
> > This can go to 2.6.20, and possibly even to -stable (after either me or
> > Jeff tests it once).

> So..  did you test it?

Just tested, I could reproduce the bug and verify the fix works, on 2.6.18; 
and for me it's enough to merge it, considering that little changes happened 
on hostfs, and because it's well understood with static review that this fix 
is needed.

It should also be merged in 2.6.16-stable.
-- 
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-01-26 18:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-22 20:13 [PATCH] [UML] fix mknod Johannes Stezenbach
2007-01-23  8:02 ` [uml-devel] " Blaisorblade
2007-01-23 13:17   ` Johannes Stezenbach
2007-01-23 22:33     ` Blaisorblade
2007-01-25  4:31       ` Andrew Morton
2007-01-26 18:49         ` Blaisorblade

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).