Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp470145ybl; Tue, 28 Jan 2020 06:28:18 -0800 (PST) X-Google-Smtp-Source: APXvYqypqg2l5vroorMJqabiQwmnqQrA7hpHojCfMM5s+gtCYN+LuVNYlv3G25xqqa4D3AtqBWHj X-Received: by 2002:a05:6830:1198:: with SMTP id u24mr16028418otq.215.1580221697830; Tue, 28 Jan 2020 06:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221697; cv=none; d=google.com; s=arc-20160816; b=sKgNn+gRgBsv7ilktk2mPff0J/KEhWHQi0xv/BQ2FCCum9f8RlkzD7TMHWoU2nkMKG 2BSc7BaLeISPS9yB6p6uZZYMrbbuocbIsD+PtSSRnsUNW17gDpP7V6+I5uZ74N4uTyY+ v2A/hKM2xJTbSsdz3u6c0l5mY6wWBr0mr1ylh3H/Znw+driRBijTatmFyVRx16m4639j 4N3L9gSvHaempHD07MbIEMp+0xVGlmB8Q5c1saoTyrKon9vuZ52o6xZOKmRFw9s3H4pp U7XNivLIBwiTQau6iuE3O918ZxeLGfBcU9UaF94vvHTNnEbsgJcgcdFfb8uIQMEaZCcn OpiQ== 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=Qmf62swnoIhN0T4YfYkdShA2qshqs3NIg4z97/uX4NU=; b=WeQUGlTVL6YsZNig4mbqZLBzwVACiwsvT4Hrb9Mbgx0+xXV+Frq9OBRhDX2IDTmsO6 TF5XQE8nS7aH5gOuP7P+0KDwV9hxi9dcpF4ILwuM4+vRg3VLf6w1qZW9nxQDHAn0BqXu ysyl7GMaodG1iu89brplQz3U2h2egwWPvff8UOwQ2xHCYQfIssKLHA1mIE0yinH7XeVt 5xj8XS2wvbvKteVmQPeIyFGdTws2ibmwMApGTZgenBf39XKokp1pMlBHSTQOOk8h8K98 VKXbnN39IbJwjupdOalJUMrp6Z77+ya38DVW8XSHsC4uSLfIFh08zUGHmIbiBge0IHT2 y4CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ox51Cdi4; 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 l140si2267198oib.114.2020.01.28.06.28.05; Tue, 28 Jan 2020 06:28:17 -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=Ox51Cdi4; 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 S1733161AbgA1O0O (ORCPT + 99 others); Tue, 28 Jan 2020 09:26:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:53516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732452AbgA1O0M (ORCPT ); Tue, 28 Jan 2020 09:26:12 -0500 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 E3A8C24686; Tue, 28 Jan 2020 14:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221570; bh=kkT6YiO+GlHgtDUnXg8CIwWUr3PK5wDQPNbN0rxBj10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ox51Cdi44DYXJRjc5cOwzm6nuWenUgxJWf2wWcSSo7XDASC6TlW0oBuiWI2BjTSCV h4tj6dEli6FvdV9h2xnWSgda8x51WbX3vrjN1JFPXIPtsO19dsQ0T4gbUAPWjKsBsr puxMFSOCXz1M5/B7spwdmnDNgsq40Dt6YnI2Pf+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+fabca5cbf5e54f3fe2de@syzkaller.appspotmail.com, syzbot+827ced406c9a1d9570ed@syzkaller.appspotmail.com, syzbot+190d63957b22ef673ea5@syzkaller.appspotmail.com, syzbot+dfccdb2bdb4a12ad425e@syzkaller.appspotmail.com, syzbot+df0d0f5895ef1f41a65b@syzkaller.appspotmail.com, syzbot+b08bd19bb37513357fd4@syzkaller.appspotmail.com, syzbot+53cdd0ec0bbabd53370a@syzkaller.appspotmail.com, Jozsef Kadlecsik , Pablo Neira Ayuso Subject: [PATCH 4.9 270/271] netfilter: ipset: use bitmap infrastructure completely Date: Tue, 28 Jan 2020 15:06:59 +0100 Message-Id: <20200128135912.692398476@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@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: Kadlecsik József commit 32c72165dbd0e246e69d16a3ad348a4851afd415 upstream. The bitmap allocation did not use full unsigned long sizes when calculating the required size and that was triggered by KASAN as slab-out-of-bounds read in several places. The patch fixes all of them. Reported-by: syzbot+fabca5cbf5e54f3fe2de@syzkaller.appspotmail.com Reported-by: syzbot+827ced406c9a1d9570ed@syzkaller.appspotmail.com Reported-by: syzbot+190d63957b22ef673ea5@syzkaller.appspotmail.com Reported-by: syzbot+dfccdb2bdb4a12ad425e@syzkaller.appspotmail.com Reported-by: syzbot+df0d0f5895ef1f41a65b@syzkaller.appspotmail.com Reported-by: syzbot+b08bd19bb37513357fd4@syzkaller.appspotmail.com Reported-by: syzbot+53cdd0ec0bbabd53370a@syzkaller.appspotmail.com Signed-off-by: Jozsef Kadlecsik Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- include/linux/netfilter/ipset/ip_set.h | 7 ------- net/netfilter/ipset/ip_set_bitmap_gen.h | 2 +- net/netfilter/ipset/ip_set_bitmap_ip.c | 6 +++--- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 6 +++--- net/netfilter/ipset/ip_set_bitmap_port.c | 6 +++--- 5 files changed, 10 insertions(+), 17 deletions(-) --- a/include/linux/netfilter/ipset/ip_set.h +++ b/include/linux/netfilter/ipset/ip_set.h @@ -537,13 +537,6 @@ ip6addrptr(const struct sk_buff *skb, bo sizeof(*addr)); } -/* Calculate the bytes required to store the inclusive range of a-b */ -static inline int -bitmap_bytes(u32 a, u32 b) -{ - return 4 * ((((b - a + 8) / 8) + 3) / 4); -} - #include #include --- a/net/netfilter/ipset/ip_set_bitmap_gen.h +++ b/net/netfilter/ipset/ip_set_bitmap_gen.h @@ -81,7 +81,7 @@ mtype_flush(struct ip_set *set) if (set->extensions & IPSET_EXT_DESTROY) mtype_ext_cleanup(set); - memset(map->members, 0, map->memsize); + bitmap_zero(map->members, map->elements); } static int --- a/net/netfilter/ipset/ip_set_bitmap_ip.c +++ b/net/netfilter/ipset/ip_set_bitmap_ip.c @@ -40,7 +40,7 @@ MODULE_ALIAS("ip_set_bitmap:ip"); /* Type structure */ struct bitmap_ip { - void *members; /* the set members */ + unsigned long *members; /* the set members */ u32 first_ip; /* host byte order, included in range */ u32 last_ip; /* host byte order, included in range */ u32 elements; /* number of max elements in the set */ @@ -222,7 +222,7 @@ init_map_ip(struct ip_set *set, struct b u32 first_ip, u32 last_ip, u32 elements, u32 hosts, u8 netmask) { - map->members = ip_set_alloc(map->memsize); + map->members = bitmap_zalloc(elements, GFP_KERNEL | __GFP_NOWARN); if (!map->members) return false; map->first_ip = first_ip; @@ -315,7 +315,7 @@ bitmap_ip_create(struct net *net, struct if (!map) return -ENOMEM; - map->memsize = bitmap_bytes(0, elements - 1); + map->memsize = BITS_TO_LONGS(elements) * sizeof(unsigned long); set->variant = &bitmap_ip; if (!init_map_ip(set, map, first_ip, last_ip, elements, hosts, netmask)) { --- a/net/netfilter/ipset/ip_set_bitmap_ipmac.c +++ b/net/netfilter/ipset/ip_set_bitmap_ipmac.c @@ -46,7 +46,7 @@ enum { /* Type structure */ struct bitmap_ipmac { - void *members; /* the set members */ + unsigned long *members; /* the set members */ u32 first_ip; /* host byte order, included in range */ u32 last_ip; /* host byte order, included in range */ u32 elements; /* number of max elements in the set */ @@ -299,7 +299,7 @@ static bool init_map_ipmac(struct ip_set *set, struct bitmap_ipmac *map, u32 first_ip, u32 last_ip, u32 elements) { - map->members = ip_set_alloc(map->memsize); + map->members = bitmap_zalloc(elements, GFP_KERNEL | __GFP_NOWARN); if (!map->members) return false; map->first_ip = first_ip; @@ -363,7 +363,7 @@ bitmap_ipmac_create(struct net *net, str if (!map) return -ENOMEM; - map->memsize = bitmap_bytes(0, elements - 1); + map->memsize = BITS_TO_LONGS(elements) * sizeof(unsigned long); set->variant = &bitmap_ipmac; if (!init_map_ipmac(set, map, first_ip, last_ip, elements)) { kfree(map); --- a/net/netfilter/ipset/ip_set_bitmap_port.c +++ b/net/netfilter/ipset/ip_set_bitmap_port.c @@ -34,7 +34,7 @@ MODULE_ALIAS("ip_set_bitmap:port"); /* Type structure */ struct bitmap_port { - void *members; /* the set members */ + unsigned long *members; /* the set members */ u16 first_port; /* host byte order, included in range */ u16 last_port; /* host byte order, included in range */ u32 elements; /* number of max elements in the set */ @@ -207,7 +207,7 @@ static bool init_map_port(struct ip_set *set, struct bitmap_port *map, u16 first_port, u16 last_port) { - map->members = ip_set_alloc(map->memsize); + map->members = bitmap_zalloc(map->elements, GFP_KERNEL | __GFP_NOWARN); if (!map->members) return false; map->first_port = first_port; @@ -250,7 +250,7 @@ bitmap_port_create(struct net *net, stru return -ENOMEM; map->elements = elements; - map->memsize = bitmap_bytes(0, map->elements); + map->memsize = BITS_TO_LONGS(elements) * sizeof(unsigned long); set->variant = &bitmap_port; if (!init_map_port(set, map, first_port, last_port)) { kfree(map);