From e9a57cd87598515b9b4bf09caf89407c2a164e76 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 29 Oct 2010 18:34:48 +0000 Subject: [PATCH] Enforce max LUNs limitation git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@2490 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst_const.h | 3 +++ scst/src/scst_proc.c | 7 +++++++ scst/src/scst_sysfs.c | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/scst/include/scst_const.h b/scst/include/scst_const.h index fd6b6344f..e7b4f477a 100644 --- a/scst/include/scst_const.h +++ b/scst/include/scst_const.h @@ -46,6 +46,9 @@ /* Max size of external names, like initiator name */ #define SCST_MAX_EXTERNAL_NAME 256 +/* Max LUN. 2 bits are used for addressing method. */ +#define SCST_MAX_LUN ((1 << (16-2)) - 1) + /* * Size of sense sufficient to carry standard sense data. * Warning! It's allocated on stack! diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index 6b98d0937..3a418e86e 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -2007,7 +2007,14 @@ static ssize_t scst_proc_groups_devices_write(struct file *file, e++; while (isspace(*e) && *e != '\0') e++; + virt_lun = simple_strtoul(e, &e, 0); + if (virt_lun > SCST_MAX_LUN) { + PRINT_ERROR("Too big LUN %d (max %d)", virt_lun, + SCST_MAX_LUN); + res = -EINVAL; + goto out_free_up; + } while (isspace(*e) && *e != '\0') e++; diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 9a0011c13..f0fbb5fa5 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -2720,7 +2720,14 @@ static int __scst_process_luns_mgmt_store(char *buffer, e++; while (isspace(*e) && *e != '\0') e++; + virt_lun = simple_strtoul(e, &e, 0); + if (virt_lun > SCST_MAX_LUN) { + PRINT_ERROR("Too big LUN %d (max %d)", virt_lun, + SCST_MAX_LUN); + res = -EINVAL; + goto out_unlock; + } while (isspace(*e) && *e != '\0') e++;