aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/devlink.c
diff options
context:
space:
mode:
authorMoshe Shemesh <moshe@mellanox.com>2018-10-10 09:09:27 -0400
committerDavid S. Miller <davem@davemloft.net>2018-10-10 13:19:10 -0400
commitbde74ad10eb55aaa472c37b107934e6b8563c25e (patch)
tree834c7d34a735b3be2621f897c76275bd6427f694 /net/core/devlink.c
parent1276534c988ba752fa01bf090412a877ee783829 (diff)
devlink: Add helper function for safely copy string param
Devlink string param buffer is allocated at the size of DEVLINK_PARAM_MAX_STRING_VALUE. Add helper function which makes sure this size is not exceeded. Renamed DEVLINK_PARAM_MAX_STRING_VALUE to __DEVLINK_PARAM_MAX_STRING_VALUE to emphasize that it should be used by devlink only. The driver should use the helper function instead to verify it doesn't exceed the allowed length. Signed-off-by: Moshe Shemesh <moshe@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/devlink.c')
-rw-r--r--net/core/devlink.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 1a0de1677197..6bc42933be4a 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -3015,7 +3015,7 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
3015 len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]), 3015 len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]),
3016 nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); 3016 nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]));
3017 if (len == nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) || 3017 if (len == nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) ||
3018 len >= DEVLINK_PARAM_MAX_STRING_VALUE) 3018 len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
3019 return -EINVAL; 3019 return -EINVAL;
3020 strcpy(value->vstr, 3020 strcpy(value->vstr,
3021 nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); 3021 nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]));
@@ -4618,6 +4618,23 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id)
4618EXPORT_SYMBOL_GPL(devlink_param_value_changed); 4618EXPORT_SYMBOL_GPL(devlink_param_value_changed);
4619 4619
4620/** 4620/**
4621 * devlink_param_value_str_fill - Safely fill-up the string preventing
4622 * from overflow of the preallocated buffer
4623 *
4624 * @dst_val: destination devlink_param_value
4625 * @src: source buffer
4626 */
4627void devlink_param_value_str_fill(union devlink_param_value *dst_val,
4628 const char *src)
4629{
4630 size_t len;
4631
4632 len = strlcpy(dst_val->vstr, src, __DEVLINK_PARAM_MAX_STRING_VALUE);
4633 WARN_ON(len >= __DEVLINK_PARAM_MAX_STRING_VALUE);
4634}
4635EXPORT_SYMBOL_GPL(devlink_param_value_str_fill);
4636
4637/**
4621 * devlink_region_create - create a new address region 4638 * devlink_region_create - create a new address region
4622 * 4639 *
4623 * @devlink: devlink 4640 * @devlink: devlink