From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexei Starovoitov Subject: Re: [PATCH RFC v2 net-next 08/16] bpf: add hashtable type of BPF maps Date: Wed, 23 Jul 2014 12:57:23 -0700 Message-ID: References: <1405657206-12060-1-git-send-email-ast@plumgrid.com> <1405657206-12060-9-git-send-email-ast@plumgrid.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: In-Reply-To: Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Kees Cook Cc: "David S. Miller" , Ingo Molnar , Linus Torvalds , Andy Lutomirski , Steven Rostedt , Daniel Borkmann , Chema Gonzalez , Eric Dumazet , Peter Zijlstra , Arnaldo Carvalho de Melo , Jiri Olsa , Thomas Gleixner , "H. Peter Anvin" , Andrew Morton , Linux API , Network Development , LKML List-Id: linux-api@vger.kernel.org On Wed, Jul 23, 2014 at 11:36 AM, Kees Cook wrote: >> +static struct bpf_map *htab_map_alloc(struct nlattr *attr[BPF_MAP_ATTR_MAX + 1]) >> +{ >> + struct bpf_htab *htab; >> + int err, i; >> + >> + htab = kmalloc(sizeof(*htab), GFP_USER); > > I'd prefer kzalloc here. in this case I agree. will change, since it's not in critical path and we can waste few cycles zeroing memory. >> + err = -ENOMEM; >> + htab->buckets = kmalloc(htab->n_buckets * sizeof(struct hlist_head), >> + GFP_USER); > > I'd prefer kcalloc here, even though n_buckets can't currently trigger > an integer overflow. hmm, I would argue that kmalloc_array is a preferred way, but kcalloc ? Few lines below the whole array is inited with INIT_HLIST_HEAD... >> + for (i = 0; i < htab->n_buckets; i++) >> + INIT_HLIST_HEAD(&htab->buckets[i]); >> + htab->slab_name = kasprintf(GFP_USER, "bpf_htab_%p", htab); > > This leaks a kernel heap memory pointer to userspace. If a unique name > needed, I think map_id should be used instead. it leaks, how? slabinfo is only available to root. The same code exists in conntrack: net/netfilter/nf_conntrack_core.c:1767