Skip to content

Commit 58f40ab

Browse files
kaberummakynes
authored andcommitted
netfilter: nft_lookup: use nft_validate_register_store() to validate types
In preparation of validating the length of a register store, use nft_validate_register_store() in nft_lookup instead of open coding the validation. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 1ec1021 commit 58f40ab

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,7 +4169,7 @@ EXPORT_SYMBOL_GPL(nft_validate_output_register);
41694169
* Validate that a data load uses the appropriate data type for
41704170
* the destination register and the length is within the bounds.
41714171
* A value of NULL for the data means that its runtime gathered
4172-
* data, which is always of type NFT_DATA_VALUE.
4172+
* data.
41734173
*/
41744174
int nft_validate_register_store(const struct nft_ctx *ctx,
41754175
enum nft_registers reg,
@@ -4180,10 +4180,11 @@ int nft_validate_register_store(const struct nft_ctx *ctx,
41804180

41814181
switch (reg) {
41824182
case NFT_REG_VERDICT:
4183-
if (data == NULL || type != NFT_DATA_VERDICT)
4183+
if (type != NFT_DATA_VERDICT)
41844184
return -EINVAL;
41854185

4186-
if (data->verdict == NFT_GOTO || data->verdict == NFT_JUMP) {
4186+
if (data != NULL &&
4187+
(data->verdict == NFT_GOTO || data->verdict == NFT_JUMP)) {
41874188
err = nf_tables_check_loops(ctx, data->chain);
41884189
if (err < 0)
41894190
return err;

net/netfilter/nft_lookup.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
8484
if (err < 0)
8585
return err;
8686

87-
if (priv->dreg == NFT_REG_VERDICT) {
88-
if (set->dtype != NFT_DATA_VERDICT)
89-
return -EINVAL;
90-
} else if (set->dtype == NFT_DATA_VERDICT)
91-
return -EINVAL;
87+
err = nft_validate_register_store(ctx, priv->dreg, NULL,
88+
set->dtype, set->dlen);
89+
if (err < 0)
90+
return err;
9291
} else if (set->flags & NFT_SET_MAP)
9392
return -EINVAL;
9493

0 commit comments

Comments
 (0)