From patchwork Fri Nov 14 17:44:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 410956 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2E4AB1400D5 for ; Sat, 15 Nov 2014 04:42:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161630AbaKNRml (ORCPT ); Fri, 14 Nov 2014 12:42:41 -0500 Received: from mail.us.es ([193.147.175.20]:46504 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161471AbaKNRmj (ORCPT ); Fri, 14 Nov 2014 12:42:39 -0500 Received: (qmail 21574 invoked from network); 14 Nov 2014 18:42:38 +0100 Received: from unknown (HELO us.es) (192.168.2.11) by us.es with SMTP; 14 Nov 2014 18:42:38 +0100 Received: (qmail 11270 invoked by uid 507); 14 Nov 2014 17:42:38 -0000 X-Qmail-Scanner-Diagnostics: from 127.0.0.1 by antivirus1 (envelope-from , uid 501) with qmail-scanner-2.10 (clamdscan: 0.98.4/19628. spamassassin: 3.3.2. Clear:RC:1(127.0.0.1):SA:0(-103.2/7.5):. Processed in 2.163831 secs); 14 Nov 2014 17:42:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on antivirus1 X-Spam-Level: X-Spam-Status: No, score=-103.2 required=7.5 tests=BAYES_50,SMTPAUTH_US, SPF_HELO_FAIL,USER_IN_WHITELIST autolearn=disabled version=3.3.2 X-Spam-ASN: AS12715 87.216.0.0/16 X-Envelope-From: pneira@us.es Received: from unknown (HELO antivirus1) (127.0.0.1) by us.es with SMTP; 14 Nov 2014 17:42:36 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus1 (F-Secure/fsigk_smtp/412/antivirus1); Fri, 14 Nov 2014 18:42:36 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/412/antivirus1) Received: (qmail 31384 invoked from network); 14 Nov 2014 18:42:35 +0100 Received: from 129.166.216.87.static.jazztel.es (HELO us.es) (1984lsi@87.216.166.129) by mail.us.es with AES128-SHA encrypted SMTP; 14 Nov 2014 18:42:35 +0100 Date: Fri, 14 Nov 2014 18:44:38 +0100 From: Pablo Neira Ayuso To: Andrey Ryabinin Cc: Patrick McHardy , Jozsef Kadlecsik , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, "netdev@vger.kernel.org" , linux-kernel@vger.kernel.org Subject: Re: [BUG] index is out of range for nfnl_group2type[] Message-ID: <20141114174438.GA10644@salvia> References: <5464733B.5060505@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5464733B.5060505@samsung.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Nov 13, 2014 at 12:00:43PM +0300, Andrey Ryabinin wrote: > FYI I've spotted this: > > [ 180.202810] ================================================================================ > [ 180.203600] UBSan: Undefined behaviour in ../net/netfilter/nfnetlink.c:467:28 > [ 180.204249] index 9 is out of range for type 'int [9]' > [ 180.204697] CPU: 0 PID: 1771 Comm: trinity-main Not tainted 3.18.0-rc4-mm1+ #122 > [ 180.205365] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014 > [ 180.206498] 0000000000000018 0000000000000000 0000000000000009 ffff88007bdf7da8 > [ 180.207220] ffffffff82b0ef5f 0000000000000092 ffffffff845ae2e0 ffff88007bdf7db8 > [ 180.207887] ffffffff8199e489 ffff88007bdf7e18 ffffffff8199ea22 0000003900000000 > [ 180.208639] Call Trace: > [ 180.208857] dump_stack (lib/dump_stack.c:52) > [ 180.209370] ubsan_epilogue (lib/ubsan.c:174) > [ 180.209849] __ubsan_handle_out_of_bounds (lib/ubsan.c:400) > [ 180.210512] nfnetlink_bind (net/netfilter/nfnetlink.c:467) > [ 180.210986] netlink_bind (net/netlink/af_netlink.c:1483) > [ 180.211495] SYSC_bind (net/socket.c:1541) > [ 180.211940] ? security_socket_setsockopt (security/security.c:1208) > [ 180.212541] ? SyS_setsockopt (net/socket.c:1920 net/socket.c:1900) > [ 180.213057] ? SyS_write (fs/read_write.c:276 fs/read_write.c:588 fs/read_write.c:577) > [ 180.213506] SyS_bind (net/socket.c:1527) > [ 180.213919] system_call_fastpath (arch/x86/kernel/entry_64.S:423) > [ 180.214479] ================================================================================ Thanks for reporting. I think the attached patch fixes this problem. From 289a727f1561b4e228078d60235f77e88b350f84 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 14 Nov 2014 18:14:33 +0100 Subject: [PATCH] netfilter: nfnetlink: fix insufficient validation in nfnetlink_bind Make sure the netlink group exists, otherwise this trigger an out of bound array memory access from the netlink_bind() path. This splat can only be triggered only by superuser. [ 180.203600] UBSan: Undefined behaviour in ../net/netfilter/nfnetlink.c:467:28 [ 180.204249] index 9 is out of range for type 'int [9]' [ 180.204697] CPU: 0 PID: 1771 Comm: trinity-main Not tainted 3.18.0-rc4-mm1+ #122 [ 180.205365] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org +04/01/2014 [ 180.206498] 0000000000000018 0000000000000000 0000000000000009 ffff88007bdf7da8 [ 180.207220] ffffffff82b0ef5f 0000000000000092 ffffffff845ae2e0 ffff88007bdf7db8 [ 180.207887] ffffffff8199e489 ffff88007bdf7e18 ffffffff8199ea22 0000003900000000 [ 180.208639] Call Trace: [ 180.208857] dump_stack (lib/dump_stack.c:52) [ 180.209370] ubsan_epilogue (lib/ubsan.c:174) [ 180.209849] __ubsan_handle_out_of_bounds (lib/ubsan.c:400) [ 180.210512] nfnetlink_bind (net/netfilter/nfnetlink.c:467) [ 180.210986] netlink_bind (net/netlink/af_netlink.c:1483) [ 180.211495] SYSC_bind (net/socket.c:1541) Moreover, define the missing nf_tables and nf_acct multicast groups too to skip. Reported-by: Andrey Ryabinin Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nfnetlink.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c index 6c5a915..13c2e17 100644 --- a/net/netfilter/nfnetlink.c +++ b/net/netfilter/nfnetlink.c @@ -47,6 +47,8 @@ static const int nfnl_group2type[NFNLGRP_MAX+1] = { [NFNLGRP_CONNTRACK_EXP_NEW] = NFNL_SUBSYS_CTNETLINK_EXP, [NFNLGRP_CONNTRACK_EXP_UPDATE] = NFNL_SUBSYS_CTNETLINK_EXP, [NFNLGRP_CONNTRACK_EXP_DESTROY] = NFNL_SUBSYS_CTNETLINK_EXP, + [NFNLGRP_NFTABLES] = NFNL_SUBSYS_NFTABLES, + [NFNLGRP_ACCT_QUOTA] = NFNL_SUBSYS_ACCT, }; void nfnl_lock(__u8 subsys_id) @@ -464,7 +466,12 @@ static void nfnetlink_rcv(struct sk_buff *skb) static int nfnetlink_bind(int group) { const struct nfnetlink_subsystem *ss; - int type = nfnl_group2type[group]; + int type; + + if (group <= NFNLGRP_NONE || group > NFNLGRP_MAX) + return -EINVAL; + + type = nfnl_group2type[group]; rcu_read_lock(); ss = nfnetlink_get_subsys(type); @@ -514,6 +521,9 @@ static int __init nfnetlink_init(void) { int i; + for (i = NFNLGRP_NONE + 1; i <= NFNLGRP_MAX; i++) + BUG_ON(nfnl_group2type[i] == NFNL_SUBSYS_NONE); + for (i=0; i