File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,7 @@ struct nla_policy {
325
325
struct netlink_range_validation_signed * range_signed ;
326
326
struct {
327
327
s16 min , max ;
328
+ u8 network_byte_order :1 ;
328
329
};
329
330
int (* validate )(const struct nlattr * attr ,
330
331
struct netlink_ext_ack * extack );
@@ -418,6 +419,14 @@ struct nla_policy {
418
419
.type = NLA_ENSURE_INT_OR_BINARY_TYPE(tp), \
419
420
.validation_type = NLA_VALIDATE_MAX, \
420
421
.max = _max, \
422
+ .network_byte_order = 0, \
423
+ }
424
+
425
+ #define NLA_POLICY_MAX_BE (tp , _max ) { \
426
+ .type = NLA_ENSURE_UINT_TYPE(tp), \
427
+ .validation_type = NLA_VALIDATE_MAX, \
428
+ .max = _max, \
429
+ .network_byte_order = 1, \
421
430
}
422
431
423
432
#define NLA_POLICY_MASK (tp , _mask ) { \
Original file line number Diff line number Diff line change @@ -159,6 +159,31 @@ void nla_get_range_unsigned(const struct nla_policy *pt,
159
159
}
160
160
}
161
161
162
+ static u64 nla_get_attr_bo (const struct nla_policy * pt ,
163
+ const struct nlattr * nla )
164
+ {
165
+ switch (pt -> type ) {
166
+ case NLA_U16 :
167
+ if (pt -> network_byte_order )
168
+ return ntohs (nla_get_be16 (nla ));
169
+
170
+ return nla_get_u16 (nla );
171
+ case NLA_U32 :
172
+ if (pt -> network_byte_order )
173
+ return ntohl (nla_get_be32 (nla ));
174
+
175
+ return nla_get_u32 (nla );
176
+ case NLA_U64 :
177
+ if (pt -> network_byte_order )
178
+ return be64_to_cpu (nla_get_be64 (nla ));
179
+
180
+ return nla_get_u64 (nla );
181
+ }
182
+
183
+ WARN_ON_ONCE (1 );
184
+ return 0 ;
185
+ }
186
+
162
187
static int nla_validate_range_unsigned (const struct nla_policy * pt ,
163
188
const struct nlattr * nla ,
164
189
struct netlink_ext_ack * extack ,
@@ -172,12 +197,10 @@ static int nla_validate_range_unsigned(const struct nla_policy *pt,
172
197
value = nla_get_u8 (nla );
173
198
break ;
174
199
case NLA_U16 :
175
- value = nla_get_u16 (nla );
176
- break ;
177
200
case NLA_U32 :
178
- value = nla_get_u32 (nla );
179
- break ;
180
201
case NLA_U64 :
202
+ value = nla_get_attr_bo (pt , nla );
203
+ break ;
181
204
case NLA_MSECS :
182
205
value = nla_get_u64 (nla );
183
206
break ;
Original file line number Diff line number Diff line change @@ -173,10 +173,10 @@ static const struct nla_policy nft_payload_policy[NFTA_PAYLOAD_MAX + 1] = {
173
173
[NFTA_PAYLOAD_SREG ] = { .type = NLA_U32 },
174
174
[NFTA_PAYLOAD_DREG ] = { .type = NLA_U32 },
175
175
[NFTA_PAYLOAD_BASE ] = { .type = NLA_U32 },
176
- [NFTA_PAYLOAD_OFFSET ] = { . type = NLA_U32 } ,
177
- [NFTA_PAYLOAD_LEN ] = { . type = NLA_U32 } ,
176
+ [NFTA_PAYLOAD_OFFSET ] = NLA_POLICY_MAX_BE ( NLA_U32 , 255 ) ,
177
+ [NFTA_PAYLOAD_LEN ] = NLA_POLICY_MAX_BE ( NLA_U32 , 255 ) ,
178
178
[NFTA_PAYLOAD_CSUM_TYPE ] = { .type = NLA_U32 },
179
- [NFTA_PAYLOAD_CSUM_OFFSET ] = { . type = NLA_U32 } ,
179
+ [NFTA_PAYLOAD_CSUM_OFFSET ] = NLA_POLICY_MAX_BE ( NLA_U32 , 255 ) ,
180
180
[NFTA_PAYLOAD_CSUM_FLAGS ] = { .type = NLA_U32 },
181
181
};
182
182
You can’t perform that action at this time.
0 commit comments