Host insane unsafe usage

This commit is contained in:
Ciro Santilli
2017-08-03 04:32:06 +01:00
parent dfc4981e46
commit 0bb3e8519a
13 changed files with 85 additions and 54 deletions

View File

@@ -1,10 +1,10 @@
obj-m += $(addsuffix .o, $(notdir $(basename $(wildcard $(BR2_EXTERNAL_KERNEL_MODULE_PATH)/*.c))))
ccflags-y := -DDEBUG -g -std=gnu99 -Werror -Wno-declaration-after-statement
obj-m += $(addsuffix .o, $(notdir $(basename $(filter-out %.mod.c, $(wildcard $(BR2_EXTERNAL_KERNEL_MODULE_PATH)/*.c)))))
ccflags-y := -DDEBUG -g -std=gnu99 -Werror -Wno-declaration-after-statement -Wframe-larger-than=1000000000
.PHONY: all clean
all:
$(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' modules
$(MAKE) -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' modules
clean:
$(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' clean

15
kernel_module/make-host.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# We can almost do everything from the Makefile itself by using default values for
#
# LINUX_DIR ?= "/lib/modules/$(uname -r)/build"
# BR2_EXTERNAL_KERNEL_MODULE_PATH="$(pwd)"
#
# The problem with that is that if you define those variables in your environment,
# the build breaks, so this is more portable.
#
# Trying to add `-i` to overcome incompatible modules will fail,
# because any build failure prevents the generation of all `.mod.c` files.
make -j $(($(nproc) - 2)) BR2_EXTERNAL_KERNEL_MODULE_PATH="$(pwd)" LINUX_DIR="/lib/modules/$(uname -r)/build" "$@"
make -C user/ -j $(($(nproc) - 2)) "$@"

View File

@@ -1,6 +1,6 @@
.PHONY: clean
.PHONY: all clean
CC ?= gcc -ggdb3 -O0 -std=c99 -Wall -Werror -Wextra
CCC ?= gcc -ggdb3 -O0 -std=c99 -Wall -Werror -Wextra
IN_EXT ?= .c
OUT_EXT ?= .out
@@ -9,7 +9,7 @@ OUTS := $(addsuffix $(OUT_EXT), $(basename $(wildcard *$(IN_EXT))))
all: $(OUTS)
%$(OUT_EXT): %$(IN_EXT)
$(CC) -o '$@' '$<'
$(CCC) -o '$@' '$<'
clean:
rm -f *'$(OUT_EXT)'

View File

@@ -1,7 +1,7 @@
#ifndef COMMON_H
#define COMMON_H
#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700
#include <fcntl.h> /* open */
#include <stdint.h> /* uint64_t */
#include <stdlib.h> /* size_t */

View File

@@ -1,3 +1,4 @@
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>

View File

@@ -11,7 +11,7 @@ Dump the page map of a given process PID.
Data sources: /proc/PIC/{map,pagemap}
*/
#define _POSIX_C_SOURCE 200809L
#define _XOPEN_SOURCE 700
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
@@ -63,7 +63,6 @@ int main(int argc, char **argv) {
size_t x = i - 1;
while (x && buffer[x] != '\n') x--;
if (buffer[x] == '\n') x++;
size_t beginning = x;
while (buffer[x] != '-' && x < sizeof buffer) {
char c = buffer[x++];
low *= 16;

View File

@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <fcntl.h> /* creat, O_CREAT */
#include <poll.h> /* poll */
#include <stdio.h> /* printf, puts, snprintf */
@@ -6,11 +7,15 @@
#include <unistd.h> /* read */
int main(int argc, char **argv) {
char buf[1024], path[1024];
char buf[1024];
int fd, i, n;
short revents;
struct pollfd pfd;
if (argc < 2) {
fprintf(stderr, "usage: %s <poll-device>\n", argv[0]);
exit(EXIT_FAILURE);
}
fd = open(argv[1], O_RDONLY | O_NONBLOCK);
if (fd == -1) {
perror("open");
@@ -23,7 +28,7 @@ int main(int argc, char **argv) {
i = poll(&pfd, 1, -1);
if (i == -1) {
perror("poll");
exit(EXIT_FAILURE);
assert(0);
}
revents = pfd.revents;
if (revents & POLLIN) {

View File

@@ -39,7 +39,7 @@ Yes!!! We read the correct value from the physical address.
## /dev/mem
Firts up, this requires:
Firt up, this requires:
- CONFIG_STRICT_DEVMEM is not set.
- nopat on kernel parameters

View File

@@ -6,6 +6,7 @@ https://stackoverflow.com/questions/5748492/is-there-any-api-for-determining-the
Test this out with usermem.c.
*/
#define _XOPEN_SOURCE 700
#include <stdio.h> /* printf */
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE, strtoull */
@@ -14,7 +15,7 @@ Test this out with usermem.c.
int main(int argc, char **argv)
{
pid_t pid;
uintptr_t vaddr, paddr;
uintptr_t vaddr, paddr = 0;
if (argc < 3) {
printf("Usage: %s pid vaddr\n", argv[0]);