Commit cc9b2e9f6603190c009e5d2629ce8e3f99571346

Authored by James Bottomley
1 parent c982c368bb

[SCSI] enclosure: fix oops while iterating enclosure_status array

Based on patch originally by Jeff Mahoney <jeffm@suse.com>

 enclosure_status is expected to be a NULL terminated array of strings
 but isn't actually NULL terminated. When writing an invalid value to
 /sys/class/enclosure/.../.../status, it goes off the end of the array
 and Oopses.


Fix by making the assumption true and adding NULL at the end.

Reported-by: Artur Wojcik <artur.wojcik@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>

Showing 2 changed files with 3 additions and 0 deletions Side-by-side Diff

drivers/misc/enclosure.c
... ... @@ -391,6 +391,7 @@
391 391 [ENCLOSURE_STATUS_NOT_INSTALLED] = "not installed",
392 392 [ENCLOSURE_STATUS_UNKNOWN] = "unknown",
393 393 [ENCLOSURE_STATUS_UNAVAILABLE] = "unavailable",
  394 + [ENCLOSURE_STATUS_MAX] = NULL,
394 395 };
395 396  
396 397 static const char *const enclosure_type [] = {
include/linux/enclosure.h
... ... @@ -42,6 +42,8 @@
42 42 ENCLOSURE_STATUS_NOT_INSTALLED,
43 43 ENCLOSURE_STATUS_UNKNOWN,
44 44 ENCLOSURE_STATUS_UNAVAILABLE,
  45 + /* last element for counting purposes */
  46 + ENCLOSURE_STATUS_MAX
45 47 };
46 48  
47 49 /* SFF-8485 activity light settings */