sensors-detect: Skip "random" I/O port probing
PATCH 1/1 sensors-detect: Skip "random" I/O port probing
Hi all,
As a follow-up of this discussion on LKML:
http://lkml.org/lkml/2008/2/13/390
I would like to propose the following patch to sensors-detect:
Index: prog/detect/sensors-detect
=================================--- prog/detect/sensors-detect (révision 5123)
+++ prog/detect/sensors-detect (copie de travail)
@@ -3,7 +3,7 @@
#
# sensors-detect - Detect PCI bus and chips # Copyright (C) 1998 - 2002 Frodo Looijaard <[email protected]> -# Copyright (C) 2004 - 2007 Jean Delvare <[email protected]> +# Copyright (C) 2004 - 2008 Jean Delvare <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -2366,12 +2366,13 @@
# [2] -> SUBLEVEL
# [3] -> EXTRAVERSION
#
-use vars qw(@kernel_version);
+use vars qw(@kernel_version $kernel_arch);
sub initialize_kernel_version
{
uname -r =~ /(\d+)\.(\d+)\.(\d+)(.*)/;
@kernel_version = ($1, $2, $3, $4);
+ $kernel_arch = uname -m;
}
sub kernel_version_at_least
@@ -5810,27 +5811,32 @@
}
print "\n";
- print "Some chips are also accessible through the ISA I/O ports. We have to\n".
- "write to arbitrary I/O ports to probe them. This is usually safe though.\n".
- "Yes, you do have ISA I/O ports even if you do not have any ISA slots!\n";
- print "Do you want to scan the ISA I/O ports? (YES/no): ";
- unless (<STDIN> =~ /^\s*n/i) {
- initialize_ioports(); - scan_isa_bus(); - close_ioports(); - } - print "\n"; + # Skip "random" I/O port probing on PPC + if ($kernel_arch ne 'ppc'
+ && $kernel_arch ne 'ppc64'
+ && $kernel_arch ne 'powerpc') {
+ print "Some chips are also accessible through the ISA I/O ports. We have to\n".
+ "write to arbitrary I/O ports to probe them. This is usually safe though.\n".
+ "Yes, you do have ISA I/O ports even if you do not have any ISA slots!\n";
+ print "Do you want to scan the ISA I/O ports? (YES/no): ";
+ unless (<STDIN> =~ /^\s*n/i) {
+ initialize_ioports(); + scan_isa_bus(); + close_ioports();
+ }
+ print "\n";
- print "Some Super I/O chips may also contain sensors. We have to write to\n".
- "standard I/O ports to probe them. This is usually safe.\n";
- print "Do you want to scan for Super I/O sensors? (YES/no): ";
- unless (<STDIN> =~ /^\s*n/i) {
- initialize_ioports();
- scan_superio(0x2e, 0x2f);
- scan_superio(0x4e, 0x4f);
- close_ioports();
+ print "Some Super I/O chips may also contain sensors. We have to write to\n".
+ "standard I/O ports to probe them. This is usually safe.\n";
+ print "Do you want to scan for Super I/O sensors? (YES/no): ";
+ unless (<STDIN> =~ /^\s*n/i) {
+ initialize_ioports();
+ scan_superio(0x2e, 0x2f);
+ scan_superio(0x4e, 0x4f);
+ close_ioports();+ }
+ print "\n";
}
- print "\n";
print "Some CPUs or memory controllers may also contain embedded sensors.\n"; print "Do you want to scan for them? (YES/no): ";
The idea is to skip "random" I/O port probing on PPC, as it won't find anything anyway and can cause the kernel to oops.
Christian, can you please test this patch and confirm that it solves your problem?
Ben, can you please comment on this patch? I'm not familiar with the PPC architecture at all so I'm not sure if I am looking for the right strings.
Thanks,
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
Quoted 2 lines · Jean Delvare
The idea is to skip "random" I/O port probing on PPC, as it won't find anything anyway and can cause the kernel to oops.
To be more precise, it can cause the chip to access random parts of the address space that will result in machine checks or worse.
The fact that it oopses instead of SIGBUS is an unfortunate side effect of those accesses being done by the kernel and not by userland, and not being marked as recoverable in the exception tables. We could try to fix -that- though it would still be fairly unreliable as that sort of machine check tends to be asynchronous, and that wouldn't fix the problem that on non-x86 arch, it's not uncommon to have completely different bits of HW around those ports.
So I believe the only thing that should be allowed on powerpc is to probe "known" areas, that is, places where you know there is something to be found, typically via the device-tree provided by the platform or the firmware.
Quoted 6 lines
Christian, can you please test this patch and confirm that it solves your problem?
Ben, can you please comment on this patch? I'm not familiar with the PPC architecture at all so I'm not sure if I am looking for the right strings.
I think ppc and ppc64 are what you get.
Cheers,
Ben.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 11 lines · Jean Delvare
Hi all,
As a follow-up of this discussion on LKML:
http://lkml.org/lkml/2008/2/13/390
I would like to propose the following patch to sensors-detect:
(...)
The idea is to skip "random" I/O port probing on PPC, as it won't find anything anyway and can cause the kernel to oops.Christian, can you please test this patch and confirm that it solves your problem?
My patch wasn't correct, I forgot to chomp the trailing new line returned by uname -m. I've just committed a working fix to SVN, please try this instead.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareHi Jean,
I will try to test your patch today, but only have a little time for this. If I'm not getting it today, I'll continue next monday.
I'm not very convinced, that this is the right solution, but as a circumvention, it will take the pressure away.
Cheers,
Christian
Quoted 17 lines · On Wed, 20 Feb 2008 20:07:42 +0100 Jean Delvare <[email protected]> wrote:
Quoted 11 lines · Jean Delvare
Hi all,
As a follow-up of this discussion on LKML:
http://lkml.org/lkml/2008/2/13/390
I would like to propose the following patch to sensors-detect:
(...)
The idea is to skip "random" I/O port probing on PPC, as it won't find anything anyway and can cause the kernel to oops.Christian, can you please test this patch and confirm that it solves your problem?
My patch wasn't correct, I forgot to chomp the trailing new line returned by uname -m. I've just committed a working fix to SVN, please try this instead.
Signature · 13 lines
Mit freundlichen Gruessen, kind regards, Christian Krafft IBM Systems & Technology Group, Linux Kernel Development IT Specialist Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Herbert Kircher Sitz der Gesellschaft: Boeblingen Registriergericht: Amtsgericht Stuttgart, HRB 243294
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 2 lines · Christian Krafft
I will try to test your patch today, but only have a little time for this. If I'm not getting it today, I'll continue next monday.
Note that I managed to test the SVN version of sensors-detect myself (on ppc64) so I am confident that it works well now.
Quoted 2 lines
I'm not very convinced, that this is the right solution, but as a circumvention, it will take the pressure away.
What do you think would be the right solution? I agree that making /dev/port access safer at the kernel level is still needed. Do you have anything else in mind?
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 7 lines · Jean Delvare
Quoted 2 lines · Christian Krafft
I will try to test your patch today, but only have a little time for this. If I'm not getting it today, I'll continue next monday.
Note that I managed to test the SVN version of sensors-detect myself (on ppc64) so I am confident that it works well now.
Quoted 6 lines
Quoted 2 lines
I'm not very convinced, that this is the right solution, but as a circumvention, it will take the pressure away.
What do you think would be the right solution? I agree that making
/dev/portaccess safer at the kernel level is still needed. Do you have anything else in mind?
"safer" how so ?
How can the kernel differenciate between valid and non valid uses of it ?
Ben.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 12 lines · Benjamin Herrenschmidt
Quoted 10 lines · Jean Delvare
Quoted 2 lines · Christian Krafft
I will try to test your patch today, but only have a little time for this. If I'm not getting it today, I'll continue next monday.
Note that I managed to test the SVN version of sensors-detect myself (on ppc64) so I am confident that it works well now.
Quoted 2 lines
I'm not very convinced, that this is the right solution, but as a circumvention, it will take the pressure away.
Quoted 8 lines
Quoted 3 lines
What do you think would be the right solution? I agree that making
/dev/portaccess safer at the kernel level is still needed. Do you have anything else in mind?"safer" how so ?
How can the kernel differenciate between valid and non valid uses of it ?
I was referring to the kernel patch Christian submitted earlier this week which prevents oopses or machine checks when older versions of sensors-detect access /dev/port in unexpected ways. My update to sensors-detect was meant as a complement of his patch, not a replacement.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 6 lines · Jean Delvare
I was referring to the kernel patch Christian submitted earlier this week which prevents oopses or machine checks when older versions of sensors-detect access
/dev/portin unexpected ways. My update to sensors-detect was meant as a complement of his patch, not a replacement.
But his patch can't recognize a potentially valid use of /proc/port right ?
Christian, can you re-send me that patch ?
Ben.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jean Delvare
I was referring to the kernel patch Christian submitted earlier this week which prevents oopses or machine checks when older versions of sensors-detect access
/dev/portin unexpected ways. My update to sensors-detect was meant as a complement of his patch, not a replacement.But his patch can't recognize a potentially valid use of
/proc/portright ?
I don't know much about PPC so I can't comment on the implementation. All I'm saying is that, if it is possible at all, I believe that preventing invalid accesses from oopsing the machine is a good idea.
Quoted 1 line
Christian, can you re-send me that patch ?
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareHi Ben,
regarding your problem with poking into PCI ranges:
As arnd mentioned, we could check, wether there is a mapping for that address and if so, allow the access. That could be done in check_legacy_ioport, although the name looks a bit misleading.
What do you think ?
Quoted 4 lines · On Fri, 22 Feb 2008 18:21:23 +1100 Benjamin Herrenschmidt…
Christian, can you re-send me that patch ?
Ben.
Sure, patch was as trivial as this:
sensors_detect crashes kernel on PowerPC, as it pokes directly to memory. This patch adds a check_legacy_ioports to read_port and write_port. It will now return ENXIO, instead of oopsing.
drivers/char/mem.c +11 -1
@@ -566,8 +566,13 @@ static ssize_t read_port(struct file * fchar __user *tmp = buf;if (!access_ok (VERIFY_WRITE , buf, count)) -return -EFAULT ; +return -EFAULT ; +while (count-- >0 && i <65536 ) { +#ifdef CONFIG_PPC_MERGE +if (check_legacy_ioport (i)) +return -ENXIO ; +#endif if (__put_user (inb (i),tmp) <0 )return -EFAULT ; i++;
@@ -585,6 +590,7 @@ static ssize_t write_port(struct file *if (!access_ok (VERIFY_READ ,buf,count))return -EFAULT ; +while (count-- >0 && i <65536 ) {char c;if (__get_user (c, tmp)) {
@@ -592,6 +598,10 @@ static ssize_t write_port(struct file *break ;return -EFAULT ; } +#ifdef CONFIG_PPC_MERGE +if (check_legacy_ioport (i)) +return -ENXIO ; +#endif outb (c,i); i++; tmp++;
Signature · 13 lines
Mit freundlichen Gruessen, kind regards, Christian Krafft IBM Systems & Technology Group, Linux Kernel Development IT Specialist Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Herbert Kircher Sitz der Gesellschaft: Boeblingen Registriergericht: Amtsgericht Stuttgart, HRB 243294
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O port
In reply to Jean DelvareQuoted 10 lines · Jean Delvare
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jean Delvare
I was referring to the kernel patch Christian submitted earlier this week which prevents oopses or machine checks when older versions of sensors-detect access
/dev/portin unexpected ways. My update to sensors-detect was meant as a complement of his patch, not a replacement.
Quoted 6 lines
Quoted 2 lines
But his patch can't recognize a potentially valid use of
/proc/portright ?I don't know much about PPC so I can't comment on the implementation. All I'm saying is that, if it is possible at all, I believe that preventing invalid accesses from oopsing the machine is a good idea.
Preventing root from doing something stupid is not worth bothering.
I don't see how you can effectively prevent invalid accesses to IO ports without also blocking potentially valid ones in that case, unless the kernel happens to know exactly what is where (which isn't necessarily the case as far as such IOs are concerned) and even then, who can the kernel differenciate ?
For example, on some machines, I have seen firmwares putting PCI IO BARs of device where usually legacy stuff is on x86. So while accesses to this area via /proc would be legit by something that knows about that device, something like sensors-detect would definitely do the wrong thing by assuming those ports are hooked up to legacy devices.
Ben.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Re: [lm-sensors] [PATCH] sensors-detect: Skip "random" I/O
In reply to Jean DelvareQuoted 7 lines · Christian Krafft
Hi Ben,
regarding your problem with poking into PCI ranges:
As arnd mentioned, we could check, wether there is a mapping for that address and if so, allow the access. That could be done incheck_legacy_ioport, although the name looks a bit misleading.
What do you think ?
It would be pretty gross to end up checking the whole device-tree for things...
Maybe we could check that there's something in the resource tree though, under ioport_resources, that matches the requested port.
But again, its a matter of preventing root from being stupid, which I'm not sure is that worth pursuing...
Ben.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors