Skip to content

Commit

Permalink
netfilter: nft_queue: check the validation of queues_total and queuenum
Browse files Browse the repository at this point in the history
Although the validation of queues_total and queuenum is checked in nft
utility, but user can add nft rules via nfnetlink, so it is necessary
to check the validation at the nft_queue expr init routine too.

Tested by run ./nft-test.py any/queue.t:
  any/queue.t: 6 unit tests, 0 error, 0 warning

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed Sep 9, 2016
1 parent 1bcabc8 commit fe01111
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions net/netfilter/nft_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static int nft_queue_init(const struct nft_ctx *ctx,
const struct nlattr * const tb[])
{
struct nft_queue *priv = nft_expr_priv(expr);
u32 maxid;

if (tb[NFTA_QUEUE_NUM] == NULL)
return -EINVAL;
Expand All @@ -74,6 +75,16 @@ static int nft_queue_init(const struct nft_ctx *ctx,

if (tb[NFTA_QUEUE_TOTAL] != NULL)
priv->queues_total = ntohs(nla_get_be16(tb[NFTA_QUEUE_TOTAL]));
else
priv->queues_total = 1;

if (priv->queues_total == 0)
return -EINVAL;

maxid = priv->queues_total - 1 + priv->queuenum;
if (maxid > U16_MAX)
return -ERANGE;

if (tb[NFTA_QUEUE_FLAGS] != NULL) {
priv->flags = ntohs(nla_get_be16(tb[NFTA_QUEUE_FLAGS]));
if (priv->flags & ~NFT_QUEUE_FLAG_MASK)
Expand Down

0 comments on commit fe01111

Please sign in to comment.