Commit ad1fe473 authored by Patrick Mochel's avatar Patrick Mochel

sleep: fix /proc/acpi/sleep write handling.

- Prevent users from screwing themselves by removing support for entering
  S5 from the proc file. S5 is 'soft-off' and the state the system enters
  when powering down. It needs to be preceded by a proper shutdown sequence
  and should not be triggered manually. 
- Fix a potential unchecked array reference using the written value as the
  index.
parent 92f777ca
...@@ -318,14 +318,14 @@ acpi_system_write_sleep ( ...@@ -318,14 +318,14 @@ acpi_system_write_sleep (
size_t count, size_t count,
loff_t *ppos) loff_t *ppos)
{ {
acpi_status status = AE_OK; acpi_status status = AE_ERROR;
char state_string[12] = {'\0'}; char state_string[12] = {'\0'};
u32 state = 0; u32 state = 0;
ACPI_FUNCTION_TRACE("acpi_system_write_sleep"); ACPI_FUNCTION_TRACE("acpi_system_write_sleep");
if (count > sizeof(state_string) - 1) if (count > sizeof(state_string) - 1)
return_VALUE(-EINVAL); goto Done;
if (copy_from_user(state_string, buffer, count)) if (copy_from_user(state_string, buffer, count))
return_VALUE(-EFAULT); return_VALUE(-EFAULT);
...@@ -333,22 +333,25 @@ acpi_system_write_sleep ( ...@@ -333,22 +333,25 @@ acpi_system_write_sleep (
state_string[count] = '\0'; state_string[count] = '\0';
state = simple_strtoul(state_string, NULL, 0); state = simple_strtoul(state_string, NULL, 0);
if (state < 1 || state > 4)
goto Done;
if (!sleep_states[state]) if (!sleep_states[state])
return_VALUE(-ENODEV); return_VALUE(-ENODEV);
#ifdef CONFIG_SOFTWARE_SUSPEND #ifdef CONFIG_SOFTWARE_SUSPEND
if (state == 4) { if (state == 4) {
software_suspend(); software_suspend();
return_VALUE(count); goto Done;
} }
#endif #endif
status = acpi_suspend(state); status = acpi_suspend(state);
Done:
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return_VALUE(-ENODEV); return_VALUE(-EINVAL);
else
return_VALUE(count); return_VALUE(count);
} }
static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment