From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Liping Zhang <zlpnobody@163.com>
Cc: netfilter-devel@vger.kernel.org, Liping Zhang <zlpnobody@gmail.com>
Subject: Re: [PATCH nf 2/5] netfilter: nfnl_cthelper: fix incorrect helper->expect_class_max
Date: Tue, 21 Mar 2017 11:27:52 +0100 [thread overview]
Message-ID: <20170321102752.GB1940@salvia> (raw)
In-Reply-To: <1489934162-7415-3-git-send-email-zlpnobody@163.com>
On Sun, Mar 19, 2017 at 10:35:59PM +0800, Liping Zhang wrote:
> From: Liping Zhang <zlpnobody@gmail.com>
>
> The helper->expect_class_max must be set to the total number of
> expect_policy minus 1, since we will use the statement "if (class >
> helper->expect_class_max)" to validate the CTA_EXPECT_CLASS attr in
> ctnetlink_alloc_expect.
>
> So for compatibility, set the helper->expect_class_max to the
> NFCTH_POLICY_SET_NUM attr's value minus 1.
>
> Also: it's invalid when the NFCTH_POLICY_SET_NUM attr's value is zero.
> 1. this will result "expect_policy = kzalloc(0, GFP_KERNEL);";
> 2. we cannot set the helper->expect_class_max to a proper value.
>
> So if nla_get_be32(tb[NFCTH_POLICY_SET_NUM]) is zero, report -EINVAL to
> the userspace.
>
> Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
> ---
> net/netfilter/nfnetlink_cthelper.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c
> index 9c24301..cc70dd5 100644
> --- a/net/netfilter/nfnetlink_cthelper.c
> +++ b/net/netfilter/nfnetlink_cthelper.c
> @@ -161,6 +161,7 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
> int i, ret;
> struct nf_conntrack_expect_policy *expect_policy;
> struct nlattr *tb[NFCTH_POLICY_SET_MAX+1];
> + unsigned int class_max;
>
> ret = nla_parse_nested(tb, NFCTH_POLICY_SET_MAX, attr,
> nfnl_cthelper_expect_policy_set);
> @@ -170,19 +171,18 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
> if (!tb[NFCTH_POLICY_SET_NUM])
> return -EINVAL;
>
> - helper->expect_class_max =
> - ntohl(nla_get_be32(tb[NFCTH_POLICY_SET_NUM]));
> -
> - if (helper->expect_class_max != 0 &&
> - helper->expect_class_max > NF_CT_MAX_EXPECT_CLASSES)
> + class_max = ntohl(nla_get_be32(tb[NFCTH_POLICY_SET_NUM]));
> + if (class_max == 0)
> + return -EINVAL;
I think this patch is just fixing up this case. We should always
provide a policy for the expectation.
> + if (class_max > NF_CT_MAX_EXPECT_CLASSES)
> return -EOVERFLOW;
>
> expect_policy = kzalloc(sizeof(struct nf_conntrack_expect_policy) *
> - helper->expect_class_max, GFP_KERNEL);
> + class_max, GFP_KERNEL);
> if (expect_policy == NULL)
> return -ENOMEM;
>
> - for (i=0; i<helper->expect_class_max; i++) {
> + for (i = 0; i < class_max; i++) {
> if (!tb[NFCTH_POLICY_SET+i])
> goto err;
>
> @@ -191,6 +191,8 @@ nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper *helper,
> if (ret < 0)
> goto err;
> }
> +
> + helper->expect_class_max = class_max - 1;
Why - 1 ?
class_max represents the array size, you can just keep this code the
way it is.
> helper->expect_policy = expect_policy;
> return 0;
> err:
> @@ -375,10 +377,10 @@ nfnl_cthelper_dump_policy(struct sk_buff *skb,
> goto nla_put_failure;
>
> if (nla_put_be32(skb, NFCTH_POLICY_SET_NUM,
> - htonl(helper->expect_class_max)))
> + htonl(helper->expect_class_max + 1)))
> goto nla_put_failure;
>
> - for (i=0; i<helper->expect_class_max; i++) {
> + for (i = 0; i < helper->expect_class_max + 1; i++) {
> nest_parms2 = nla_nest_start(skb,
> (NFCTH_POLICY_SET+i) | NLA_F_NESTED);
> if (nest_parms2 == NULL)
> --
> 2.5.5
>
>
next prev parent reply other threads:[~2017-03-21 10:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-19 14:35 [PATCH nf 0/5] netfilter: nfnl_cthelper: fix some bugs Liping Zhang
2017-03-19 14:35 ` [PATCH nf 1/5] netfilter: nfnl_cthelper: don't report error if NFCTH_PRIV_DATA_LEN is empty Liping Zhang
2017-03-21 10:18 ` Pablo Neira Ayuso
2017-03-21 14:26 ` Liping Zhang
2017-03-19 14:35 ` [PATCH nf 2/5] netfilter: nfnl_cthelper: fix incorrect helper->expect_class_max Liping Zhang
2017-03-21 10:27 ` Pablo Neira Ayuso [this message]
2017-03-21 14:35 ` Liping Zhang
2017-03-21 14:49 ` Pablo Neira Ayuso
2017-03-19 14:36 ` [PATCH nf 3/5] netfilter: drop const qualifier from struct nf_conntrack_expect_policy Liping Zhang
2017-03-21 10:34 ` Pablo Neira Ayuso
2017-03-21 15:00 ` Liping Zhang
2017-03-21 15:03 ` Pablo Neira Ayuso
2017-03-19 14:36 ` [PATCH nf 4/5] netfilter: nfnl_cthelper: fix memory leak when do update Liping Zhang
2017-03-21 10:32 ` Pablo Neira Ayuso
2017-03-21 13:23 ` Pablo Neira Ayuso
2017-03-19 14:36 ` [PATCH nf 5/5] netfilter: nfnl_cthelper: fix a race when walk the nf_ct_helper_hash table Liping Zhang
2017-03-21 10:33 ` Pablo Neira Ayuso
2017-03-21 14:48 ` Liping Zhang
2017-03-21 15:19 ` Liping Zhang
2017-03-21 15:26 ` Pablo Neira Ayuso
2017-03-22 0:06 ` Liping Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170321102752.GB1940@salvia \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=zlpnobody@163.com \
--cc=zlpnobody@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).