Skip to content

Commit

Permalink
tetragon: Add direct-write-tester tester prog
Browse files Browse the repository at this point in the history
Adding direct-write-tester tester prog to test the bypass of sigkill
action in pwrite. It's originally written by Anastasios.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Jan 29, 2024
1 parent 9a7a956 commit e02a421
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contrib/tester-progs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ PROGS = sigkill-tester \
threads-exit \
killer-tester \
drop-privileges \
getcpu
getcpu \
direct-write-tester

# For now killer-tester is compiled to 32-bit only on x86_64 as we want
# to test 32-bit binaries and system calls compatibility layer.
Expand Down
43 changes: 43 additions & 0 deletions contrib/tester-progs/direct-write-tester.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
// Copyright Authors of Tetragon

#include <fcntl.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>

#define BLOCKSIZE 4096
#define O_DIRECT 00040000

int main(int argc, char **argv)
{
char *avd = "NEW_MESSAGE\n";
void *buffer;
int fd;

if (argc != 2)
exit(-1);

fd = open(argv[1], O_WRONLY | O_DIRECT | O_CREAT, S_IRWXU | S_IRWXG);
if (fd == -1) {
perror("open");
exit(-1);
}

posix_memalign(&buffer, BLOCKSIZE, BLOCKSIZE);
memset(buffer, 0, BLOCKSIZE);
memcpy(buffer, avd, strlen(avd) + 1);

ssize_t ret = pwrite(fd, buffer, BLOCKSIZE, 0);
if (ret == -1) {
perror("write");
exit(-1);
}

close(fd);
free(buffer);
return 0;
}

0 comments on commit e02a421

Please sign in to comment.