mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] off-by-1 in kernel/power/main.c
@ 2006-04-22  4:05 dean gaudet
  2006-04-22 21:37 ` Pavel Machek
  0 siblings, 1 reply; 5+ messages in thread
From: dean gaudet @ 2006-04-22  4:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: len.brown

there's an off-by-1 in 2.6.16.9 (and 2.6.17-rc2) 
kernel/power/main.c:state_store() ... if your kernel just happens to have 
some non-zero data at pm_states[PM_SUSPEND_MAX] (i.e. one past the end of 
the array) then it'll let you write anything you want to /sys/power/state 
and in response the box will enter S5.

i randomly discovered this because i really wanted to put my box into S5 
(for wake on lan) and tried "echo off >/sys/power/state" and was quite 
happy that the box entered S5... happy until i compiled a different kernel 
and this S5 trick stopped working :)

anyhow, this begs the question, what is the correct way to get a box to 
shutdown into s5?  on a fc4 box i have here it does that happily, but 
ubuntu boxes don't seem to go into s5... and i couldn't figure out from 
fc4 patches if they'd changed anything in this area.  pointers 
appreciated.

btw i can whip up a patch making "off" a valid value for /sys/power/state 
...

-dean

Signed-off-by: dean gaudet <dean@arctic.org>

--- linux/kernel/power/main.c.orig	2006-03-19 21:53:29.000000000 -0800
+++ linux/kernel/power/main.c	2006-04-21 20:54:12.000000000 -0700
@@ -272,7 +272,7 @@
 		if (*s && !strncmp(buf, *s, len))
 			break;
 	}
-	if (*s)
+	if (state < PM_SUSPEND_MAX && *s)
 		error = enter_state(state);
 	else
 		error = -EINVAL;

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

* Re: [PATCH] off-by-1 in kernel/power/main.c
  2006-04-22  4:05 [PATCH] off-by-1 in kernel/power/main.c dean gaudet
@ 2006-04-22 21:37 ` Pavel Machek
       [not found]   ` <Pine.LNX.4.64.0604231958020.22072@twinlark.arctic.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2006-04-22 21:37 UTC (permalink / raw)
  To: dean gaudet; +Cc: linux-kernel, len.brown

Hi!

> there's an off-by-1 in 2.6.16.9 (and 2.6.17-rc2) 
> kernel/power/main.c:state_store() ... if your kernel just happens to have 
> some non-zero data at pm_states[PM_SUSPEND_MAX] (i.e. one past the end of 
> the array) then it'll let you write anything you want to /sys/power/state 
> and in response the box will enter S5.
> 
> i randomly discovered this because i really wanted to put my box into S5 
> (for wake on lan) and tried "echo off >/sys/power/state" and was quite 
> happy that the box entered S5... happy until i compiled a different kernel 
> and this S5 trick stopped working :)
> 
> anyhow, this begs the question, what is the correct way to get a box to 
> shutdown into s5?  on a fc4 box i have here it does that happily, but 
> ubuntu boxes don't seem to go into s5... and i couldn't figure out from 
> fc4 patches if they'd changed anything in this area.  pointers 
> appreciated.
> 
> btw i can whip up a patch making "off" a valid value for /sys/power/state 
> ...

Looks okay to me. Can you add acked-by: Pavel Machek and mail it to
akpm?

Valid way to power off machine is by shutdown -o now, and there's a
syscall to do that. It should not be done by /sys/power/state.

								Pavel

-- 
Thanks for all the (sleeping) penguins.

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

* Re: [PATCH] off-by-1 in kernel/power/main.c
       [not found]   ` <Pine.LNX.4.64.0604231958020.22072@twinlark.arctic.org>
@ 2006-04-24  7:57     ` Pavel Machek
  2006-04-25 21:38       ` dean gaudet
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Machek @ 2006-04-24  7:57 UTC (permalink / raw)
  To: dean gaudet; +Cc: kernel list


