Re: Re: [PATCH] usb-storage: don't call utsname()

Previous thread: [2.6 patch] unexport proc_clear_tty by Adrian Bunk on Monday, May 5, 2008 - 11:29 am. (2 messages)

Next thread: [2.6 patch] make sched_feat_{names,open} static by Adrian Bunk on Monday, May 5, 2008 - 11:29 am. (20 messages)
From: Adrian Bunk
Date: Monday, May 5, 2008 - 11:29 am

With the removal of the Solaris binary emulation the export of 
uts_sem became unused.

Signed-off-by: Adrian Bunk <bunk@kernel.org>
Acked-by: David S. Miller <davem@davemloft.net>

---

This patch has been sent on:
- 23 Apr 2008

e15db7b262fd8c3d9000e7d5e7a2b1d720fba8de diff --git a/kernel/sys.c b/kernel/sys.c
index 6a0cc71..773d4a5 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1331,8 +1331,6 @@ EXPORT_SYMBOL(in_egroup_p);
 
 DECLARE_RWSEM(uts_sem);
 
-EXPORT_SYMBOL(uts_sem);
-
 asmlinkage long sys_newuname(struct new_utsname __user * name)
 {
 	int errno = 0;


--

From: Frank Ch. Eigler
Date: Tuesday, May 20, 2008 - 10:16 am

Am I correct that this would makes it invalid for modules to call
utsname() (since the protective semaphore is now hidden)?  Systemtap
has been using them in order to validate the modules it builds against
possible kernel vs. kernel-devel differences.

- FChE
--

From: Christoph Hellwig
Date: Tuesday, May 20, 2008 - 10:27 am

Yesm they should never had done that anyway.  The module support
does it's own version checking already.

--

From: Frank Ch. Eigler
Date: Tuesday, May 20, 2008 - 11:38 am

Hi -


Sorry, I misspoke - this check is intended not to cross-check
kernel-devel and the kernel itself, but the debuginfo or similar data
that is given to describe target of a systemtap script.  I guess for
new enough kernels we'll just do that using buildid hash codes.

By the way, there do appear to be a few suspect in-tree users of
utsname() without uts_sem locking (usb/storage/usb.c, cifs/connect.c,
char/random.cc, fs/lockd/clntproc.c, ...).  If these need to be fixed,
then wouldn't uts_sem need to come back exported?

- FChE
--

From: Christoph Hellwig
Date: Wednesday, May 21, 2008 - 5:37 am

Just a debug printk.  Note sure why this particular one needs to
print the version, but if it really wants to do it it should rather use

This one is quite fishy. Not sure what it needs the name for but the
kernel utsname is probably a bad choise.  And yes, this one actually

random.c is always built-in and utsname is called during the

Yes, this one is racy.  Should probably be fixed by starting lockd
with CLONE_NEWUTS so that it never changed during it's lifetime.
It's probably not a good idea when it changes with outstanding lockd
--

From: Steve French (smfltc)
Date: Wednesday, May 21, 2008 - 7:48 am

CIFS in fs/cifs/sess.c uses utsname()->version because the cifs protocol 
requires that the server and client report their native operating system 
version during session setup (not just their "network operating system" 
or network file system version).   The other uses of utsname()->version 
in connect.c will be removed (they are used in an older implementation 
of session_setup which is disabled by default).

CIFS in fs/cifs/connect.c uses utsname()->nodename to get the default 
hostname during mount.   For RFC1001 connections and for NTLMSSP, if no 
RFC1001 name for the client is supplied on the mount, the TCP host name 
must be used to identify the client in those packets.

--

From: Alan Stern
Date: Wednesday, May 21, 2008 - 10:51 am

This patch (as1100) replaces the core-kernel function call to utsname()
in usb-storage with the UTS_RELEASE macro.  It's used only for warning
about extra unusual_devs entries.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>

---

Index: usb-2.6/drivers/usb/storage/usb.c
===================================================================
--- usb-2.6.orig/drivers/usb/storage/usb.c
+++ usb-2.6/drivers/usb/storage/usb.c
@@ -53,7 +53,7 @@
 #include <linux/slab.h>
 #include <linux/kthread.h>
 #include <linux/mutex.h>
-#include <linux/utsname.h>
+#include <linux/utsrelease.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -531,8 +531,8 @@ static int get_device_info(struct us_dat
 		if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
 			printk(KERN_NOTICE USB_STORAGE "This device "
 				"(%04x,%04x,%04x S %02x P %02x)"
-				" has %s in unusual_devs.h (kernel"
-				" %s)\n"
+				" has %s in unusual_devs.h (kernel "
+				UTS_RELEASE ")\n"
 				"   Please send a copy of this message to "
 				"<linux-usb@vger.kernel.org> and "
 				"<usb-storage@lists.one-eyed-alien.net>\n",
@@ -541,8 +541,7 @@ static int get_device_info(struct us_dat
 				le16_to_cpu(ddesc->bcdDevice),
 				idesc->bInterfaceSubClass,
 				idesc->bInterfaceProtocol,
-				msgs[msg],
-				utsname()->release);
+				msgs[msg]);
 	}
 
 	return 0;

--

From: Greg KH
Date: Wednesday, May 21, 2008 - 11:09 am

Why?  With this change, if you change the version number, the file will
have to be rebuilt.  Without the change, the file will not need to be
rebuilt, right?

I thought that was why this change was made a while ago, to prevent
things from having to be rebuilt that didn't need to be.

thanks,

greg k-h
--

From: Steve French (smfltc)
Date: Wednesday, May 21, 2008 - 11:19 am

I agree - what was wrong with utsname->release ... it seems odd to 
statically build the kernel's version
number into a module - it should be something we should be able to query 
(and it shouldn't change without
reboot so accessing it is not racy).  Access to other fields in the 
structure (nodename, domainname etc.) might
need to be included in a macro but I didn't see one in utsname.h for this.
--

From: Christoph Hellwig
Date: Wednesday, May 21, 2008 - 11:52 am

Because thanks to the container patches it utsname fields other than
hostname can actually change at runtime now and you'll get races looking
at them.  And probably not the output you want if someone in your
container changes the kernel version to trick applications.
--

From: Greg KH
Date: Wednesday, May 21, 2008 - 12:35 pm

So, do we now go and rip out all usages of utsname()->release and put
back the #define just because of the loonacy of containers?

No kernel should have to change it's version number to trick an
application, why would an application care about the version number to
start with?  In the "enterprise kernel" world, version numbers have
little to no relevance on the functionality or features of the kernel,
so any check of something like this is sure to be wrong to start with.

thanks,

greg k-h
--

From: Steve French (smfltc)
Date: Wednesday, May 21, 2008 - 2:01 pm

The version number (of the OS not just of the SMB/CIFS implementation, 
both of which are exchanged by client and server) has sometimes been 
useful in debugging problems that I and others and the Samba team look 
at (you can see it in wireshark/tcpdump traces, and it can be logged 
easily on either end as well).

If containers are crazy enough to change the version number, not just 
the hostname, why don't we simply define a three line macro for 
retrieving this which is safe and put it in utsname.h?
--

Previous thread: [2.6 patch] unexport proc_clear_tty by Adrian Bunk on Monday, May 5, 2008 - 11:29 am. (2 messages)

Next thread: [2.6 patch] make sched_feat_{names,open} static by Adrian Bunk on Monday, May 5, 2008 - 11:29 am. (20 messages)