Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp101669ybg; Mon, 8 Jun 2020 17:37:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLtYT+skoORpdwfTWRa29mHrDYDWJWsyaIX/3lNUPUGL3qYEd7wYblTKCD2JQ6fsrhrImZ X-Received: by 2002:a17:906:f0c6:: with SMTP id dk6mr23801669ejb.157.1591663028073; Mon, 08 Jun 2020 17:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663028; cv=none; d=google.com; s=arc-20160816; b=XMYqoyrzkwJ91dtgeBuC1WzrNcEEKFSbxPh+7cc+t8gvcsG3z/VvFJO+vLi7S/rqM6 2CEO1qPFbdNlO3Fus8MKdW8OYI53ym0DMB3vm3aN0Ov85alNtSdCpZB/NbEIzwMALRJI e63OPidPNqI5aULUlIzI46MIGtcyf3sOAcY6IEHnJfbQR0eWIxUZEO7HlAAFRoc8sQ88 pygdH9xbcqMQyTMZUr2xKOmyHtwfOb1D9JeSkgtBPyC/q1tIns5d67AZU2VgPL9XtyOp L7r0uygJ/nkLV+1xEZmL9959qICclAliH1Bk2JeRcNg5/QPc+6nX4FjajxZAVWrozKzB dJEA== 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=bfhWn3DXOnre55gPXpQ+jf84o8uXfGIJEMFMtNW6/ug=; b=gIM/uPvrWTKpixTn+nxx7mAjfh5aSDOdGC1YJimiJHebw+/jygY537jxrXKw1HyyHP xHeN7bTR2Dpmq4xCJdDbk4PkFSYuLMF8TppF5+yAvE75Neg84iuURsBb2ICXM/5w54GP kKqiY59n5WcHMQpCxPrjfUZ3/oDcKx+Z4TmeQA6FmAUuZTr98GQQ/BjDYAtRFKWLe9ZL iC+46ldyw9jpmf/D1OZxzvwPlD1WutsgHweaR4y0Inqp0dBAxkrH17y4Y0cf3eK10TZV mF97/qx+1ZMCyLpDFnV7lFwGZTEodASKV4pYo99DfRO1v6IXocjP1BcUzl6PEEIGK09o dikA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X0ltNQV0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id u14si9296536ejf.226.2020.06.08.17.36.45; Mon, 08 Jun 2020 17:37:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X0ltNQV0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729825AbgFHXOa (ORCPT + 99 others); Mon, 8 Jun 2020 19:14:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:59044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729013AbgFHXL4 (ORCPT ); Mon, 8 Jun 2020 19:11:56 -0400 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 CF45A2145D; Mon, 8 Jun 2020 23:11:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657915; bh=U+JU3pulcrPnDSUFMUHuppeZgdml6VTYsuEf4BfNm28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X0ltNQV0ghGRev4g5tC1lTwAVT+9MUdObSE7WIZnMHBqM4s+P6iOnezrhsGHM6MMX 2LIzPLXswrryB6FL3U2cRhf8l4W3eviauEXh+dtxsxNwSu06oi122K/aigQoG7unlq JZCUG7XR4gFBpuIC8qZuOIBaakQ3nZLtXEtQdH1U= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anton Protopopov , Daniel Borkmann , Alexei Starovoitov , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 266/274] bpf: Fix map permissions check Date: Mon, 8 Jun 2020 19:05:59 -0400 Message-Id: <20200608230607.3361041-266-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-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: Anton Protopopov [ Upstream commit 1ea0f9120c8ce105ca181b070561df5cbd6bc049 ] The map_lookup_and_delete_elem() function should check for both FMODE_CAN_WRITE and FMODE_CAN_READ permissions because it returns a map element to user space. Fixes: bd513cd08f10 ("bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall") Signed-off-by: Anton Protopopov Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20200527185700.14658-5-a.s.protopopov@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4e6dee19a668..5e52765161f9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1468,7 +1468,8 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr) map = __bpf_map_get(f); if (IS_ERR(map)) return PTR_ERR(map); - if (!(map_get_sys_perms(map, f) & FMODE_CAN_WRITE)) { + if (!(map_get_sys_perms(map, f) & FMODE_CAN_READ) || + !(map_get_sys_perms(map, f) & FMODE_CAN_WRITE)) { err = -EPERM; goto err_put; } -- 2.25.1