From: Chenbo Feng <chenbofeng.kernel@gmail.com> To: linux-security-module@vger.kernel.org, netdev@vger.kernel.org, SELinux <Selinux@tycho.nsa.gov> Cc: Jeffrey Vander Stoep <jeffv@google.com>, Alexei Starovoitov <alexei.starovoitov@gmail.com>, lorenzo@google.com, Daniel Borkmann <daniel@iogearbox.net>, Stephen Smalley <sds@tycho.nsa.gov>, Chenbo Feng <fengc@google.com> Subject: [PATCH net-next v2 2/5] bpf: Add tests for eBPF file mode Date: Mon, 9 Oct 2017 15:20:25 -0700 [thread overview] Message-ID: <20171009222028.13096-3-chenbofeng.kernel@gmail.com> (raw) In-Reply-To: <20171009222028.13096-1-chenbofeng.kernel@gmail.com> From: Chenbo Feng <fengc@google.com> Two related tests are added into bpf selftest to test read only map and write only map. The tests verified the read only and write only flags are working on hash maps. Signed-off-by: Chenbo Feng <fengc@google.com> --- tools/testing/selftests/bpf/test_maps.c | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index fe3a443a1102..896f23cfe918 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -1033,6 +1033,51 @@ static void test_map_parallel(void) assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT); } +static void test_map_rdonly(void) +{ + int i, fd, key = 0, value = 0; + + fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), + MAP_SIZE, map_flags | BPF_F_RDONLY); + if (fd < 0) { + printf("Failed to create map for read only test '%s'!\n", + strerror(errno)); + exit(1); + } + + key = 1; + value = 1234; + /* Insert key=1 element. */ + assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == -1 && + errno == EPERM); + + /* Check that key=2 is not found. */ + assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); + assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == ENOENT); +} + +static void test_map_wronly(void) +{ + int i, fd, key = 0, value = 0; + + 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", + strerror(errno)); + exit(1); + } + + key = 1; + value = 1234; + /* Insert key=1 element. */ + assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0) + + /* Check that key=2 is not found. */ + assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == EPERM); + assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == EPERM); +} + static void run_all_tests(void) { test_hashmap(0, NULL); @@ -1050,6 +1095,9 @@ static void run_all_tests(void) test_map_large(); test_map_parallel(); test_map_stress(); + + test_map_rdonly(); + test_map_wronly(); } int main(void) -- 2.14.2.920.gcf0c67979c-goog
WARNING: multiple messages have this Message-ID (diff)
From: chenbofeng.kernel@gmail.com (Chenbo Feng) To: linux-security-module@vger.kernel.org Subject: [PATCH net-next v2 2/5] bpf: Add tests for eBPF file mode Date: Mon, 9 Oct 2017 15:20:25 -0700 [thread overview] Message-ID: <20171009222028.13096-3-chenbofeng.kernel@gmail.com> (raw) In-Reply-To: <20171009222028.13096-1-chenbofeng.kernel@gmail.com> From: Chenbo Feng <fengc@google.com> Two related tests are added into bpf selftest to test read only map and write only map. The tests verified the read only and write only flags are working on hash maps. Signed-off-by: Chenbo Feng <fengc@google.com> --- tools/testing/selftests/bpf/test_maps.c | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index fe3a443a1102..896f23cfe918 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -1033,6 +1033,51 @@ static void test_map_parallel(void) assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT); } +static void test_map_rdonly(void) +{ + int i, fd, key = 0, value = 0; + + fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), + MAP_SIZE, map_flags | BPF_F_RDONLY); + if (fd < 0) { + printf("Failed to create map for read only test '%s'!\n", + strerror(errno)); + exit(1); + } + + key = 1; + value = 1234; + /* Insert key=1 element. */ + assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == -1 && + errno == EPERM); + + /* Check that key=2 is not found. */ + assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); + assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == ENOENT); +} + +static void test_map_wronly(void) +{ + int i, fd, key = 0, value = 0; + + 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", + strerror(errno)); + exit(1); + } + + key = 1; + value = 1234; + /* Insert key=1 element. */ + assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0) + + /* Check that key=2 is not found. */ + assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == EPERM); + assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == EPERM); +} + static void run_all_tests(void) { test_hashmap(0, NULL); @@ -1050,6 +1095,9 @@ static void run_all_tests(void) test_map_large(); test_map_parallel(); test_map_stress(); + + test_map_rdonly(); + test_map_wronly(); } int main(void) -- 2.14.2.920.gcf0c67979c-goog -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info@ http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-10-09 22:20 UTC|newest] Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-10-09 22:20 [PATCH net-next v2 0/5] bpf: security: New file mode and LSM hooks for eBPF object permission control Chenbo Feng 2017-10-09 22:20 ` Chenbo Feng 2017-10-09 22:20 ` [PATCH net-next v2 1/5] bpf: Add file mode configuration into bpf maps Chenbo Feng 2017-10-09 22:20 ` Chenbo Feng 2017-10-09 23:07 ` Alexei Starovoitov 2017-10-09 23:07 ` Alexei Starovoitov 2017-10-09 23:31 ` Chenbo Feng 2017-10-09 23:31 ` Chenbo Feng 2017-10-09 22:20 ` Chenbo Feng [this message] 2017-10-09 22:20 ` [PATCH net-next v2 2/5] bpf: Add tests for eBPF file mode Chenbo Feng 2017-10-09 22:20 ` [PATCH net-next v2 3/5] security: bpf: Add LSM hooks for bpf object related syscall Chenbo Feng 2017-10-09 22:20 ` Chenbo Feng 2017-10-09 22:20 ` [PATCH net-next v2 4/5] selinux: bpf: Add selinux check for eBPF syscall operations Chenbo Feng 2017-10-09 22:20 ` Chenbo Feng 2017-10-10 14:18 ` Stephen Smalley 2017-10-10 14:18 ` Stephen Smalley [not found] ` <1507645097.30616.6.camel-+05T5uksL2qpZYMLLGbcSA@public.gmane.org> 2017-10-10 14:52 ` Stephen Smalley 2017-10-10 14:52 ` Stephen Smalley 2017-10-10 14:52 ` Stephen Smalley 2017-10-10 17:54 ` Chenbo Feng 2017-10-10 17:54 ` Chenbo Feng 2017-10-11 13:00 ` Stephen Smalley 2017-10-11 13:00 ` Stephen Smalley 2017-10-10 17:59 ` kbuild test robot 2017-10-10 17:59 ` kbuild test robot 2017-10-10 21:30 ` kbuild test robot 2017-10-10 21:30 ` kbuild test robot 2017-10-09 22:20 ` [PATCH net-next v2 5/5] selinux: bpf: Add addtional check for bpf object file receive Chenbo Feng 2017-10-09 22:20 ` Chenbo Feng 2017-10-10 14:24 ` Stephen Smalley 2017-10-10 14:24 ` Stephen Smalley 2017-10-10 17:48 ` Chenbo Feng 2017-10-10 17:48 ` Chenbo Feng 2017-10-10 19:23 ` [Non-DoD Source] " Stephen Smalley 2017-10-10 19:23 ` Stephen Smalley 2017-10-10 19:23 ` Stephen Smalley 2017-10-10 19:42 ` [Non-DoD Source] " Chenbo Feng 2017-10-10 19:42 ` Chenbo Feng 2017-10-10 19:42 ` Chenbo Feng
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20171009222028.13096-3-chenbofeng.kernel@gmail.com \ --to=chenbofeng.kernel@gmail.com \ --cc=Selinux@tycho.nsa.gov \ --cc=alexei.starovoitov@gmail.com \ --cc=daniel@iogearbox.net \ --cc=fengc@google.com \ --cc=jeffv@google.com \ --cc=linux-security-module@vger.kernel.org \ --cc=lorenzo@google.com \ --cc=netdev@vger.kernel.org \ --cc=sds@tycho.nsa.gov \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.