diff options
Diffstat (limited to 'lib/nlattr.c')
-rw-r--r-- | lib/nlattr.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/nlattr.c b/lib/nlattr.c index b42b8577fc23..a7e0b16078df 100644 --- a/lib/nlattr.c +++ b/lib/nlattr.c | |||
@@ -112,6 +112,7 @@ static int validate_nla(const struct nlattr *nla, int maxtype, | |||
112 | * @len: length of attribute stream | 112 | * @len: length of attribute stream |
113 | * @maxtype: maximum attribute type to be expected | 113 | * @maxtype: maximum attribute type to be expected |
114 | * @policy: validation policy | 114 | * @policy: validation policy |
115 | * @extack: extended ACK report struct | ||
115 | * | 116 | * |
116 | * Validates all attributes in the specified attribute stream against the | 117 | * Validates all attributes in the specified attribute stream against the |
117 | * specified policy. Attributes with a type exceeding maxtype will be | 118 | * specified policy. Attributes with a type exceeding maxtype will be |
@@ -120,20 +121,23 @@ static int validate_nla(const struct nlattr *nla, int maxtype, | |||
120 | * Returns 0 on success or a negative error code. | 121 | * Returns 0 on success or a negative error code. |
121 | */ | 122 | */ |
122 | int nla_validate(const struct nlattr *head, int len, int maxtype, | 123 | int nla_validate(const struct nlattr *head, int len, int maxtype, |
123 | const struct nla_policy *policy) | 124 | const struct nla_policy *policy, |
125 | struct netlink_ext_ack *extack) | ||
124 | { | 126 | { |
125 | const struct nlattr *nla; | 127 | const struct nlattr *nla; |
126 | int rem, err; | 128 | int rem; |
127 | 129 | ||
128 | nla_for_each_attr(nla, head, len, rem) { | 130 | nla_for_each_attr(nla, head, len, rem) { |
129 | err = validate_nla(nla, maxtype, policy); | 131 | int err = validate_nla(nla, maxtype, policy); |
130 | if (err < 0) | 132 | |
131 | goto errout; | 133 | if (err < 0) { |
134 | if (extack) | ||
135 | extack->bad_attr = nla; | ||
136 | return err; | ||
137 | } | ||
132 | } | 138 | } |
133 | 139 | ||
134 | err = 0; | 140 | return 0; |
135 | errout: | ||
136 | return err; | ||
137 | } | 141 | } |
138 | EXPORT_SYMBOL(nla_validate); | 142 | EXPORT_SYMBOL(nla_validate); |
139 | 143 | ||
@@ -180,7 +184,8 @@ EXPORT_SYMBOL(nla_policy_len); | |||
180 | * Returns 0 on success or a negative error code. | 184 | * Returns 0 on success or a negative error code. |
181 | */ | 185 | */ |
182 | int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head, | 186 | int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head, |
183 | int len, const struct nla_policy *policy) | 187 | int len, const struct nla_policy *policy, |
188 | struct netlink_ext_ack *extack) | ||
184 | { | 189 | { |
185 | const struct nlattr *nla; | 190 | const struct nlattr *nla; |
186 | int rem, err; | 191 | int rem, err; |
@@ -193,8 +198,11 @@ int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head, | |||
193 | if (type > 0 && type <= maxtype) { | 198 | if (type > 0 && type <= maxtype) { |
194 | if (policy) { | 199 | if (policy) { |
195 | err = validate_nla(nla, maxtype, policy); | 200 | err = validate_nla(nla, maxtype, policy); |
196 | if (err < 0) | 201 | if (err < 0) { |
202 | if (extack) | ||
203 | extack->bad_attr = nla; | ||
197 | goto errout; | 204 | goto errout; |
205 | } | ||
198 | } | 206 | } |
199 | 207 | ||
200 | tb[type] = (struct nlattr *)nla; | 208 | tb[type] = (struct nlattr *)nla; |