• Home
  • Raw
  • Download

Lines Matching +full:max +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0
60 static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype,
72 return -EINVAL; in validate_nla_bitfield32()
75 if (bf->selector & ~valid_flags_mask) in validate_nla_bitfield32()
76 return -EINVAL; in validate_nla_bitfield32()
79 if (bf->value & ~valid_flags_mask) in validate_nla_bitfield32()
80 return -EINVAL; in validate_nla_bitfield32()
83 if (bf->value & ~bf->selector) in validate_nla_bitfield32()
84 return -EINVAL; in validate_nla_bitfield32()
89 static int nla_validate_array(const struct nlattr *head, int len, int maxtype, in nla_validate_array() argument
97 nla_for_each_attr(entry, head, len, rem) { in nla_validate_array()
106 return -ERANGE; in nla_validate_array()
122 WARN_ON_ONCE(pt->validation_type != NLA_VALIDATE_RANGE_PTR && in nla_get_range_unsigned()
123 (pt->min < 0 || pt->max < 0)); in nla_get_range_unsigned()
125 range->min = 0; in nla_get_range_unsigned()
127 switch (pt->type) { in nla_get_range_unsigned()
129 range->max = U8_MAX; in nla_get_range_unsigned()
134 range->max = U16_MAX; in nla_get_range_unsigned()
138 range->max = U32_MAX; in nla_get_range_unsigned()
142 range->max = U64_MAX; in nla_get_range_unsigned()
149 switch (pt->validation_type) { in nla_get_range_unsigned()
152 range->min = pt->min; in nla_get_range_unsigned()
153 range->max = pt->max; in nla_get_range_unsigned()
156 *range = *pt->range; in nla_get_range_unsigned()
159 range->min = pt->min; in nla_get_range_unsigned()
162 range->max = pt->max; in nla_get_range_unsigned()
177 switch (pt->type) { in nla_validate_range_unsigned()
203 return -EINVAL; in nla_validate_range_unsigned()
208 if (pt->validation_type == NLA_VALIDATE_RANGE_WARN_TOO_LONG && in nla_validate_range_unsigned()
209 pt->type == NLA_BINARY && value > range.max) { in nla_validate_range_unsigned()
211 current->comm, pt->type); in nla_validate_range_unsigned()
215 return -EINVAL; in nla_validate_range_unsigned()
218 /* this assumes min <= max (don't validate against min) */ in nla_validate_range_unsigned()
222 if (value < range.min || value > range.max) { in nla_validate_range_unsigned()
223 bool binary = pt->type == NLA_BINARY; in nla_validate_range_unsigned()
232 return -ERANGE; in nla_validate_range_unsigned()
241 switch (pt->type) { in nla_get_range_signed()
243 range->min = S8_MIN; in nla_get_range_signed()
244 range->max = S8_MAX; in nla_get_range_signed()
247 range->min = S16_MIN; in nla_get_range_signed()
248 range->max = S16_MAX; in nla_get_range_signed()
251 range->min = S32_MIN; in nla_get_range_signed()
252 range->max = S32_MAX; in nla_get_range_signed()
255 range->min = S64_MIN; in nla_get_range_signed()
256 range->max = S64_MAX; in nla_get_range_signed()
263 switch (pt->validation_type) { in nla_get_range_signed()
265 range->min = pt->min; in nla_get_range_signed()
266 range->max = pt->max; in nla_get_range_signed()
269 *range = *pt->range_signed; in nla_get_range_signed()
272 range->min = pt->min; in nla_get_range_signed()
275 range->max = pt->max; in nla_get_range_signed()
289 switch (pt->type) { in nla_validate_int_range_signed()
303 return -EINVAL; in nla_validate_int_range_signed()
308 if (value < range.min || value > range.max) { in nla_validate_int_range_signed()
311 return -ERANGE; in nla_validate_int_range_signed()
322 switch (pt->type) { in nla_validate_int_range()
339 return -EINVAL; in nla_validate_int_range()
349 switch (pt->type) { in nla_validate_mask()
369 return -EINVAL; in nla_validate_mask()
372 if (value & ~(u64)pt->mask) { in nla_validate_mask()
374 return -EINVAL; in nla_validate_mask()
387 int err = -ERANGE; in validate_nla()
398 BUG_ON(pt->type > NLA_TYPE_MAX); in validate_nla()
400 if (nla_attr_len[pt->type] && attrlen != nla_attr_len[pt->type]) { in validate_nla()
402 current->comm, type); in validate_nla()
406 return -EINVAL; in validate_nla()
411 if ((pt->type == NLA_NESTED || pt->type == NLA_NESTED_ARRAY) && in validate_nla()
412 !(nla->nla_type & NLA_F_NESTED)) { in validate_nla()
415 return -EINVAL; in validate_nla()
417 if (pt->type != NLA_NESTED && pt->type != NLA_NESTED_ARRAY && in validate_nla()
418 pt->type != NLA_UNSPEC && (nla->nla_type & NLA_F_NESTED)) { in validate_nla()
421 return -EINVAL; in validate_nla()
425 switch (pt->type) { in validate_nla()
427 if (extack && pt->reject_message) { in validate_nla()
429 extack->_msg = pt->reject_message; in validate_nla()
430 return -EINVAL; in validate_nla()
432 err = -EINVAL; in validate_nla()
444 err = validate_nla_bitfield32(nla, pt->bitfield32_valid); in validate_nla()
450 if (pt->len) in validate_nla()
451 minlen = min_t(int, attrlen, pt->len + 1); in validate_nla()
456 err = -EINVAL; in validate_nla()
465 if (pt->len) { in validate_nla()
468 if (buf[attrlen - 1] == '\0') in validate_nla()
469 attrlen--; in validate_nla()
471 if (attrlen > pt->len) in validate_nla()
477 if (pt->len && attrlen > pt->len) in validate_nla()
489 if (pt->nested_policy) { in validate_nla()
491 pt->len, pt->nested_policy, in validate_nla()
511 if (pt->nested_policy) { in validate_nla()
515 pt->len, pt->nested_policy, in validate_nla()
531 return -EINVAL; in validate_nla()
533 if (attrlen < pt->len) in validate_nla()
538 if (pt->len) in validate_nla()
539 minlen = pt->len; in validate_nla()
541 minlen = nla_attr_minlen[pt->type]; in validate_nla()
548 switch (pt->validation_type) { in validate_nla()
567 if (pt->validate) { in validate_nla()
568 err = pt->validate(nla, extack); in validate_nla()
582 static int __nla_validate_parse(const struct nlattr *head, int len, int maxtype, in __nla_validate_parse() argument
594 return -EINVAL; in __nla_validate_parse()
600 nla_for_each_attr(nla, head, len, rem) { in __nla_validate_parse()
607 return -EINVAL; in __nla_validate_parse()
626 rem, current->comm); in __nla_validate_parse()
629 return -EINVAL; in __nla_validate_parse()
636 * __nla_validate - Validate a stream of attributes
638 * @len: length of attribute stream
651 int __nla_validate(const struct nlattr *head, int len, int maxtype, in __nla_validate() argument
655 return __nla_validate_parse(head, len, maxtype, policy, validate, in __nla_validate()
661 * nla_policy_len - Determine the max. length of a policy
665 * Determines the max. length of the policy. It is currently used
674 int i, len = 0; in nla_policy_len() local
677 if (p->len) in nla_policy_len()
678 len += nla_total_size(p->len); in nla_policy_len()
679 else if (nla_attr_len[p->type]) in nla_policy_len()
680 len += nla_total_size(nla_attr_len[p->type]); in nla_policy_len()
681 else if (nla_attr_minlen[p->type]) in nla_policy_len()
682 len += nla_total_size(nla_attr_minlen[p->type]); in nla_policy_len()
685 return len; in nla_policy_len()
690 * __nla_parse - Parse a stream of attributes into a tb buffer
694 * @len: length of attribute stream
706 const struct nlattr *head, int len, in __nla_parse() argument
710 return __nla_validate_parse(head, len, maxtype, policy, validate, in __nla_parse()
716 * nla_find - Find a specific attribute in a stream of attributes
718 * @len: length of attribute stream
723 struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype) in nla_find() argument
728 nla_for_each_attr(nla, head, len, rem) in nla_find()
737 * nla_strscpy - Copy string attribute payload into a sized buffer
742 * Copies at most dstsize - 1 bytes into the destination buffer.
746 * * srclen - Returns @nla length (not including the trailing %NUL).
747 * * -E2BIG - If @dstsize is 0 or greater than U16_MAX or @nla length greater
755 size_t len; in nla_strscpy() local
758 return -E2BIG; in nla_strscpy()
760 if (srclen > 0 && src[srclen - 1] == '\0') in nla_strscpy()
761 srclen--; in nla_strscpy()
764 len = dstsize - 1; in nla_strscpy()
765 ret = -E2BIG; in nla_strscpy()
767 len = srclen; in nla_strscpy()
768 ret = len; in nla_strscpy()
771 memcpy(dst, src, len); in nla_strscpy()
773 memset(dst + len, 0, dstsize - len); in nla_strscpy()
780 * nla_strdup - Copy string attribute payload into a newly allocated buffer
791 if (srclen > 0 && src[srclen - 1] == '\0') in nla_strdup()
792 srclen--; in nla_strdup()
804 * nla_memcpy - Copy a netlink attribute into another memory area
820 memset(dest + minlen, 0, count - minlen); in nla_memcpy()
827 * nla_memcmp - Compare an attribute with sized memory area
835 int d = nla_len(nla) - size; in nla_memcmp()
845 * nla_strcmp - Compare a string attribute against a string
851 int len = strlen(str); in nla_strcmp() local
856 while (attrlen > 0 && buf[attrlen - 1] == '\0') in nla_strcmp()
857 attrlen--; in nla_strcmp()
859 d = attrlen - len; in nla_strcmp()
861 d = memcmp(nla_data(nla), str, len); in nla_strcmp()
869 * __nla_reserve - reserve room for attribute on the skb
885 nla->nla_type = attrtype; in __nla_reserve()
886 nla->nla_len = nla_attr_size(attrlen); in __nla_reserve()
888 memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen)); in __nla_reserve()
895 * __nla_reserve_64bit - reserve room for attribute on the skb and align it
903 * attribute will have a 64-bit aligned nla_data() area.
918 * __nla_reserve_nohdr - reserve room for attribute without header
934 * nla_reserve - reserve room for attribute on the skb
955 * nla_reserve_64bit - reserve room for attribute on the skb and align it
963 * attribute will have a 64-bit aligned nla_data() area.
971 size_t len; in nla_reserve_64bit() local
974 len = nla_total_size_64bit(attrlen); in nla_reserve_64bit()
976 len = nla_total_size(attrlen); in nla_reserve_64bit()
977 if (unlikely(skb_tailroom(skb) < len)) in nla_reserve_64bit()
985 * nla_reserve_nohdr - reserve room for attribute without header
1004 * __nla_put - Add a netlink attribute to a socket buffer
1024 * __nla_put_64bit - Add a netlink attribute to a socket buffer and align it
1045 * __nla_put_nohdr - Add a netlink attribute without header
1063 * nla_put - Add a netlink attribute to a socket buffer
1069 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
1075 return -EMSGSIZE; in nla_put()
1083 * nla_put_64bit - Add a netlink attribute to a socket buffer and align it
1090 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
1096 size_t len; in nla_put_64bit() local
1099 len = nla_total_size_64bit(attrlen); in nla_put_64bit()
1101 len = nla_total_size(attrlen); in nla_put_64bit()
1102 if (unlikely(skb_tailroom(skb) < len)) in nla_put_64bit()
1103 return -EMSGSIZE; in nla_put_64bit()
1111 * nla_put_nohdr - Add a netlink attribute without header
1116 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
1122 return -EMSGSIZE; in nla_put_nohdr()
1130 * nla_append - Add a netlink attribute without header or padding
1135 * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
1141 return -EMSGSIZE; in nla_append()