Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4562635pja; Thu, 21 Nov 2019 21:55:42 -0800 (PST) X-Google-Smtp-Source: APXvYqx1Jqa1f/EqeBZWoZwrRjCv1bKiS+OdI5WLJ91CUGE2jBWJJ4kwBXH5tdUGkt6gjbrEkpiU X-Received: by 2002:a17:906:bc9:: with SMTP id y9mr19663116ejg.64.1574402142518; Thu, 21 Nov 2019 21:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574402142; cv=none; d=google.com; s=arc-20160816; b=AUxPNac6BmTZJSxw8dTHeybEzusvU18YXdgyY1SZF6zwkZgEw+Us4n4uZD4MsU+4lX UjchtdTa/zjFwMAyJ6RqD84g/LO4i+WYfxOrOLaUxA7FV42spde4t3wrGmQUJoatQXh9 NSatJxfgwFl0dvzBgXKxKs+peBApTvXTAFFsKVcKuNMtyssICvd02MysgfQfrtAmtmif LlRN1L90qW+1pLbyki79x4oYOWrICWFd6wi/rwP1MMAccpyxNdyh91kECB5vXmFgdpuS Ooi0bPU+DSwaSfAsmWqyqva5pBpXhtVR5NHb9K5zHDD8OsmWy3GVTKi8la1wMeV47NXA 7FmA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wiKEEfiWy1rDSWc28eVIWBYUlr6vhqxAu+s3vnwBnYQ=; b=L/NgPblArfQTxVIFAwfeS7+yeEiAKlACEnNESC4AnUT9wT2rRLbGUx45NlDeDIOubp x6W99GOlGIh35ksEX35fzho6GAH+PM3mv5ed+jJ26i/QmlND6yPxwUI1qXC7hK0aecGf bFqitabwYqlnfnkYqjsIZc3ipFGV1W5q0Vm+hz01cpuPJEbeu1eoQjRU1XoiLIxMsRmH nwpOS5yyrdAdqhaB/dyrmOl1KVsmvCJC4zkHc8tb+YZFdRC+8S1mmb+9Or7dVKLchvA/ PSmSxGtEq2aJqTW36Vw5UPXgcEJz9h1qUeo3rSRxs3imc262T85i/uBsaz7ryGca03Wc ooGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vmsAQMm2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l20si3637112edv.282.2019.11.21.21.55.13; Thu, 21 Nov 2019 21:55:42 -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=vmsAQMm2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728746AbfKVFw7 (ORCPT + 99 others); Fri, 22 Nov 2019 00:52:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:58868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727521AbfKVFw4 (ORCPT ); Fri, 22 Nov 2019 00:52:56 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D42A2071B; Fri, 22 Nov 2019 05:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401975; bh=aEig3xLJ0ayeEDQUT+Zv0DbOuIHBjOVxj1yI+WpZ7DI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vmsAQMm2y+oZPVsr+Yy5XevbpNZaK7/X7VWtBPD0gb7KzeiU7m3dbAnSvsntG4Trn LdTlyIEjMI31FhrD7hq1ti6O5OUFN4JuHACFXlUirFlz80Lmo6vlHIZGfn0joI8mFD 5YSLwM4VngliGfiH4zerBqhQmhDoAwuR1lZw3oEM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peng Sun , Martin KaFai Lau , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 195/219] bpf: decrease usercnt if bpf_map_new_fd() fails in bpf_map_get_fd_by_id() Date: Fri, 22 Nov 2019 00:48:47 -0500 Message-Id: <20191122054911.1750-188-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 6e544e364821e..90bb0c05c10e9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1887,7 +1887,7 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr) fd = bpf_map_new_fd(map, f_flags); if (fd < 0) - bpf_map_put(map); + bpf_map_put_with_uref(map); return fd; } -- 2.20.1