From patchwork Wed May 27 18:56:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Protopopov X-Patchwork-Id: 208462 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=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, 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 50BD4C433E0 for ; Wed, 27 May 2020 18:59:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 369682073B for ; Wed, 27 May 2020 18:59:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IcCGEHwh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728561AbgE0S5h (ORCPT ); Wed, 27 May 2020 14:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbgE0S5g (ORCPT ); Wed, 27 May 2020 14:57:36 -0400 Received: from mail-oo1-xc44.google.com (mail-oo1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9F65C08C5C1; Wed, 27 May 2020 11:57:35 -0700 (PDT) Received: by mail-oo1-xc44.google.com with SMTP id v3so575236oot.1; Wed, 27 May 2020 11:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r46D0cfhvOhWWQ3wuo1JGTI5mTXEa2xSDV25qx6cAKk=; b=IcCGEHwh6VfbORhnPgDkpXIEqASSNM6+Dy5fNAYhoMaqUwYzRyY2PLTJbYrUDfoyAO reP2FE0YljDiGL3KMwEUMilq3ThaHIkNeOTdv2cCnM7zjE4NNXddO4UQnbwni8qb2fUX 6lZX8tVc43EGjFxWqEeCLEsX6ZO/lWbBXAPVzNMQJ6LZTIjmqKh8raLLYG06iutyoWbR xRT/XINpNtPB4gySXxiPq339x9iO/FtFJ+YL9Gk6VbwD6+a1YJKtzEjg0jiHmJgES6sW SPkb/ZxUeEgp1uMHuhlR+25VB2++Byfdnu5oFbEfQYfkQ6qnDYAmFvkXnbJsMUfwxnIx ayPg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=r46D0cfhvOhWWQ3wuo1JGTI5mTXEa2xSDV25qx6cAKk=; b=cde1GrR6zFyUnFdLP9tId+y66zcOBhv1MB3vGmboIy81LlF+w5GH2h7xDClnq/Klw2 nwgZRBUPTpId6gNMUVaiVxx0VbtM5A52mT2Kj4QeA+M5yTk8FkpRf0dvcDxeP2LQUUE3 YSPIqs9PePwhmtjKtR7+nNTnD8eApp5M7FwlBxw+IWRujTUztPkwLCwgLvAgcW0VX6F3 M+0SFui6+09+plBvG6uSt9YVa7gFGNnsiVyG6U510BzpPns/fnXYVP7Of4MIDh9Ie8bK G4V/KG78BI7oxpxb0HW+oy5KuAYvj7whC1qj+9cHBuBf+Jn6kh7ujIwgAS6njnyqXtB5 Iv8g== X-Gm-Message-State: AOAM532HKiejRtn2IuiV6Vp49I5p3nxN2nnRvOU64fndEWfTu1Va1b1t t6novdpXroMcxda739AQ7Uo= X-Google-Smtp-Source: ABdhPJwY0kLd6Qt/cOzyeaTF+lRjh66ysW6Shhec+3r7seZ08dLvdYfT34asas6wWsct9uKRnljAMw== X-Received: by 2002:a4a:244e:: with SMTP id v14mr4182967oov.57.1590605855296; Wed, 27 May 2020 11:57:35 -0700 (PDT) Received: from localhost.members.linode.com ([2600:3c00::f03c:92ff:fe3e:1759]) by smtp.gmail.com with ESMTPSA id i127sm1074596oih.38.2020.05.27.11.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 11:57:34 -0700 (PDT) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Shuah Khan Cc: Anton Protopopov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf 1/5] selftests/bpf: fix a typo in test_maps Date: Wed, 27 May 2020 18:56:56 +0000 Message-Id: <20200527185700.14658-2-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527185700.14658-1-a.s.protopopov@gmail.com> References: <20200527185700.14658-1-a.s.protopopov@gmail.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Trivial fix to a typo in the test_map_wronly test: "read" -> "write" Signed-off-by: Anton Protopopov --- tools/testing/selftests/bpf/test_maps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index c6766b2cff85..f717acc0c68d 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -1410,7 +1410,7 @@ static void test_map_wronly(void) fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), MAP_SIZE, map_flags | BPF_F_WRONLY); if (fd < 0) { - printf("Failed to create map for read only test '%s'!\n", + printf("Failed to create map for write only test '%s'!\n", strerror(errno)); exit(1); } From patchwork Wed May 27 18:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Protopopov X-Patchwork-Id: 208463 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=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham 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 BB959C433E1 for ; Wed, 27 May 2020 18:58:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A06AD2075A for ; Wed, 27 May 2020 18:58:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CQIL3L9Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729009AbgE0S6w (ORCPT ); Wed, 27 May 2020 14:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbgE0S5k (ORCPT ); Wed, 27 May 2020 14:57:40 -0400 Received: from mail-oo1-xc43.google.com (mail-oo1-xc43.google.com [IPv6:2607:f8b0:4864:20::c43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3815EC08C5C1; Wed, 27 May 2020 11:57:40 -0700 (PDT) Received: by mail-oo1-xc43.google.com with SMTP id x17so1243749oog.6; Wed, 27 May 2020 11:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/bi2v/w881kTu6aWVQghMQWdHo/A6/i+CwZouKlxmms=; b=CQIL3L9QuGAGDOch3ZMsrDWOowK34i8Dzmn0YPcOlbVnRAkpWIkm5klrZ7exR8KX2V yvoM1/mwIx6c32q4jY+hff50T+XO+4+RwrlJH5VzZ1+9hud0QAGUzzTtnb3Zpyr2n2tV tp1gO7TsKr3QnvY49tvhWCjqbHBmI4cchjZq/CNphEyjEv5bceDjxftzbADAsOUXbZ2u RN4T2b7SqMfyAnp4JyjgbAilvaycZNST78JZEBc4Y9S57yNkJcIaC7Gcs4ppj47iB/Ky qXwwXupF+FcBY/udgJBgefsgsVBNHDPDve4jiF9V9DcOQLcmKyQZzCaNpT5l6cCWS/xL 7D1g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=/bi2v/w881kTu6aWVQghMQWdHo/A6/i+CwZouKlxmms=; b=nWgasd1qg/E/bb6gkrjIy8qFYjpnzlb/Bke2TQcaWooxHtqdY2ddNNH9/mj6an0Hzu YcpCDfD1PGqgEeW31hYrRqSsH+Rza+z1M2bpJuMtbWxEU5e0pRRiUF4+N88qhwXMzgTa s4m6SSJPtEFrybnK/tD9JoqzR08BS6F4lJsoO+CcmI88/Ej1ho5BMKz5eoTh8OBuSKPP 9tXcvP5RpCem4cVqtKE+N8AeA8mouOgwy3wvwtholqs1UpXm9N2YMpwt2GNK0rLDyJIX Xy6+34HpDggVLdA4+4xsTBUiOAkRI3u9gS1bFRu+BRyx0f1gc0tbkvXu0FcJYHLhc6Gu /1Kw== X-Gm-Message-State: AOAM533DRdpP+leTPuXHwR+NrjcOGFz+obovEl0lUB9kwaGXxMTMW3WE vZG288V/50k5V8xoghoFjO8= X-Google-Smtp-Source: ABdhPJyzzRIMTL2FQqJKEg9svGszotkEOxIapfGj9shfnfRkXZ8OYl6TxV8aHgl0uRVzP+PIFoUAhQ== X-Received: by 2002:a4a:5548:: with SMTP id e69mr4198269oob.23.1590605859440; Wed, 27 May 2020 11:57:39 -0700 (PDT) Received: from localhost.members.linode.com ([2600:3c00::f03c:92ff:fe3e:1759]) by smtp.gmail.com with ESMTPSA id i127sm1074596oih.38.2020.05.27.11.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 11:57:38 -0700 (PDT) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Shuah Khan Cc: Anton Protopopov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf 4/5] bpf: fix map permissions check Date: Wed, 27 May 2020 18:56:59 +0000 Message-Id: <20200527185700.14658-5-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200527185700.14658-4-a.s.protopopov@gmail.com> References: <20200527185700.14658-1-a.s.protopopov@gmail.com> <20200527185700.14658-2-a.s.protopopov@gmail.com> <20200527185700.14658-3-a.s.protopopov@gmail.com> <20200527185700.14658-4-a.s.protopopov@gmail.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 --- 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; }