From patchwork Fri May 8 12:33:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 226121 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 48D30C38A2A for ; Fri, 8 May 2020 13:16:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09CEC20870 for ; Fri, 8 May 2020 13:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588943806; bh=x/gFrVpT3Ffj+PZBClFJzWrlSI7AG0PbmewHrFiUroo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oLj+CXNjLnNnD5FoouoR6P4aRbs7aDXhuIULe5ndu380gem+EFN5gf2HJv4MwYNrS lGXKM5ROxavnVaJjps3jhKpZK0FMsKvMUqZ5HffpU6/4rfb0rpaMBpN5iTuQQTki1O FVG89sYx2uc//CSsufBjfsR/8PkwGTBnixxidh2I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729225AbgEHMor (ORCPT ); Fri, 8 May 2020 08:44:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:43438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbgEHMoq (ORCPT ); Fri, 8 May 2020 08:44:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 89E4821974; Fri, 8 May 2020 12:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941885; bh=x/gFrVpT3Ffj+PZBClFJzWrlSI7AG0PbmewHrFiUroo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aNADdHmCWjEKw+kMkX0PX/i9uS1LfaVBck/Rd4Pk6rIGIifjd20CCHlusJP7RTtHi WjerH2C0BPeIEj893Bg9kZB/xVKCoSRWSo+GC8sePswaA066dQZAbPQVArQIrcBZ9T jPk6KGV/SH9CHU9STYCIdaXSQAW0R1/6ev5X2o/g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Alexei Starovoitov , "David S. Miller" Subject: [PATCH 4.4 211/312] bpf: fix map not being uncharged during map creation failure Date: Fri, 8 May 2020 14:33:22 +0200 Message-Id: <20200508123139.247890347@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123124.574959822@linuxfoundation.org> References: <20200508123124.574959822@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Borkmann commit 20b2b24f91f70e7d3f0918c077546cb21bd73a87 upstream. In map_create(), we first find and create the map, then once that suceeded, we charge it to the user's RLIMIT_MEMLOCK, and then fetch a new anon fd through anon_inode_getfd(). The problem is, once the latter fails f.e. due to RLIMIT_NOFILE limit, then we only destruct the map via map->ops->map_free(), but without uncharging the previously locked memory first. That means that the user_struct allocation is leaked as well as the accounted RLIMIT_MEMLOCK memory not released. Make the label names in the fix consistent with bpf_prog_load(). Fixes: aaac3ba95e4c ("bpf: charge user for creation of BPF maps and programs") Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/syscall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -152,7 +152,7 @@ static int map_create(union bpf_attr *at err = bpf_map_charge_memlock(map); if (err) - goto free_map; + goto free_map_nouncharge; err = bpf_map_new_fd(map); if (err < 0) @@ -162,6 +162,8 @@ static int map_create(union bpf_attr *at return err; free_map: + bpf_map_uncharge_memlock(map); +free_map_nouncharge: map->ops->map_free(map); return err; }