diff mbox

Disable /dev/port interface on powerpc systems

Message ID 1332308237.23222.49.camel@hbabu-laptop (mailing list archive)
State Superseded
Headers show

Commit Message

Haren Myneni March 21, 2012, 5:37 a.m. UTC
Some power systems do not have legacy ISA devices. So, /dev/port is not
a valid interface on these systems. User level tools such as kbdrate is
trying to access the device using this interface which is causing the
system crash. 

This patch will fix this issue by not creating this interface on these
powerpc systems. 

Signed-off-by: Haren Myneni <haren@us.ibm.com>


diff -Naurp linux.orig/arch/powerpc/kernel/isa-bridge.c
linux/arch/powerpc/kernel/isa-bridge.c
--- linux.orig/arch/powerpc/kernel/isa-bridge.c	2012-02-11
02:08:08.780005293 -0800
+++ linux/arch/powerpc/kernel/isa-bridge.c	2012-02-11 02:16:25.080003386
-0800
@@ -255,6 +255,14 @@ static struct notifier_block isa_bridge_
 	.notifier_call = isa_bridge_notify
 };
 
+int __init legacy_isa_device_found(void)
+{
+	if (isa_bridge_pcidev)
+		return 1;
+	
+	return 0;
+}
+
 /**
  * isa_bridge_init - register to be notified of ISA bridge
addition/removal
  *

Comments

Benjamin Herrenschmidt March 21, 2012, 7:23 a.m. UTC | #1
On Tue, 2012-03-20 at 22:37 -0700, Haren Myneni wrote:
> Some power systems do not have legacy ISA devices. So, /dev/port is not
> a valid interface on these systems. User level tools such as kbdrate is
> trying to access the device using this interface which is causing the
> system crash. 
> 
> This patch will fix this issue by not creating this interface on these
> powerpc systems. 

Doesn't fix 32-bit... not a big deal for now I suppose... But I'd rather
you change the patch a tiny bit to change legacy_isa_device_found() to
arch_has_dev_port() instead. There may be other reason than legacy ISA
to enable dev/port or not so let's make the arch hook more generic.

Another approach which might be even better is to filter per-access,
ie for each read/write to /dev/port, have a hook to check if that
specific port is valid, but that may be overkill for what is
essentially a legacy interface that should have died a long time ago :)

Cheers,
Ben.

> Signed-off-by: Haren Myneni <haren@us.ibm.com>
> 
> 
> diff -Naurp linux.orig/arch/powerpc/kernel/isa-bridge.c
> linux/arch/powerpc/kernel/isa-bridge.c
> --- linux.orig/arch/powerpc/kernel/isa-bridge.c	2012-02-11
> 02:08:08.780005293 -0800
> +++ linux/arch/powerpc/kernel/isa-bridge.c	2012-02-11 02:16:25.080003386
> -0800
> @@ -255,6 +255,14 @@ static struct notifier_block isa_bridge_
>  	.notifier_call = isa_bridge_notify
>  };
>  
> +int __init legacy_isa_device_found(void)
> +{
> +	if (isa_bridge_pcidev)
> +		return 1;
> +	
> +	return 0;
> +}
> +
>  /**
>   * isa_bridge_init - register to be notified of ISA bridge
> addition/removal
>   *
> diff -Naurp linux.orig/drivers/char/mem.c linux/drivers/char/mem.c
> --- linux.orig/drivers/char/mem.c	2012-02-11 02:08:42.710002440 -0800
> +++ linux/drivers/char/mem.c	2012-03-20 20:40:43.650000003 -0700
> @@ -35,6 +35,8 @@
>  # include <linux/efi.h>
>  #endif
>  
> +#define DEVPORT_MINOR	4
> +
>  static inline unsigned long size_inside_page(unsigned long start,
>  					     unsigned long size)
>  {
> @@ -910,6 +912,11 @@ static char *mem_devnode(struct device *
>  
>  static struct class *mem_class;
>  
> +int __init __weak legacy_isa_device_found(void)
> +{
> +	return 1;
> +}
> +
>  static int __init chr_dev_init(void)
>  {
>  	int minor;
> @@ -930,6 +937,13 @@ static int __init chr_dev_init(void)
>  	for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
>  		if (!devlist[minor].name)
>  			continue;
> +
> +		/*
> +		 * Create /dev/port? 
> +		 */
> +		if ((minor == DEVPORT_MINOR) && !legacy_isa_device_found())
> +			continue;
> +
>  		device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
>  			      NULL, devlist[minor].name);
>  	}
> diff -Naurp linux.orig/include/linux/isa.h linux/include/linux/isa.h
> --- linux.orig/include/linux/isa.h	2012-02-11 02:07:52.030019810 -0800
> +++ linux/include/linux/isa.h	2012-02-11 02:16:49.810002296 -0800
> @@ -36,4 +36,5 @@ static inline void isa_unregister_driver
>  }
>  #endif
>  
> +extern int __init legacy_isa_device_found(void);
>  #endif /* __LINUX_ISA_H */
>
Haren Myneni March 21, 2012, 6:58 p.m. UTC | #2
On Wed, 2012-03-21 at 18:23 +1100, Benjamin Herrenschmidt wrote:
> On Tue, 2012-03-20 at 22:37 -0700, Haren Myneni wrote:
> > Some power systems do not have legacy ISA devices. So, /dev/port is not
> > a valid interface on these systems. User level tools such as kbdrate is
> > trying to access the device using this interface which is causing the
> > system crash. 
> > 
> > This patch will fix this issue by not creating this interface on these
> > powerpc systems. 
> 
> Doesn't fix 32-bit... not a big deal for now I suppose... But I'd rather
> you change the patch a tiny bit to change legacy_isa_device_found() to
> arch_has_dev_port() instead. There may be other reason than legacy ISA
> to enable dev/port or not so let's make the arch hook more generic.

