From f4bd4294a55b2a0e897148bf25a32e189abda38a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 9 Nov 2015 21:19:42 +0000 Subject: [PATCH] scst_vdisk: Make expl_alua sysfs attribute input validation more strict git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6640 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 26 ++++++++++++++++++++++++++ scst/src/dev_handlers/scst_vdisk.c | 9 ++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 53a2f55ab..f349bb80a 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -255,6 +255,32 @@ static inline void hex2bin(u8 *dst, const char *src, size_t count) } #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) +static inline int __must_check kstrtoull(const char *s, unsigned int base, + unsigned long long *res) +{ + return strict_strtoull(s, base, res); +} + +static inline int __must_check kstrtoll(const char *s, unsigned int base, + long long *res) +{ + return strict_strtoll(s, base, res); +} + +static inline int __must_check kstrtoul(const char *s, unsigned int base, + unsigned long *res) +{ + return strict_strtoul(s, base, res); +} + +static inline int __must_check kstrtol(const char *s, unsigned int base, + long *res) +{ + return strict_strtol(s, base, res); +} +#endif + /* */ #ifndef __list_for_each diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index f3788afa0..952b73d33 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -8823,7 +8823,7 @@ static ssize_t vdisk_sysfs_expl_alua_store(struct kobject *kobj, struct scst_device *dev; struct scst_vdisk_dev *virt_dev; char ch[16]; - bool expl_alua; + unsigned long expl_alua; int res; TRACE_ENTRY(); @@ -8831,14 +8831,17 @@ static ssize_t vdisk_sysfs_expl_alua_store(struct kobject *kobj, dev = container_of(kobj, struct scst_device, dev_kobj); virt_dev = dev->dh_priv; sprintf(ch, "%.*s", min_t(int, sizeof(ch) - 1, count), buf); - expl_alua = !!simple_strtoul(ch, NULL, 0); + res = kstrtoul(ch, NULL, &expl_alua); + if (res < 0) + goto out; spin_lock(&virt_dev->flags_lock); - virt_dev->expl_alua = expl_alua; + virt_dev->expl_alua = !!expl_alua; spin_unlock(&virt_dev->flags_lock); res = count; +out: TRACE_EXIT_RES(res); return res; }