Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp819617ybl; Wed, 4 Dec 2019 11:24:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzTZqHioFPxtAV7fb7g8Cwwe02+lFbmWt0D6++aXcBTJgkZcZL5paR5Wbr/zqvu6JF9wH+C X-Received: by 2002:aca:ef44:: with SMTP id n65mr1881527oih.175.1575487451188; Wed, 04 Dec 2019 11:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575487451; cv=none; d=google.com; s=arc-20160816; b=Hzep9x1sZT0nBsz3XOxUvT4Y6tufh/mX3gFUDPmbur8DY0Ij5mV/TAYfMbfmjR2G7k LVPxv69XkcHvyvfSdkfbjj1GD0RwzWNKpOubK3sJUIKnH09BwW+XBMO7LjMD6Xd1hNlq UVUKkuMb6ORi/dl6TB3cnko8B5885q0r9+x8BhoMpPQrXEaoZL/XxFWSlUm+a2faS6wJ EWaJZrFn6YVFXKZK6fw8ho+i1mM161uus3C76js2X+IG75xBOH/Hdvxjy4Brr56is+S7 0NDo6AXYNgO2U/kA8d9z3x9mGBkKYL+63egJZSchvn+1pVGMSWfjvHo08TKZMxiWspwE I69Q== 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=eiekCJqMqPT+NNYJYqnmRnMXQXq60tsip4jKYB7ULJo=; b=dgdINGuzy8reN7dH3v08enQa4RCoe7hmNDKJdTfa0o87wBb1vR3MhjjUanGLpzZPHn U+qYzyEyYomHtM1xH2Qag5w1Kz5+cKJFCGyztanD7wQ94cKljk8v45AgDGgOdtmFmV+d 0Qk7cD6AsaXOPiCMhDKmQgmAYX5JUPzVChKuv6j95BORzURu28p4SpLNA+/u8xm4Btf0 6JbOK7DnBY3YZNH9Y9jvtqBeWkqH8qMrDrl1ve/ptwnzvlDZt5mzM0OgO10HfP7SSpd0 6CXjF/epJx4Y6vf6xyl7E3u9h/dmGIVBQ/q7m2Om5vBxI1Sfgv/Bz0i1/V3u/10xJ7MQ reLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="oP4Q/Vu6"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90si3815622otv.13.2019.12.04.11.23.57; Wed, 04 Dec 2019 11:24:11 -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="oP4Q/Vu6"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730978AbfLDSIz (ORCPT + 99 others); Wed, 4 Dec 2019 13:08:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:33042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730950AbfLDSIn (ORCPT ); Wed, 4 Dec 2019 13:08:43 -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 2C94B206DF; Wed, 4 Dec 2019 18:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482922; bh=Nh+HcfVHCez8hEtRqsXlfDz3c1EZS0DjrPKmFW0Nb7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oP4Q/Vu6XSYETN2ILr2I8vVLmooWuZl5JlpAoGpeHfjqBRmOh/8xBHa1o/AEZZCPY tYLnvoYBpawqM+iKOvJLFtuDTjTG2TpsLE1sCdsV8mzwrkPfFx74pA+64TCYoXHszT sZDN6s+5Y3P68oCp1quh78e49xCn8r1bxn3fz7/Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peng Sun , Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.14 145/209] bpf: drop refcount if bpf_map_new_fd() fails in map_create() Date: Wed, 4 Dec 2019 18:55:57 +0100 Message-Id: <20191204175333.517622722@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 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 34110450a78f2..f5c1d5479ba3d 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -348,12 +348,12 @@ static int map_create(union bpf_attr *attr) err = bpf_map_new_fd(map); 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