Thanks for your suggestions. I will make a change and re-post the patch.

> 
> Another approach which might be even better is to filter per-access,
> ie for each read/write to /dev/port, have a hook to check if that
> specific port is valid, but that may be overkill for what is
> essentially a legacy interface that should have died a long time ago :)

Yes, can be changed open or read/write calls and return -ENODEV,
but /dev/port is no use on these systems.

I am not sure whether any power systems have legacy ISA devices. If we
do not have, CONFIG_DEVPORT can be disabled in Kconfig.

--- 
src/drivers/char/Kconfig.orig	2012-03-21 11:05:54.610010864 -0700
+++ src/drivers/char/Kconfig	2012-03-21 11:02:29.750009886 -0700
@@ -596,6 +596,7 @@ config DEVPORT
 	bool
 	depends on !M68K
 	depends on ISA || PCI
+	depends on !PPC64
 	default y


Thanks
Haren

> 
> Cheers,
> Ben.
> 
> > Signed-off-by: Haren Myneni <haren@us.ibm.com>
> > 
> > 
> > diff -Naurp linux.orig/arch/powerpc/kernel/isa-bridge.c
> > linux/arch/powerpc/kernel/isa-bridge.c
> > --- linux.orig/arch/powerpc/kernel/isa-bridge.c	2012-02-11
> > 02:08:08.780005293 -0800
> > +++ linux/arch/powerpc/kernel/isa-bridge.c	2012-02-11 02:16:25.080003386
> > -0800
> > @@ -255,6 +255,14 @@ static struct notifier_block isa_bridge_
> >  	.notifier_call = isa_bridge_notify
> >  };
> >  
> > +int __init legacy_isa_device_found(void)
> > +{
> > +	if (isa_bridge_pcidev)
> > +		return 1;
> > +	
> > +	return 0;
> > +}
> > +
> >  /**
> >   * isa_bridge_init - register to be notified of ISA bridge
> > addition/removal
> >   *
> > diff -Naurp linux.orig/drivers/char/mem.c linux/drivers/char/mem.c
> > --- linux.orig/drivers/char/mem.c	2012-02-11 02:08:42.710002440 -0800
> > +++ linux/drivers/char/mem.c	2012-03-20 20:40:43.650000003 -0700
> > @@ -35,6 +35,8 @@
> >  # include <linux/efi.h>
> >  #endif
> >  
> > +#define DEVPORT_MINOR	4
> > +
> >  static inline unsigned long size_inside_page(unsigned long start,
> >  					     unsigned long size)
> >  {
> > @@ -910,6 +912,11 @@ static char *mem_devnode(struct device *
> >  
> >  static struct class *mem_class;
> >  
> > +int __init __weak legacy_isa_device_found(void)
> > +{
> > +	return 1;
> > +}
> > +
> >  static int __init chr_dev_init(void)
> >  {
> >  	int minor;
> > @@ -930,6 +937,13 @@ static int __init chr_dev_init(void)
> >  	for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
> >  		if (!devlist[minor].name)
> >  			continue;
> > +
> > +		/*
> > +		 * Create /dev/port? 
> > +		 */
> > +		if ((minor == DEVPORT_MINOR) && !legacy_isa_device_found())
> > +			continue;
> > +
> >  		device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
> >  			      NULL, devlist[minor].name);
> >  	}
> > diff -Naurp linux.orig/include/linux/isa.h linux/include/linux/isa.h
> > --- linux.orig/include/linux/isa.h	2012-02-11 02:07:52.030019810 -0800
> > +++ linux/include/linux/isa.h	2012-02-11 02:16:49.810002296 -0800
> > @@ -36,4 +36,5 @@ static inline void isa_unregister_driver
> >  }
> >  #endif
> >  
> > +extern int __init legacy_isa_device_found(void);
> >  #endif /* __LINUX_ISA_H */
> > 
> 
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>
Benjamin Herrenschmidt March 21, 2012, 8:48 p.m. UTC | #3
On Wed, 2012-03-21 at 11:58 -0700, Haren Myneni wrote:
> 
> Yes, can be changed open or read/write calls and return -ENODEV,
> but /dev/port is no use on these systems.
> 
> I am not sure whether any power systems have legacy ISA devices. If we
> do not have, CONFIG_DEVPORT can be disabled in Kconfig. 

