From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DFEFC2BC73 for ; Wed, 4 Dec 2019 18:07:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EBFF0206DF for ; Wed, 4 Dec 2019 18:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482878; bh=QApcd85KJGu+VIAEdaq2EaYQKmtUl3gmpV+llI2BE+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uIwvKG43iCj8Gvr2owgM2gP+gXkBiMO5pOBBn3J1ILvHqTaaDOoj8gv70CKHCMJmX N5QobYj+O83I1yGKgz6B6/MGwRJ4qW7dVchWlDvEymsTLQhB8vPbHqglvwCQ6M1QCr TJ3NNULJ1NNRUZ7gy2C37I5pDBcRksSmHFJLKzDI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730836AbfLDSH5 (ORCPT ); Wed, 4 Dec 2019 13:07:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:58748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730825AbfLDSHy (ORCPT ); Wed, 4 Dec 2019 13:07:54 -0500 Received: from localhost (unknown [217.68.49.72]) (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 9952320675; Wed, 4 Dec 2019 18:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482874; bh=QApcd85KJGu+VIAEdaq2EaYQKmtUl3gmpV+llI2BE+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hg9rSd+endKIW5Y2rY3fLhDf9NecJi0XHKHgjNNuwKiNg4ezNiyq4zEzOjOuWLr5h +332D6DiY7MW0Eo+s5XhPv4DnnzTZYgsyQ3as4BAE1kdd2Lhidc2IN1aD4Tc3eGWmV RwcFfFC3+a/rWvM5i2GjmsSsGH3Bhkwx4t6cWfL8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peng Sun , Martin KaFai Lau , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.14 142/209] bpf: decrease usercnt if bpf_map_new_fd() fails in bpf_map_get_fd_by_id() Date: Wed, 4 Dec 2019 18:55:54 +0100 Message-Id: <20191204175333.088896488@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175321.609072813@linuxfoundation.org> References: <20191204175321.609072813@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: Peng Sun [ Upstream commit 781e62823cb81b972dc8652c1827205cda2ac9ac ] In bpf/syscall.c, bpf_map_get_fd_by_id() use bpf_map_inc_not_zero() to increase the refcount, both map->refcnt and map->usercnt. Then, if bpf_map_new_fd() fails, should handle map->usercnt too. Fixes: bd5f5f4ecb78 ("bpf: Add BPF_MAP_GET_FD_BY_ID") Signed-off-by: Peng Sun Acked-by: Martin KaFai Lau Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 59d2e94ecb798..34110450a78f2 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1354,7 +1354,7 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr) fd = bpf_map_new_fd(map); if (fd < 0) - bpf_map_put(map); + bpf_map_put_with_uref(map); return fd; } -- 2.20.1