netfilter: x_tables: fix pointer leaks to userspace
authorDmitry Vyukov <dvyukov@google.com>
Mon, 29 Jan 2018 12:21:20 +0000 (13:21 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Apr 2018 09:02:13 +0000 (11:02 +0200)
[ Upstream commit 1e98ffea5a8935ec040ab72299e349cb44b8defd ]

Several netfilter matches and targets put kernel pointers into
info objects, but don't set usersize in descriptors.
This leads to kernel pointer leaks if a match/target is set
and then read back to userspace.

Properly set usersize for these matches/targets.

Found with manual code inspection.

Fixes: ec2318904965 ("xtables: extend matches and targets with .usersize")
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netfilter/xt_IDLETIMER.c
net/netfilter/xt_LED.c
net/netfilter/xt_limit.c
net/netfilter/xt_nfacct.c
net/netfilter/xt_statistic.c

index bb5d6a058fb7bca388d279e224ed22d019b1394b..1141f08810b6f228796cedec53bfe73f551f6d30 100644 (file)
@@ -256,6 +256,7 @@ static struct xt_target idletimer_tg __read_mostly = {
        .family         = NFPROTO_UNSPEC,
        .target         = idletimer_tg_target,
        .targetsize     = sizeof(struct idletimer_tg_info),
+       .usersize       = offsetof(struct idletimer_tg_info, timer),
        .checkentry     = idletimer_tg_checkentry,
        .destroy        = idletimer_tg_destroy,
        .me             = THIS_MODULE,
index 0858fe17e14a22a0b4dde95fc8d02aeb6fda8117..2d1c5c169a26baf62f60a25667d5801b5d7d9247 100644 (file)
@@ -198,6 +198,7 @@ static struct xt_target led_tg_reg __read_mostly = {
        .family         = NFPROTO_UNSPEC,
        .target         = led_tg,
        .targetsize     = sizeof(struct xt_led_info),
+       .usersize       = offsetof(struct xt_led_info, internal_data),
        .checkentry     = led_tg_check,
        .destroy        = led_tg_destroy,
        .me             = THIS_MODULE,
index d27b5f1ea619f9696912b58bd5012358206725d7..61403b77361cbfdf55db2a6c824a21003fb82b22 100644 (file)
@@ -193,9 +193,8 @@ static struct xt_match limit_mt_reg __read_mostly = {
        .compatsize       = sizeof(struct compat_xt_rateinfo),
        .compat_from_user = limit_mt_compat_from_user,
        .compat_to_user   = limit_mt_compat_to_user,
-#else
-       .usersize         = offsetof(struct xt_rateinfo, prev),
 #endif
+       .usersize         = offsetof(struct xt_rateinfo, prev),
        .me               = THIS_MODULE,
 };
 
index cc0518fe598e459f27de36984e0313c73c43b61f..6f92d25590a85d8db7bb6ccec30a298f7206448e 100644 (file)
@@ -62,6 +62,7 @@ static struct xt_match nfacct_mt_reg __read_mostly = {
        .match      = nfacct_mt,
        .destroy    = nfacct_mt_destroy,
        .matchsize  = sizeof(struct xt_nfacct_match_info),
+       .usersize   = offsetof(struct xt_nfacct_match_info, nfacct),
        .me         = THIS_MODULE,
 };
 
index 11de55e7a868950c6b9ad5bbfa0a0561eb8787d7..8710fdba2ae23eeb4f59a5f4efdada6884fde89d 100644 (file)
@@ -84,6 +84,7 @@ static struct xt_match xt_statistic_mt_reg __read_mostly = {
        .checkentry = statistic_mt_check,
        .destroy    = statistic_mt_destroy,
        .matchsize  = sizeof(struct xt_statistic_info),
+       .usersize   = offsetof(struct xt_statistic_info, master),
        .me         = THIS_MODULE,
 };