Dome do, older ones mostly.

Cheers,
Ben.
Benjamin Herrenschmidt April 30, 2012, 5 a.m. UTC | #4
On Wed, 2012-03-21 at 18:23 +1100, Benjamin Herrenschmidt wrote:
> On Tue, 2012-03-20 at 22:37 -0700, Haren Myneni wrote:
> > Some power systems do not have legacy ISA devices. So, /dev/port is not
> > a valid interface on these systems. User level tools such as kbdrate is
> > trying to access the device using this interface which is causing the
> > system crash. 
> > 
> > This patch will fix this issue by not creating this interface on these
> > powerpc systems. 
> 
> Doesn't fix 32-bit... not a big deal for now I suppose... But I'd rather
> you change the patch a tiny bit to change legacy_isa_device_found() to
> arch_has_dev_port() instead. There may be other reason than legacy ISA
> to enable dev/port or not so let's make the arch hook more generic.
> 
> Another approach which might be even better is to filter per-access,
> ie for each read/write to /dev/port, have a hook to check if that
> specific port is valid, but that may be overkill for what is
> essentially a legacy interface that should have died a long time ago :)

The more I think about this the less I like it ...

At the end of the day, the bug is in kbdrate (or the distro, whatever)

It's just completely broken to have a bit of userspace running as root
randomly whacking IO ports or MMIO registers based on the assumption
that there must be some kind of ISA kbd controller there... It's going
to break on more than just powerpc (ARM anyone ?).

So kbdrate is busted and needs to be either fixed or removed.

Cheers,
Ben.
diff mbox

Patch

diff -Naurp linux.orig/drivers/char/mem.c linux/drivers/char/mem.c
--- linux.orig/drivers/char/mem.c	2012-02-11 02:08:42.710002440 -0800
+++ linux/drivers/char/mem.c	2012-03-20 20:40:43.650000003 -0700
@@ -35,6 +35,8 @@ 
 # include <linux/efi.h>
 #endif
 
+#define DEVPORT_MINOR	4
+
 static inline unsigned long size_inside_page(unsigned long start,
 					     unsigned long size)
 {
@@ -910,6 +912,11 @@  static char *mem_devnode(struct device *
 
 static struct class *mem_class;
 
+int __init __weak legacy_isa_device_found(void)
+{
+	return 1;
+}
+
 static int __init chr_dev_init(void)
 {
 	int minor;
@@ -930,6 +937,13 @@  static int __init chr_dev_init(void)
 	for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
 		if (!devlist[minor].name)
 			continue;
+
+		/*
+		 * Create /dev/port? 
+		 */
+		if ((minor == DEVPORT_MINOR) && !legacy_isa_device_found())
+			continue;
+
 		device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
 			      NULL, devlist[minor].name);
 	}
diff -Naurp linux.orig/include/linux/isa.h linux/include/linux/isa.h
--- linux.orig/include/linux/isa.h	2012-02-11 02:07:52.030019810 -0800
+++ linux/include/linux/isa.h	2012-02-11 02:16:49.810002296 -0800
@@ -36,4 +36,5 @@  static inline void isa_unregister_driver
 }
 #endif
 
+extern int __init legacy_isa_device_found(void);
 #endif /* __LINUX_ISA_H */