Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp460681yba; Wed, 15 May 2019 04:30:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7uxGiSbR6/0NowHjQZQjDYXqLwBu1j9hdBeISmovFsiPQzT9iFwN4x+CbsFnl64/oIODZ X-Received: by 2002:a17:902:9f83:: with SMTP id g3mr27408932plq.330.1557919849317; Wed, 15 May 2019 04:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557919849; cv=none; d=google.com; s=arc-20160816; b=B4lo3O8RxnJdqPuq5ePQV9+LRnPI1b77BmIfzhUq7EsiRlT2N3EMTtH+IESDAPVYBr 4lJywjzzSz1qSSLZST+xCUEzVjaNCISTNWKn9lrM+hGdxIHpA60gds1OSaeQgKunRuRi t+eUOkl795q6rxdRThcPGhh+5+QVEPZZQQnvuv/J6yHRxrDjBWeISK8z0F8RB8QmRDSn MNOCBUaTsp22zZd4Vq34Zwyc8nuVdsGQiLvcwiCD3kYAOg9IAoBzo7e105KUPehDF5LT 0qUi6kuIsNVBLMlX1NzD5oJl30p71nIQZFpQ45sx9QQj2mmYMqoEX7mBVd5S3O8E+lvC pCVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BgniY9c9k/DQnKa8oKvnJr9Ko4wSk4fKgaXI5fRKp0M=; b=SIBAz0IcD2OdvvVMowVqUt5C9vNptL6AWxYXMoZSUOC93frwLQP9c3Icn9Pn4esH0E Huzbve3db3DukU4z6JWz2kChp1Mus7BY1el4pYJXGva5AZxq0lBCgOlfk2kmU8yZLtOO JwFd74Q5a3n+PLIrY7LEMxBxcOV5WBpF0MpqfCXtsMHaMsC1SF/QtCrp7DdEAf2159+g W58yl2CARqzA6rJpUMcHV5ZK5Yhu1wh1DsEor3Y3+A7uYyJAZc+ZimrJ5fh52PcEkRiA a9Sh8Kd9WZCBALpeDnyD6BfhWbABwj11qq5Orz004h+DIKrZQsCTMNIKbAdCsLXnNNxP yVAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ky/JnRbO"; 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 e40si1702742plb.180.2019.05.15.04.30.34; Wed, 15 May 2019 04:30:49 -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; dkim=pass header.i=@kernel.org header.s=default header.b="ky/JnRbO"; 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 S1732185AbfEOL2r (ORCPT + 99 others); Wed, 15 May 2019 07:28:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:39856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732434AbfEOL2n (ORCPT ); Wed, 15 May 2019 07:28:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8EEEF206BF; Wed, 15 May 2019 11:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919723; bh=2OasU5JmCB1n24w3mQY8vAviPP73G/mzqv6p+ILM9Ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ky/JnRbO9i0kdkdGOuOWotIwB6VcRzBS3g/7gLC+fwMp2rDdmn/ZFkhKdrooUZOWK 8uOpH3pySzWO9pJTGoDJmw+Zh4M39sv+TiJJV2lyPqOYIza1OhM42UuDrC7Clyzo4w omjUr4Ls8evmpT20mKVzGOBe9pNgLhuXRMeUxjxs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.0 067/137] netfilter: nf_tables: prevent shift wrap in nft_chain_parse_hook() Date: Wed, 15 May 2019 12:55:48 +0200 Message-Id: <20190515090658.323236652@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 33d1c018179d0a30c39cc5f1682b77867282694b ] I believe that "hook->num" can be up to UINT_MAX. Shifting more than 31 bits would is undefined in C but in practice it would lead to shift wrapping. That would lead to an array overflow in nf_tables_addchain(): ops->hook = hook.type->hooks[ops->hooknum]; Fixes: fe19c04ca137 ("netfilter: nf_tables: remove nhooks field from struct nft_af_info") Signed-off-by: Dan Carpenter Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index e2aac80f9b7b1..25c2b98b9a960 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -1502,7 +1502,7 @@ static int nft_chain_parse_hook(struct net *net, if (IS_ERR(type)) return PTR_ERR(type); } - if (!(type->hook_mask & (1 << hook->num))) + if (hook->num > NF_MAX_HOOKS || !(type->hook_mask & (1 << hook->num))) return -EOPNOTSUPP; if (type->type == NFT_CHAIN_T_NAT && -- 2.20.1