This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #1808: block mknod(2) only if creating a device
- Loading branch information
Showing
9 changed files
with
199 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# ch-test-scope: full | ||
# ch-test-scope: skip #1810 | ||
FROM openmpi | ||
WORKDIR /usr/local/src | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ch-test-builder-include: ch-image | ||
FROM alpine:3.17 | ||
RUN apk add gcc musl-dev strace | ||
RSYNC / / | ||
RUN gcc -std=c11 -Wall -Werror -fmax-errors=1 -o mknods mknods.c | ||
RUN strace ./mknods | ||
RUN ls -lh /_* | ||
RUN test $(ls /_* | wc -l) == 2 | ||
RUN test -p /_mknod_fifo | ||
RUN test -p /_mknodat_fifo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Use mknod(2) and mknodat(2) to create character and block devices (which | ||
should be blocked by the seccomp filters) and FIFOs (which should not.) */ | ||
|
||
#define _GNU_SOURCE | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <sys/sysmacros.h> | ||
|
||
#define DEVNULL makedev(1,3) // character device /dev/null | ||
#define DEVRAM0 makedev(1,0) // block device /dev/ram0 | ||
#define Z_(x) if (x) (fprintf(stderr, "failed: %d: %s (%d)\n", \ | ||
__LINE__, strerror(errno), errno), \ | ||
exit(1)) | ||
|
||
int main(void) | ||
{ | ||
Z_ (mknod("/_mknod_chr", S_IFCHR, DEVNULL)); | ||
Z_ (mknod("/_mknod_blk", S_IFBLK, DEVRAM0)); | ||
Z_ (mknod("/_mknod_fifo", S_IFIFO, 0)); | ||
|
||
Z_ (mknodat(AT_FDCWD, "./_mknodat_chr", S_IFCHR, DEVNULL)); | ||
Z_ (mknodat(AT_FDCWD, "./_mknodat_blk", S_IFBLK, DEVRAM0)); | ||
Z_ (mknodat(AT_FDCWD, "./_mknodat_fifo", S_IFIFO, 0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CH_TEST_TAG=$ch_test_tag | ||
load "$CHTEST_DIR"/common.bash | ||
|
||
setup () { | ||
prerequisites_ok seccomp | ||
} | ||
|
||
@test "${ch_tag}/fifos only" { | ||
ch-run "$ch_img" -- sh -c 'ls -lh /_*' | ||
# shellcheck disable=SC2016 | ||
ch-run "$ch_img" -- sh -c 'test $(ls /_* | wc -l) == 2' | ||
ch-run "$ch_img" -- test -p /_mknod_fifo | ||
ch-run "$ch_img" -- test -p /_mknodat_fifo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters