Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2020203pxa; Mon, 3 Aug 2020 05:33:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5tXVPIZP+xGtvvHs5VgxFKzbAE91n3/sECXOrd3C93+tNKGE7uBQcj2qysyQyFjmT4XOk X-Received: by 2002:a17:906:386:: with SMTP id b6mr16255009eja.538.1596458036224; Mon, 03 Aug 2020 05:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596458036; cv=none; d=google.com; s=arc-20160816; b=eFSiP36V+N8LV00UfMAqVHnx21H/q1KWDJGIf784ZEU5GCI5EYwN1bfLXgZtbMD478 Ra+fO+MPybyIdud3ZC7BcO+gtO8gqFqZWMnhTwQkgZg+22hl/vefndRR9T0TSZ/1RF6H KzbwTIxMY3BXBKrm6yjNlJZ8RjclYwPbXqTY+oIpLrxEcg6SmZaqaxs1rIjyiqgJLVEK 72KxPjgYY7nzJ5iTUidUDlMs6034/hikeSiHTZR3agQ4z36C+dzg3BRfm34EFi5xB3gF KMSY4WLgwbYYdBYG17mGDKTz2DXQsR2NbKijwDX7RY1qOyPhsKQ3Ssr0fNX/7Wl6eWh2 UW2Q== 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=qNh1xH78c1dtNyKoMNJBIsJrmETHdBvGx2aq+Tf69/U=; b=P43TxQji9DwtGly33AgQXDTEW1BDBlNLQswU/QAUjS8yC0IG+ZhT3E6Nb0SUlKU4fR fxrU8gXK+UHjqIS4lx2Cn1NJMfJAa2QDUt5pQjRmgu+Dp0JVNRNXg88tmGfuQqd0A/Db NnaKp41XA0ToC2LERBmKAGkRrkUPcqWEtI9pNDuCWXoRk3tBn9MthgpjkS9L3XQXCxdn 64uXl5H45hyaXzylMt/mYcL7EPXNXkyRskd9ki0gdnY7TnGL4tmjMueOWQH5XCsYJ14j vMVC3e/jnKji5xAOKj8OHML5fBt2qXfjTPixHH1O+TEOVfubm5PlSNmes+lFcx8rImbN iNtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FqQNakEN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si3099567ejb.443.2020.08.03.05.33.34; Mon, 03 Aug 2020 05:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FqQNakEN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729310AbgHCMc1 (ORCPT + 99 others); Mon, 3 Aug 2020 08:32:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:60286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729301AbgHCMcX (ORCPT ); Mon, 3 Aug 2020 08:32:23 -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 31A78204EC; Mon, 3 Aug 2020 12:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457941; bh=Vs6BmE6cEpyxFsmxJNBFx3YtUtzpVXtY/843g7hCNOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqQNakENwnsmKexR7vje/BaBSgmILFCOmGj/e148rtZdeSNVSAqNTLKRIOsBJMol2 1XKJMdK8eLEBZYUmq3x9feWZW/WToLxu+j61r6ko+oNamzUDASYderp3KM+ZOpzKLU J05+V2odVfceJNn8N8Zw4rsTqciDCOxgspxNsRjs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Daniel Borkmann , Song Liu , Sasha Levin Subject: [PATCH 4.19 38/56] bpf: Fix map leak in HASH_OF_MAPS map Date: Mon, 3 Aug 2020 14:19:53 +0200 Message-Id: <20200803121852.186221082@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121850.306734207@linuxfoundation.org> References: <20200803121850.306734207@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: Andrii Nakryiko [ Upstream commit 1d4e1eab456e1ee92a94987499b211db05f900ea ] Fix HASH_OF_MAPS bug of not putting inner map pointer on bpf_map_elem_update() operation. This is due to per-cpu extra_elems optimization, which bypassed free_htab_elem() logic doing proper clean ups. Make sure that inner map is put properly in optimized case as well. Fixes: 8c290e60fa2a ("bpf: fix hashmap extra_elems logic") Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Acked-by: Song Liu Link: https://lore.kernel.org/bpf/20200729040913.2815687-1-andriin@fb.com Signed-off-by: Sasha Levin --- kernel/bpf/hashtab.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 6fe72792312d8..1b28fb006763a 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -678,15 +678,20 @@ static void htab_elem_free_rcu(struct rcu_head *head) preempt_enable(); } -static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l) +static void htab_put_fd_value(struct bpf_htab *htab, struct htab_elem *l) { struct bpf_map *map = &htab->map; + void *ptr; if (map->ops->map_fd_put_ptr) { - void *ptr = fd_htab_map_get_ptr(map, l); - + ptr = fd_htab_map_get_ptr(map, l); map->ops->map_fd_put_ptr(ptr); } +} + +static void free_htab_elem(struct bpf_htab *htab, struct htab_elem *l) +{ + htab_put_fd_value(htab, l); if (htab_is_prealloc(htab)) { __pcpu_freelist_push(&htab->freelist, &l->fnode); @@ -747,6 +752,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key, */ pl_new = this_cpu_ptr(htab->extra_elems); l_new = *pl_new; + htab_put_fd_value(htab, old_elem); *pl_new = old_elem; } else { struct pcpu_freelist_node *l; -- 2.25.1