> > Valid way to power off machine is by shutdown -o now, and there's a
> > syscall to do that. It should not be done by /sys/power/state.
> 
> hey... my shutdown doesn't have a -o option... where can i find that?

Not sure where I got it, because _my_ shutdown does not have -o,
either. Sorry. It has 

       -P     Halt action is to turn off the power.

however. Plus there's a syscall you can use...
								Pavel
-- 
Thanks for all the (sleeping) penguins.

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

* Re: [PATCH] off-by-1 in kernel/power/main.c
  2006-04-24  7:57     ` Pavel Machek
@ 2006-04-25 21:38       ` dean gaudet
  2006-04-25 21:46         ` Pavel Machek
  0 siblings, 1 reply; 5+ messages in thread
From: dean gaudet @ 2006-04-25 21:38 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list

On Mon, 24 Apr 2006, Pavel Machek wrote:

> 
> > > Valid way to power off machine is by shutdown -o now, and there's a
> > > syscall to do that. It should not be done by /sys/power/state.
> > 
> > hey... my shutdown doesn't have a -o option... where can i find that?
> 
> Not sure where I got it, because _my_ shutdown does not have -o,
> either. Sorry. It has 
> 
>        -P     Halt action is to turn off the power.
> 
> however. Plus there's a syscall you can use...

"shutdown -hP now" just causes the machine to power off... i need it to go 
into S5 -- because it'll only respond to wake-on-lan from S5.  it doesn't 
respond to WOL after a "shutdown -hP now"...

ironically the off-by-1 bug let me get into S5... and i thought i had my 
code working.

so what i'm really curious about now is the Right Way to go into S5...

somehow with fc4 "shutdown -h now" put it in S5, but with debian it 
doesn't... and i haven't figured out yet where the fedora/debian 
kernel/sysvinit patches differ on this behaviour.

-dean

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

* Re: [PATCH] off-by-1 in kernel/power/main.c
  2006-04-25 21:38       ` dean gaudet
@ 2006-04-25 21:46         ` Pavel Machek
  0 siblings, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2006-04-25 21:46 UTC (permalink / raw)
  To: dean gaudet; +Cc: kernel list

Hi!

> > > > Valid way to power off machine is by shutdown -o now, and there's a
> > > > syscall to do that. It should not be done by /sys/power/state.
> > > 
> > > hey... my shutdown doesn't have a -o option... where can i find that?
> > 
> > Not sure where I got it, because _my_ shutdown does not have -o,
> > either. Sorry. It has 
> > 
> >        -P     Halt action is to turn off the power.
> > 
> > however. Plus there's a syscall you can use...
> 
> "shutdown -hP now" just causes the machine to power off... i need it to go 
> into S5 -- because it'll only respond to wake-on-lan from S5.  it doesn't 
> respond to WOL after a "shutdown -hP now"...
> 
> ironically the off-by-1 bug let me get into S5... and i thought i had my 
> code working.
> 
> so what i'm really curious about now is the Right Way to go into S5...
> 
> somehow with fc4 "shutdown -h now" put it in S5, but with debian it 
> doesn't... and i haven't figured out yet where the fedora/debian 
> kernel/sysvinit patches differ on this behaviour.

There should not be any difference between S5 and poweroff...

Well, probably driver calls are different in regular case and your
"hacked up" one. Try to find the one that matters...
								Pavel
-- 
Thanks for all the (sleeping) penguins.

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

end of thread, other threads:[~2006-04-25 21:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-22  4:05 [PATCH] off-by-1 in kernel/power/main.c dean gaudet
2006-04-22 21:37 ` Pavel Machek
     [not found]   ` <Pine.LNX.4.64.0604231958020.22072@twinlark.arctic.org>
2006-04-24  7:57     ` Pavel Machek
2006-04-25 21:38       ` dean gaudet
2006-04-25 21:46         ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®