Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4822047ybl; Wed, 22 Jan 2020 05:24:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyr+QD6ZEasWNk/U+TRUMDxfhVFioPDNkNQFyaTP7hiXgBcAyOYhU+9OljinH6TL6CfvMae X-Received: by 2002:a9d:ed5:: with SMTP id 79mr7361616otj.72.1579699461520; Wed, 22 Jan 2020 05:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699461; cv=none; d=google.com; s=arc-20160816; b=vkwI7H14CDoTgmBT8WWzIlE0rDVy7TwzXDwoRRrQJzwJuvlb7rjuhtCyqon5SQnJ4F 6NqLi0rsRU06Zc6zLwba3NUUoKDR4QSxjPxpQV/iuaY+mAc6VNJUE1HDeaOsocRHHPV6 vP0m/aEb1kOgInkSQ95xgw0+j9BQu5ofoxjFQ0HBrgNvik9JDaxs+QoK7lIiNcESU0Pn TLhFnfi65jfNoc6p/dFPB+S0z+SoL4GBmLvWehY/E27ARup4OiI+g+gOkHI/p5swO6tc xudv5RlqUSAAfHIQjst1qfz3wnDmpf0em3c2qaxW9C4Va22ikXpmuwRUMBV3iCbMEo42 LxyA== 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=i5E1NJMFzF9hxaQtWYrWC6iUEsF9Q4EADInrufuhtPQ=; b=XE6trqgAp+GLmTVIAoRLA4yTfyZFf8tKmmQDld4ALaEicfcNMSFKoliYDWUJXvePJm pCVckSV5Qfn7BN89cO2EtYjwHbK1Br5kbyICt0HRjLxmPxj1/d6HdHJIi2JXHgTQDFUr YLAxeTvaV/FA5iPCVZKjn6tr7c6+9pMncl05xD2zsTOVUZ+hDomzYSZNmVvx7ZnFeRPT 7Ph7MzymXIvjFss89j8xYyP5A7VhFHnOSQspwlDsLZmled78ciX4tuEM2AnwxTanJh4L acNMSggGhJiLjTd3uMLiOkNvUftCiVwGMRHejEP4Px6EC4HisbAA4benJbZiIvtHOSp4 1HZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CWGbFxz2; 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 q20si25479765otn.297.2020.01.22.05.24.09; Wed, 22 Jan 2020 05:24:21 -0800 (PST) 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=CWGbFxz2; 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 S1730676AbgAVNWy (ORCPT + 99 others); Wed, 22 Jan 2020 08:22:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:40788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730652AbgAVNWy (ORCPT ); Wed, 22 Jan 2020 08:22:54 -0500 Received: from localhost (unknown [84.241.205.26]) (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 E8FAE2468D; Wed, 22 Jan 2020 13:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699373; bh=6NtJ9UafG3cuTFTtzvHNxKudtUCKxLtTXakcpYPcA38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CWGbFxz2RseYnqDkvxF7l3AoFI1ACizOqagQHP2GYTlOJiWK5HJS4w5o+PGaDUHZ3 /ghDOOiMrdQMExmsV1dmeCV/0O8VcqzQs9M3yqb7qrkCMkJ+kDltvQylvzNIE+5tyJ 5j1lKEwjnyege4S4v0iZwcGMWOTe00rvHyKe9SOk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+91bdd8eece0f6629ec8b@syzkaller.appspotmail.com, Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 5.4 125/222] netfilter: arp_tables: init netns pointer in xt_tgdtor_param struct Date: Wed, 22 Jan 2020 10:28:31 +0100 Message-Id: <20200122092842.701677221@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@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 From: Florian Westphal commit 212e7f56605ef9688d0846db60c6c6ec06544095 upstream. An earlier commit (1b789577f655060d98d20e, "netfilter: arp_tables: init netns pointer in xt_tgchk_param struct") fixed missing net initialization for arptables, but turns out it was incomplete. We can get a very similar struct net NULL deref during error unwinding: general protection fault: 0000 [#1] PREEMPT SMP KASAN RIP: 0010:xt_rateest_put+0xa1/0x440 net/netfilter/xt_RATEEST.c:77 xt_rateest_tg_destroy+0x72/0xa0 net/netfilter/xt_RATEEST.c:175 cleanup_entry net/ipv4/netfilter/arp_tables.c:509 [inline] translate_table+0x11f4/0x1d80 net/ipv4/netfilter/arp_tables.c:587 do_replace net/ipv4/netfilter/arp_tables.c:981 [inline] do_arpt_set_ctl+0x317/0x650 net/ipv4/netfilter/arp_tables.c:1461 Also init the netns pointer in xt_tgdtor_param struct. Fixes: add67461240c1d ("netfilter: add struct net * to target parameters") Reported-by: syzbot+91bdd8eece0f6629ec8b@syzkaller.appspotmail.com Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/ipv4/netfilter/arp_tables.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -496,12 +496,13 @@ static inline int check_entry_size_and_h return 0; } -static inline void cleanup_entry(struct arpt_entry *e) +static void cleanup_entry(struct arpt_entry *e, struct net *net) { struct xt_tgdtor_param par; struct xt_entry_target *t; t = arpt_get_target(e); + par.net = net; par.target = t->u.kernel.target; par.targinfo = t->data; par.family = NFPROTO_ARP; @@ -584,7 +585,7 @@ static int translate_table(struct net *n xt_entry_foreach(iter, entry0, newinfo->size) { if (i-- == 0) break; - cleanup_entry(iter); + cleanup_entry(iter, net); } return ret; } @@ -927,7 +928,7 @@ static int __do_replace(struct net *net, /* Decrease module usage counts and free resource */ loc_cpu_old_entry = oldinfo->entries; xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size) - cleanup_entry(iter); + cleanup_entry(iter, net); xt_free_table_info(oldinfo); if (copy_to_user(counters_ptr, counters, @@ -990,7 +991,7 @@ static int do_replace(struct net *net, c free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) - cleanup_entry(iter); + cleanup_entry(iter, net); free_newinfo: xt_free_table_info(newinfo); return ret; @@ -1287,7 +1288,7 @@ static int compat_do_replace(struct net free_newinfo_untrans: xt_entry_foreach(iter, loc_cpu_entry, newinfo->size) - cleanup_entry(iter); + cleanup_entry(iter, net); free_newinfo: xt_free_table_info(newinfo); return ret; @@ -1514,7 +1515,7 @@ static int do_arpt_get_ctl(struct sock * return ret; } -static void __arpt_unregister_table(struct xt_table *table) +static void __arpt_unregister_table(struct net *net, struct xt_table *table) { struct xt_table_info *private; void *loc_cpu_entry; @@ -1526,7 +1527,7 @@ static void __arpt_unregister_table(stru /* Decrease module usage counts and free resources */ loc_cpu_entry = private->entries; xt_entry_foreach(iter, loc_cpu_entry, private->size) - cleanup_entry(iter); + cleanup_entry(iter, net); if (private->number > private->initial_entries) module_put(table_owner); xt_free_table_info(private); @@ -1566,7 +1567,7 @@ int arpt_register_table(struct net *net, ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks)); if (ret != 0) { - __arpt_unregister_table(new_table); + __arpt_unregister_table(net, new_table); *res = NULL; } @@ -1581,7 +1582,7 @@ void arpt_unregister_table(struct net *n const struct nf_hook_ops *ops) { nf_unregister_net_hooks(net, ops, hweight32(table->valid_hooks)); - __arpt_unregister_table(table); + __arpt_unregister_table(net, table); } /* The built-in targets: standard (NULL) and error. */