From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Phil Turnbull <phil.turnbull@oracle.com>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Ben Hutchings <ben.hutchings@codethink.co.uk>
Subject: [PATCH 4.4 12/17] netfilter: nfnetlink: correctly validate length of batch messages
Date: Fri, 28 Apr 2017 10:30:25 +0200 [thread overview]
Message-ID: <20170428082912.076133196@linuxfoundation.org> (raw)
In-Reply-To: <20170428082910.160564394@linuxfoundation.org>
4.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Phil Turnbull <phil.turnbull@oracle.com>
commit c58d6c93680f28ac58984af61d0a7ebf4319c241 upstream.
If nlh->nlmsg_len is zero then an infinite loop is triggered because
'skb_pull(skb, msglen);' pulls zero bytes.
The calculation in nlmsg_len() underflows if 'nlh->nlmsg_len <
NLMSG_HDRLEN' which bypasses the length validation and will later
trigger an out-of-bound read.
If the length validation does fail then the malformed batch message is
copied back to userspace. However, we cannot do this because the
nlh->nlmsg_len can be invalid. This leads to an out-of-bounds read in
netlink_ack:
[ 41.455421] ==================================================================
[ 41.456431] BUG: KASAN: slab-out-of-bounds in memcpy+0x1d/0x40 at addr ffff880119e79340
[ 41.456431] Read of size 4294967280 by task a.out/987
[ 41.456431] =============================================================================
[ 41.456431] BUG kmalloc-512 (Not tainted): kasan: bad access detected
[ 41.456431] -----------------------------------------------------------------------------
...
[ 41.456431] Bytes b4 ffff880119e79310: 00 00 00 00 d5 03 00 00 b0 fb fe ff 00 00 00 00 ................
[ 41.456431] Object ffff880119e79320: 20 00 00 00 10 00 05 00 00 00 00 00 00 00 00 00 ...............
[ 41.456431] Object ffff880119e79330: 14 00 0a 00 01 03 fc 40 45 56 11 22 33 10 00 05 .......@EV."3...
[ 41.456431] Object ffff880119e79340: f0 ff ff ff 88 99 aa bb 00 14 00 0a 00 06 fe fb ................
^^ start of batch nlmsg with
nlmsg_len=4294967280
...
[ 41.456431] Memory state around the buggy address:
[ 41.456431] ffff880119e79400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 41.456431] ffff880119e79480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[ 41.456431] >ffff880119e79500: 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc fc
[ 41.456431] ^
[ 41.456431] ffff880119e79580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 41.456431] ffff880119e79600: fc fc fc fc fc fc fc fc fc fc fb fb fb fb fb fb
[ 41.456431] ==================================================================
Fix this with better validation of nlh->nlmsg_len and by setting
NFNL_BATCH_FAILURE if any batch message fails length validation.
CAP_NET_ADMIN is required to trigger the bugs.
Fixes: 9ea2aa8b7dba ("netfilter: nfnetlink: validate nfnetlink header from batch")
Signed-off-by: Phil Turnbull <phil.turnbull@oracle.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
net/netfilter/nfnetlink.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -326,10 +326,12 @@ replay:
nlh = nlmsg_hdr(skb);
err = 0;
- if (nlmsg_len(nlh) < sizeof(struct nfgenmsg) ||
- skb->len < nlh->nlmsg_len) {
- err = -EINVAL;
- goto ack;
+ if (nlh->nlmsg_len < NLMSG_HDRLEN ||
+ skb->len < nlh->nlmsg_len ||
+ nlmsg_len(nlh) < sizeof(struct nfgenmsg)) {
+ nfnl_err_reset(&err_list);
+ status |= NFNL_BATCH_FAILURE;
+ goto done;
}
/* Only requests are handled by the kernel */
next prev parent reply other threads:[~2017-04-28 8:53 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-28 8:30 [PATCH 4.4 00/17] 4.4.65-stable review Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 01/17] tipc: make sure IPv6 header fits in skb headroom Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 02/17] tipc: make dist queue pernet Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 03/17] tipc: re-enable compensation for socket receive buffer double counting Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 04/17] tipc: correct error in node fsm Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 05/17] tty: nozomi: avoid a harmless gcc warning Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 06/17] hostap: avoid uninitialized variable use in hfa384x_get_rid Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 07/17] gfs2: avoid uninitialized variable warning Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 08/17] tipc: fix random link resets while adding a second bearer Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 09/17] tipc: fix socket timer deadlock Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 10/17] mnt: Add a per mount namespace limit on the number of mounts Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 11/17] [media] xc2028: avoid use after free Greg Kroah-Hartman
2017-04-28 8:30 ` Greg Kroah-Hartman [this message]
2017-04-28 8:30 ` [PATCH 4.4 14/17] vfio/pci: Fix integer overflows, bitmask check Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 15/17] staging/android/ion : fix a race condition in the ion driver Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 16/17] ping: implement proper locking Greg Kroah-Hartman
2017-04-28 8:30 ` [PATCH 4.4 17/17] perf/core: Fix concurrent sys_perf_event_open() vs. move_group race Greg Kroah-Hartman
2017-04-28 18:46 ` [PATCH 4.4 00/17] 4.4.65-stable review Guenter Roeck
2017-04-29 7:41 ` Greg Kroah-Hartman
2017-04-28 19:18 ` Shuah Khan
2017-04-29 7:41 ` Greg Kroah-Hartman
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=20170428082912.076133196@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=ben.hutchings@codethink.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil.turnbull@oracle.com \
--cc=stable@vger.kernel.org \
/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).