Skip to content

Commit

Permalink
netfilter: nft_compat: fix error path in nft_parse_compat()
Browse files Browse the repository at this point in the history
The patch 0ca743a: "netfilter: nf_tables: add compatibility
layer for x_tables", leads to the following Smatch

 warning: "net/netfilter/nft_compat.c:140 nft_parse_compat()
          warn: signedness bug returning '(-34)'"

This nft_parse_compat function returns error codes but the return
type is u8 so the error codes are transformed into small positive
values. The callers don't check the return.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Pablo Neira Ayuso committed Nov 18, 2013
1 parent 23dfe13 commit 8691a9a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions net/netfilter/nft_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static const struct nla_policy nft_rule_compat_policy[NFTA_RULE_COMPAT_MAX + 1]
[NFTA_RULE_COMPAT_FLAGS] = { .type = NLA_U32 },
};

static u8 nft_parse_compat(const struct nlattr *attr, bool *inv)
static int nft_parse_compat(const struct nlattr *attr, u8 *proto, bool *inv)
{
struct nlattr *tb[NFTA_RULE_COMPAT_MAX+1];
u32 flags;
Expand All @@ -148,7 +148,8 @@ static u8 nft_parse_compat(const struct nlattr *attr, bool *inv)
if (flags & NFT_RULE_COMPAT_F_INV)
*inv = true;

return ntohl(nla_get_be32(tb[NFTA_RULE_COMPAT_PROTO]));
*proto = ntohl(nla_get_be32(tb[NFTA_RULE_COMPAT_PROTO]));
return 0;
}

static int
Expand All @@ -166,8 +167,11 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,

target_compat_from_user(target, nla_data(tb[NFTA_TARGET_INFO]), info);

if (ctx->nla[NFTA_RULE_COMPAT])
proto = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &inv);
if (ctx->nla[NFTA_RULE_COMPAT]) {
ret = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &proto, &inv);
if (ret < 0)
goto err;
}

nft_target_set_tgchk_param(&par, ctx, target, info, &e, proto, inv);

Expand Down Expand Up @@ -356,8 +360,11 @@ nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,

match_compat_from_user(match, nla_data(tb[NFTA_MATCH_INFO]), info);

if (ctx->nla[NFTA_RULE_COMPAT])
proto = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &inv);
if (ctx->nla[NFTA_RULE_COMPAT]) {
ret = nft_parse_compat(ctx->nla[NFTA_RULE_COMPAT], &proto, &inv);
if (ret < 0)
goto err;
}

nft_match_set_mtchk_param(&par, ctx, match, info, &e, proto, inv);

Expand Down

0 comments on commit 8691a9a

Please sign in to comment.