Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp1902827img; Wed, 27 Feb 2019 07:21:59 -0800 (PST) X-Google-Smtp-Source: AHgI3Ial04DbE7IiTwRO/bTv+3dH8o6fKNozy5WaCcMfDR1lNMWKNBgfdhfEYHbOl3KR8ptRY2Eq X-Received: by 2002:a63:8b42:: with SMTP id j63mr3383641pge.79.1551280919442; Wed, 27 Feb 2019 07:21:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551280919; cv=none; d=google.com; s=arc-20160816; b=OIwCdd0or0l8Aa44aD74htH3tvqvkvd/0l4iPnJk1pPpFRqWCNrozQ+PbnOM7SjZWk 7bP5Szzsp6q+rtQabmKjtq4Bqxhtk/74+CypdJFQEjHQOQ2hvuBUoJEknBTL1drQ0aNW D76jO5vbU6jRhxFGuVGWBF6qhJV/+wLmqKiO3Tpm132ApFv7fH+ZsQwGWoUJEI8ZRiKu L3k9zeB9ZiBBfvIOKUSiIZX5qHRwhf7gVIqmmCdjO3q0T0Ngo8e5xeL66tGsdtsZFRCj vw/zDbMAVWhLvwa4tKnCPdPBc3habz+n399oGP+C3NlBa2xFu4Aa4AWyoIM8TDh8CKc1 z2Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=hMM+U5uQzrfAfl+apatZhOIfSoVUQBO+zTVJBKz6bjU=; b=J/tnYGuag6gpr/NPA/nlaZPzrupe2mlSoTtTR5RPMefXgezF0sFhF2PqM/bODXkGJO pBusGYGmwxtwGn4YjzkzGhZUQOmWebhNh7P52Miv1AM4dl4IDKZGTHi3yvVsAMdAaC/X QJHuc6ZpxBVkgW+RkySlhnS0UqcpUA6qC65sDHo/NXjnZG6K9IyVEdhSLtyvciE1WvAd ZEoO4yYaN3H0e32HUpezb0bD5taEhNrDoI130cjqW9yrOEPAF3bN6ShP5162mh47fd2I oSd69/gFX+Ew7yCPMxrEDCvmOVIK+5AIzPZYzrw3eaIh4wiPlvnbf1Qggk5QWnqtEsdz KdZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KESMNHVW; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si14842465pgm.311.2019.02.27.07.21.43; Wed, 27 Feb 2019 07:21:59 -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=@gmail.com header.s=20161025 header.b=KESMNHVW; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729929AbfB0Ogz (ORCPT + 99 others); Wed, 27 Feb 2019 09:36:55 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42730 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726063AbfB0Ogz (ORCPT ); Wed, 27 Feb 2019 09:36:55 -0500 Received: by mail-pl1-f195.google.com with SMTP id v11so2691815plg.9; Wed, 27 Feb 2019 06:36:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=hMM+U5uQzrfAfl+apatZhOIfSoVUQBO+zTVJBKz6bjU=; b=KESMNHVWlT0P2OSrupXu0sOBSnEmX/Qpb3NTYI7yol1pVUVy24XJXeuswmxdrqHnvj 7P2TmGnAMEjLErkNyD+faGRw8rkg6d62NKDeR3cEpr9TnSCh+AM4Bd5TnNZkuLYERYBV JLDwbliBffcW2J1v1eE0ix9OTNWlo961cMJknTKft43TWG1mWe2wlbmtO3fZ0WLXkvTn xoBHSb0zFk0QnJZZ+OT/QqLYshrmi2iCuZFIttnNaUzJX5ILvimT6HxEFsVMGDBUzAdC MNUOUBnh1IMdKJa31DfbV4bvj31eae9wxr+k4RB9k2CBEB5o32bX8TrP6itsrsfqz4ID IYlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hMM+U5uQzrfAfl+apatZhOIfSoVUQBO+zTVJBKz6bjU=; b=cJJJNgJXHDEdfm0cTD72yBCn5M8nh7yrQ6AXLr7OSb/zT5ORyRirrWEmo/rzKdp4/K O4UZTpTwuiKNel7k3MpT2baI9XhNxeK7rGdF53xan08hsm2celnOkvGbbvRVLAxwHqQI R7eI6HbZkqO4Vs5YBr0wyJj/ikmXKuashgEB/ttjY3WnrNnxIAYO4H7FgqpxIpxakAQZ WOyybYV77E58BSTyDJHuaiwokwvC2gsTU4DCKn//laSASMJpFCEwsop2pqVbxZPmMvkj 5e7rcPIW2qVJ5vihnnwMSO461IksTJQVEoYrRmseKX1+3TIfOgpXHsRi4Lq0o3qxp6Yk JVLg== X-Gm-Message-State: AHQUAuYPLZEfX+2rfxZTysuqbB6ND+ci4LcB/lilRotONIphYTLwu4Js 1p7ytrrn7H9cxa9nrQTZkDo= X-Received: by 2002:a17:902:14b:: with SMTP id 69mr2436336plb.120.1551278214963; Wed, 27 Feb 2019 06:36:54 -0800 (PST) Received: from localhost.localdomain ([171.221.1.102]) by smtp.googlemail.com with ESMTPSA id 33sm39097313pgs.81.2019.02.27.06.36.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Feb 2019 06:36:54 -0800 (PST) From: zerons To: ast@kernel.org, daniel@iogearbox.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Peng Sun Subject: [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create() Date: Wed, 27 Feb 2019 22:36:25 +0800 Message-Id: <1551278185-5219-1-git-send-email-sironhide0null@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Peng Sun --- 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 cf5040f..1c4f1c4 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -558,12 +558,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.7.4