diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c index b74c228191..8e932b5cf9 100644 --- a/xen/common/hypfs.c +++ b/xen/common/hypfs.c @@ -297,7 +297,9 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, int ret; ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked); - ASSERT(ulen <= leaf->e.max_size); + + if ( ulen > leaf->e.max_size ) + return -ENOSPC; if ( leaf->e.type != XEN_HYPFS_TYPE_STRING && leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size ) @@ -356,6 +358,10 @@ int hypfs_write_custom(struct hypfs_entry_leaf *leaf, ASSERT(this_cpu(hypfs_locked) == hypfs_write_locked); + /* Avoid oversized buffer allocation. */ + if ( ulen > MAX_PARAM_SIZE ) + return -ENOSPC; + buf = xzalloc_array(char, ulen); if ( !buf ) return -ENOMEM; @@ -386,9 +392,6 @@ static int hypfs_write(struct hypfs_entry *entry, ASSERT(entry->max_size); - if ( ulen > entry->max_size ) - return -ENOSPC; - l = container_of(entry, struct hypfs_entry_leaf, e); return entry->write(l, uaddr, ulen); diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 9de07b7ac5..c3a943f077 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -57,7 +57,7 @@ static int assign_integer_param(const struct kernel_param *param, uint64_t val) static int parse_params(const char *cmdline, const struct kernel_param *start, const struct kernel_param *end) { - char opt[128], *optval, *optkey, *q; + char opt[MAX_PARAM_SIZE], *optval, *optkey, *q; const char *p = cmdline, *key; const struct kernel_param *param; int rc, final_rc = 0; diff --git a/xen/include/xen/param.h b/xen/include/xen/param.h index f4be944248..d0409d3a0e 100644 --- a/xen/include/xen/param.h +++ b/xen/include/xen/param.h @@ -26,6 +26,9 @@ struct kernel_param { } par; }; +/* Maximum length of a single parameter string. */ +#define MAX_PARAM_SIZE 128 + extern const struct kernel_param __setup_start[], __setup_end[]; #define __param(att) static const att \