Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:lib\nlattr.c Create Date:2022-07-28 07:16:21
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:validate_nla

Proto:static int validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *policy, unsigned int validate, struct netlink_ext_ack *extack)

Type:int

Parameter:

TypeParameterName
const struct nlattr *nla
intmaxtype
const struct nla_policy *policy
unsigned intvalidate
struct netlink_ext_ack *extack
161  strict_start_type = This entry is special, and used for the attribute at index 0* only, and specifies special data about the policy, namely it* specifies the "boundary type" where strict length validation* starts for any attribute types >= this value, also, strict
163  minlen = 0 , attrlen = la_len - length of payload*@nla: netlink attribute , type = la_type - attribute type*@nla: netlink attribute
164  err = -ERANGE
166  If strict_start_type && type >= strict_start_type Then validate |= NL_VALIDATE_STRICT
169  If type <= 0 || type > maxtype Then Return 0
172  pt = policy[type]
174  BUG_ON(specific validation (e.g. range, function call), see > NLA_TYPE_MAX)
176  If For these data types, attribute length should be exactly the given* size. However, to maintain compatibility with broken commands, if the* attribute length does not match the expected size a warning is emitted[specific validation (e.g. range, function call), see] && attrlen != For these data types, attribute length should be exactly the given* size. However, to maintain compatibility with broken commands, if the* attribute length does not match the expected size a warning is emitted[specific validation (e.g. range, function call), see] || specific validation (e.g. range, function call), see == NLA_EXACT_LEN_WARN && attrlen != len Then
178  pr_warn_ratelimited("netlink: '%s': attribute type %d has an invalid length.\n", comm, type)
181  NL_SET_ERR_MSG_ATTR(extack, nla, "invalid attribute length")
183  Return -EINVAL
187  If validate & NL_VALIDATE_NESTED Then
190  NL_SET_ERR_MSG_ATTR(extack, nla, "NLA_F_NESTED is missing")
192  Return -EINVAL
196  NL_SET_ERR_MSG_ATTR(extack, nla, "NLA_F_NESTED not expected")
198  Return -EINVAL
204  If attrlen != len Then Go to out_err
206  Break
209  If extack && validation_data Then
212  Return -EINVAL
214  err = -EINVAL
215  Go to out_err
218  If attrlen > 0 Then Go to out_err
220  Break
223  If attrlen != sizeof(structnla_bitfield32) Then Go to out_err
227  If err Then Go to out_err
229  Break
244  If attrlen < 1 Then Go to out_err
247  If len Then
250  If buf[attrlen - 1] == '\0' Then attrlen--
253  If attrlen > len Then Go to out_err
256  Break
259  If len && attrlen > len Then Go to out_err
261  Break
267  If attrlen == 0 Then Break
269  If attrlen < NLA_HDRLEN Then Go to out_err
271  If validation_data Then
283  Break
309  If validate & NL_VALIDATE_UNSPEC Then
310  NL_SET_ERR_MSG_ATTR(extack, nla, "Unsupported attribute")
312  Return -EINVAL
316  If attrlen < len Then Go to out_err
318  Break
320  Default
321  If len Then minlen = len
326  If attrlen < minlen Then Go to out_err
334  Break
339  If err Then Return err
341  Break
343  If validate Then
344  err = validate(nla, extack)
345  If err Then Return err
348  Break
351  Return 0
352  out_err :
353  NL_SET_ERR_MSG_ATTR(extack, nla, "Attribute failed policy validation")
354  Return err
Caller
NameDescribe
__nla_validate_parse