Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1532825ybl; Thu, 22 Aug 2019 16:34:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyA4IoEuzHxMfQeNSmGopJr8QaLO718TGZQe9qx8bJhUuOSiL8zef5/FvlGPQaKtxcD3s0s X-Received: by 2002:a17:902:e83:: with SMTP id 3mr1338049plx.319.1566516874806; Thu, 22 Aug 2019 16:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566516874; cv=none; d=google.com; s=arc-20160816; b=EbU8G6DGK9mGmAWnmEj0DdyS3wZG22Ch4QXGNbe9yV1LqCubsjfyLjygA2Y7dmeqXb yYR5OFt3LhXricAlVCkbD8UGXBVwys4Fyd27KtK6Z92YvSrPaH0BWB6raYVOL/IztwP6 mkKmX1z509Cf7HAZKC7VuzhOmOxz7eyssyFJ7H6RZwu4ku5VWHvJxfVUfb5faiigLNvL NYB0Pfym32DlE1XvUZqDYGkmDWom2Rvy+uqZ5SS8vuKMucVj26hWcaKd/i2tKLJuZ2FJ PHArnbP/usZKcPr1PsLCE0AlNRiOuT1FsvrWwX2HJFar/MAls/5pfymc/BrhKmrmjVJ+ S2Nw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3E0hh8iyQJXr7cmvW5ExYgKarrsXDLN9hOm1DDeFlRg=; b=Z4Hi29AzwG7yrOmKZx2ncswwokzwEB7nRLDWia/s0eUWsu9exKCDZFkhzZynZm820H 94gPOFMnMkkq+YBstDCyQ7m9O3fDPQnuX7nWhRHPwyw/Y+VoiKYYUctkrL0hnegq3w+D obn4iZMzkvbXG2S8k7DUX2ODUsg5A5wEw2m/KGz0G8KVwkoSjZ9N3agKeanHR/KFZDSG iseqiv2+gr1StEKhstRyjHJ0qeCVcYSnNMq/HI4L+cXkeYdoN/hqTVgjsLOmWMQErROl 8IoK8Y6xIQ8KWJONzLGQpNHi0vzy/HjNc+txIl/JFWMwF9HWjhwaFH3Y+wKXnPKZ9fLT oFRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b2swMwEt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k193si548711pge.330.2019.08.22.16.34.16; Thu, 22 Aug 2019 16:34:34 -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=b2swMwEt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391261AbfHVRQz (ORCPT + 99 others); Thu, 22 Aug 2019 13:16:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:58190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390367AbfHVRIc (ORCPT ); Thu, 22 Aug 2019 13:08:32 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E668723405; Thu, 22 Aug 2019 17:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493711; bh=Pi5oWISMQ3clPukYbzRDrIssXpOIiF0xTx9td2Nxsno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b2swMwEt7laZSW6sYMxAgbtS9As+rzJVCVE64+F0AMJluIlEXp/wT3E8HuMomzfu6 XGlHsBvjUxb8WVHrZDY+8HA/pt44M2QFjURd6blxX7NAiKNtmRNmUFo/ObwEGunwrb McicPEoyZELVL9PB+aXlom7Bot/rGw+ViC0BMxhE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Florian Westphal , syzbot+276ddebab3382bbf72db@syzkaller.appspotmail.com, Pablo Neira Ayuso , Greg Kroah-Hartman Subject: [PATCH 5.2 031/135] netfilter: ebtables: also count base chain policies Date: Thu, 22 Aug 2019 13:06:27 -0400 Message-Id: <20190822170811.13303-32-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Westphal commit 3b48300d5cc7c7bed63fddb006c4046549ed4aec upstream. ebtables doesn't include the base chain policies in the rule count, so we need to add them manually when we call into the x_tables core to allocate space for the comapt offset table. This lead syzbot to trigger: WARNING: CPU: 1 PID: 9012 at net/netfilter/x_tables.c:649 xt_compat_add_offset.cold+0x11/0x36 net/netfilter/x_tables.c:649 Reported-by: syzbot+276ddebab3382bbf72db@syzkaller.appspotmail.com Fixes: 2035f3ff8eaa ("netfilter: ebtables: compat: un-break 32bit setsockopt when no rules are present") Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/bridge/netfilter/ebtables.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index 963dfdc148272..1fa9ac483173d 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -1770,20 +1770,28 @@ static int compat_calc_entry(const struct ebt_entry *e, return 0; } +static int ebt_compat_init_offsets(unsigned int number) +{ + if (number > INT_MAX) + return -EINVAL; + + /* also count the base chain policies */ + number += NF_BR_NUMHOOKS; + + return xt_compat_init_offsets(NFPROTO_BRIDGE, number); +} static int compat_table_info(const struct ebt_table_info *info, struct compat_ebt_replace *newinfo) { unsigned int size = info->entries_size; const void *entries = info->entries; + int ret; newinfo->entries_size = size; - if (info->nentries) { - int ret = xt_compat_init_offsets(NFPROTO_BRIDGE, - info->nentries); - if (ret) - return ret; - } + ret = ebt_compat_init_offsets(info->nentries); + if (ret) + return ret; return EBT_ENTRY_ITERATE(entries, size, compat_calc_entry, info, entries, newinfo); @@ -2234,11 +2242,9 @@ static int compat_do_replace(struct net *net, void __user *user, xt_compat_lock(NFPROTO_BRIDGE); - if (tmp.nentries) { - ret = xt_compat_init_offsets(NFPROTO_BRIDGE, tmp.nentries); - if (ret < 0) - goto out_unlock; - } + ret = ebt_compat_init_offsets(tmp.nentries); + if (ret < 0) + goto out_unlock; ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state); if (ret < 0) -- 2.20.1