Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3762322imm; Mon, 18 Jun 2018 03:44:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLCrauJ8ZtaFxVDb8dCRekjhDHEdQ4lFXxAUymk/qEopkhCAR5Ff6LkdpkK6LdfFKLL7isN X-Received: by 2002:a65:5b8b:: with SMTP id i11-v6mr10528075pgr.225.1529318641239; Mon, 18 Jun 2018 03:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529318641; cv=none; d=google.com; s=arc-20160816; b=WevX8SpiKqtrZwXnC3oSJ51Y/vwBgcy/2U36Cff8NaStij0otL/t4ajJn54VJPYczd e3OJ1gBj2PFjA8c+KCIE0fzrvcG7Dc5Jkyq5GMwVuQlfF6ZJnLprI0LqWCy80mPDNkzq uj3nw7ssKJ41JxNmAbk4EvfUIrw93zm7xDGpk3URDq8jB9ij67/Xdi0g6e7xY0RPlcTL 6Hglm7oG/QrDn3REtlZIAjoESrOMijU6H1KDUpiJw80QStiFaoGbDIMNGDwyPurH3R4Z U2M029N2Wrq2CDn3oxwyyc4eTQxgXKhFd566yXv4pFPP+ATatm09vc/kucy7KaNsSOWf a6bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=pPl7knZt3clzhTcNKWMKdvzCKAqyzHtE8slgK5OIPss=; b=BA5FjmGEJLAvMMsq8yZgQm6AckEvpuoRI3YHt1t6jtCibB+mRuXEMTwLvZH+6L01UE pI9em3XS1fqdtKimOTa1Syk/1RJeFahBzE2+zf5v65uVMkRwpTAen3lLMr3R40nDHDWp 8Xby/dxWB6XmxNz7BdtVqwkzWzLolgkp4haOQVqSct/K4CKFh0IOfYsSwAr8QINwuiwO q4zjfWf5FHnARrYMIDcRDNwAMwMeFidGXNjc3VIqI1BsFnsxLkjWlNIWsIeBw41VVZl7 ZlEhYcj/Cpp/lNn+Vi6FWR8KTytwI5CEo9Rk6gwQogC+2SHl38yormn49ExExhexntnZ mjIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k185-v6si11859079pgd.22.2018.06.18.03.43.47; Mon, 18 Jun 2018 03:44:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935517AbeFRITh (ORCPT + 99 others); Mon, 18 Jun 2018 04:19:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54906 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935488AbeFRITf (ORCPT ); Mon, 18 Jun 2018 04:19:35 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 85437BAD; Mon, 18 Jun 2018 08:19:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.16 055/279] netfilter: nf_tables: fix out-of-bounds in nft_chain_commit_update Date: Mon, 18 Jun 2018 10:10:40 +0200 Message-Id: <20180618080611.115752044@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Taehee Yoo [ Upstream commit d71efb599ad42ef1e564c652d8084252bdc85edf ] When chain name is changed, nft_chain_commit_update is called. In the nft_chain_commit_update, trans->ctx.chain->name has old chain name and nft_trans_chain_name(trans) has new chain name. If new chain name is longer than old chain name, KASAN warns slab-out-of-bounds. [ 175.015012] BUG: KASAN: slab-out-of-bounds in strcpy+0x9e/0xb0 [ 175.022735] Write of size 1 at addr ffff880114e022da by task iptables-compat/1458 [ 175.031353] CPU: 0 PID: 1458 Comm: iptables-compat Not tainted 4.16.0-rc7+ #146 [ 175.031353] Hardware name: To be filled by O.E.M. To be filled by O.E.M./Aptio CRB, BIOS 5.6.5 07/08/2015 [ 175.031353] Call Trace: [ 175.031353] dump_stack+0x68/0xa0 [ 175.031353] print_address_description+0xd0/0x260 [ 175.031353] ? strcpy+0x9e/0xb0 [ 175.031353] kasan_report+0x234/0x350 [ 175.031353] __asan_report_store1_noabort+0x1c/0x20 [ 175.031353] strcpy+0x9e/0xb0 [ 175.031353] nf_tables_commit+0x1ccc/0x2990 [ 175.031353] nfnetlink_rcv+0x141e/0x16c0 [ 175.031353] ? nfnetlink_net_init+0x150/0x150 [ 175.031353] ? lock_acquire+0x370/0x370 [ 175.031353] ? lock_acquire+0x370/0x370 [ 175.031353] netlink_unicast+0x444/0x640 [ 175.031353] ? netlink_attachskb+0x700/0x700 [ 175.031353] ? _copy_from_iter_full+0x180/0x740 [ 175.031353] ? kasan_check_write+0x14/0x20 [ 175.031353] ? _copy_from_user+0x9b/0xd0 [ 175.031353] netlink_sendmsg+0x845/0xc70 [ ... ] Steps to reproduce: iptables-compat -N 1 iptables-compat -E 1 aaaaaaaaa Signed-off-by: Taehee Yoo Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5741,7 +5741,7 @@ static void nft_chain_commit_update(stru struct nft_base_chain *basechain; if (nft_trans_chain_name(trans)) - strcpy(trans->ctx.chain->name, nft_trans_chain_name(trans)); + swap(trans->ctx.chain->name, nft_trans_chain_name(trans)); if (!nft_is_base_chain(trans->ctx.chain)) return;