netfilter: xt_hashlimit: use _ALL macro to reject unknown flag bits
authorFlorian Westphal <fw@strlen.de>
Thu, 10 May 2012 22:11:54 +0000 (22:11 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 16 May 2012 22:56:31 +0000 (00:56 +0200)
David Miller says:
     The canonical way to validate if the set bits are in a valid
     range is to have a "_ALL" macro, and test:
     if (val & ~XT_HASHLIMIT_ALL)
         goto err;"

make it so.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/linux/netfilter/xt_hashlimit.h
net/netfilter/xt_hashlimit.c

index 05fe7993dd761633664885025af3ca7d65c5be70..c42e52f39f8fa57b0bf8d541ee295fd15821e0f2 100644 (file)
@@ -22,10 +22,12 @@ enum {
        XT_HASHLIMIT_HASH_SPT = 1 << 3,
        XT_HASHLIMIT_INVERT   = 1 << 4,
        XT_HASHLIMIT_BYTES    = 1 << 5,
+};
 #ifdef __KERNEL__
-       XT_HASHLIMIT_MAX      = 1 << 6,
+#define XT_HASHLIMIT_ALL (XT_HASHLIMIT_HASH_DIP | XT_HASHLIMIT_HASH_DPT | \
+                         XT_HASHLIMIT_HASH_SIP | XT_HASHLIMIT_HASH_SPT | \
+                         XT_HASHLIMIT_INVERT | XT_HASHLIMIT_BYTES)
 #endif
-};
 
 struct hashlimit_cfg {
        __u32 mode;       /* bitmask of XT_HASHLIMIT_HASH_* */
index 5d5af1d04fa2bf04f05fb89d0472c6a1a615b00b..26a668a84aa288a82dc3eb243df2728a3169b2a2 100644 (file)
@@ -647,7 +647,7 @@ static int hashlimit_mt_check(const struct xt_mtchk_param *par)
                        return -EINVAL;
        }
 
-       if (info->cfg.mode >= XT_HASHLIMIT_MAX) {
+       if (info->cfg.mode & ~XT_HASHLIMIT_ALL) {
                pr_info("Unknown mode mask %X, kernel too old?\n",
                                                info->cfg.mode);
                return -EINVAL;