Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4563938pja; Thu, 21 Nov 2019 21:57:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzoLt30oy3pvWjmoa8hm/3C3Sw+QJ3vh25QiGYy8G9V8BSeK92hBz1slcbCPsqjWv7TMrrJ X-Received: by 2002:a17:906:2552:: with SMTP id j18mr20150433ejb.244.1574402245746; Thu, 21 Nov 2019 21:57:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574402245; cv=none; d=google.com; s=arc-20160816; b=KtiibQSc0qcEoBRzM71N2b0EnjxNU0IFDoxlU4URM7SHLOOVQO6Etf8Qzw8VGi2Bc6 bLtgYKu42JVtbqEJF+vRmRYUiRkxFWyvBi7bjVPweCn9L0fKrU619tNbjr24GgeCBuS5 fcSBjcBBy2sIUcmEehYxv8sAT2vf3q/uzypxhmePSt3SXWUFbSSRfIooY5KaSk/8R9Xl KiO8x5C6T4StRIYQLCmddFuBKAYOz7n9CoBI7MTIFBT05PnZyqOsL12BLza+6taRS/E1 SrVwpHsfPnJnEq0XvZ5z9QWhV6SduxNcgD6DLhf9CNFK83+X1f5+NdFep4Dxl95AIFZz OEuw== 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=t5HW/n5dPyd3v9Qy2PPEd16pjMM7JB3nBfqqz8AiknY=; b=eXtky8iLjv1KEVwIVyy1zp3ONrgkpQJb9jNDjEmr1llqXdMYV+mZk1izdUZpfFo4DF WVoeEngLgV36PsQusn0i+sTXX6s9aRynXkH98z7D6snRNm4g6tiU2/8vQbffrq4Tw1Sg pOPuD+sY2CUXX2StkhpbZZQwx+Bz6JD7V9EY4jpGj6DlHqnR6JSKcylZzocIbQDUOBJv Plf+CIef5c43AtU3BrWh9tmJDLu2smvmqbvFIvCzpdHqSOMTZXGLI60DZlm1AhlqGjXr v+PA1EYme9mHn4rQxJjCbzzWSfWwbYCKX+NCSgq0cDC8YC+1SrQacL/xxKyAnfYKIJ50 FG3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ElxX2+VT; 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 t22si3688788edy.116.2019.11.21.21.57.01; Thu, 21 Nov 2019 21:57:25 -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=ElxX2+VT; 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 S1728216AbfKVFy7 (ORCPT + 99 others); Fri, 22 Nov 2019 00:54:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:58976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728736AbfKVFxA (ORCPT ); Fri, 22 Nov 2019 00:53:00 -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 CE6E7207FA; Fri, 22 Nov 2019 05:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401979; bh=5SJfNXeOwIOAk15jkQn2Gv0V++ANh4fNNJIoak3Vnec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ElxX2+VT3BPOopzIDaLl4hUIHaE6XMPqsOFZ1owcCSz3TTMKMhL2cCzAvIPXq1PNu ZB04tKEAZUdzyrU4TfIiW3GxAclWzFyVFOEOEfTcvYkaTvkgn9XJHXXXK0CYXAIyCX +MApf16jET9R16kfvJZwiQRUaOtHrPh0tQplTJBA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peng Sun , Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 199/219] bpf: drop refcount if bpf_map_new_fd() fails in map_create() Date: Fri, 22 Nov 2019 00:48:50 -0500 Message-Id: <20191122054911.1750-191-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 352d20d611414715353ee65fc206ee57ab1a6984 ] In bpf/syscall.c, map_create() first set map->usercnt to 1, a file descriptor is supposed to return to userspace. When bpf_map_new_fd() fails, drop the refcount. Fixes: bd5f5f4ecb78 ("bpf: Add BPF_MAP_GET_FD_BY_ID") Signed-off-by: Peng Sun Acked-by: Martin KaFai Lau Signed-off-by: Alexei Starovoitov Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 90bb0c05c10e9..596959288eb9e 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -559,12 +559,12 @@ static int map_create(union bpf_attr *attr) err = bpf_map_new_fd(map, f_flags); if (err < 0) { /* failed to allocate fd. - * bpf_map_put() is needed because the above + * bpf_map_put_with_uref() is needed because the above * bpf_map_alloc_id() has published the map * to the userspace and the userspace may * have refcnt-ed it through BPF_MAP_GET_FD_BY_ID. */ - bpf_map_put(map); + bpf_map_put_with_uref(map); return err; } -- 2.20.1