aboutsummaryrefslogtreecommitdiff
path: root/kernel/inc
diff options
context:
space:
mode:
authorMarvin Borner2021-04-01 19:39:14 +0200
committerMarvin Borner2021-04-01 19:39:14 +0200
commitafa00abb2b68205bee539d7947130d6b1b1ec6e9 (patch)
tree3a821a75af6c4d4ff1bd4128c4859d77abf87e66 /kernel/inc
parent4c168fb34c15a1b8981abef7ccef1542a6fb05ca (diff)
Hardened entire system
By using the nonnull attribute and replace buffer-overflow-prone functions like strcpy, strcat and sprintf by strlcpy, strlcat and snprintf.
Diffstat (limited to 'kernel/inc')
-rw-r--r--kernel/inc/acpi.h18
-rw-r--r--kernel/inc/fb.h4
-rw-r--r--kernel/inc/fs.h56
-rw-r--r--kernel/inc/interrupts.h10
-rw-r--r--kernel/inc/load.h2
-rw-r--r--kernel/inc/mm.h36
-rw-r--r--kernel/inc/net.h26
-rw-r--r--kernel/inc/pci.h10
-rw-r--r--kernel/inc/proc.h8
-rw-r--r--kernel/inc/rtl8139.h2
-rw-r--r--kernel/inc/serial.h4
-rw-r--r--kernel/inc/timer.h2
12 files changed, 91 insertions, 87 deletions
diff --git a/kernel/inc/acpi.h b/kernel/inc/acpi.h
index f2fd030..29dcd32 100644
--- a/kernel/inc/acpi.h
+++ b/kernel/inc/acpi.h
@@ -67,7 +67,7 @@ struct madt {
u32 local_address;
u32 flags;
struct madt_entry_header entry;
-} __attribute__((packed));
+} PACKED;
#define MADT_LOCAL_APIC_ENTRY 0
#define MADT_IO_APIC_ENTRY 1
@@ -80,7 +80,7 @@ struct madt_local_apic_entry {
u8 processor_id;
u8 id;
u32 flags;
-} __attribute__((packed));
+} PACKED;
struct madt_io_apic_entry {
struct madt_entry_header header;
@@ -88,7 +88,7 @@ struct madt_io_apic_entry {
u8 reserved;
u32 address;
u32 global_system_interrupt_base;
-} __attribute__((packed));
+} PACKED;
struct madt_int_src_override_entry {
struct madt_entry_header header;
@@ -96,20 +96,20 @@ struct madt_int_src_override_entry {
u8 irq_source;
u32 global_system_interrupt;
u16 flags;
-} __attribute__((packed));
+} PACKED;
struct madt_non_maskable_int_entry {
struct madt_entry_header header;
u8 processor_id;
u16 flags;
u8 lint_number;
-} __attribute__((packed));
+} PACKED;
struct madt_local_apic_override_entry {
struct madt_entry_header header;
u16 reserved;
u64 address;
-} __attribute__((packed));
+} PACKED;
/**
* FADT
@@ -118,7 +118,7 @@ struct madt_local_apic_override_entry {
struct fadt {
struct sdt_header header;
// TODO: FADT table (big!)
-} __attribute__((packed));
+} PACKED;
/**
* HPET
@@ -136,7 +136,7 @@ struct hpet {
u8 hpet_number;
u16 minimum_tick;
u8 page_protection;
-} __attribute__((packed));
+} PACKED;
enum hpet_features { hpet_counter_size = 1 << 3, hpet_legacy_replacement_support = 1 << 5 };
enum hpet_config { hpet_enable = 1 << 0, hpet_legacy_replacement = 1 << 1 };
@@ -168,7 +168,7 @@ struct hpet_registers {
u64 reserved5;
u64 timer0; // enum hpet_timer
u64 timer_comparator0; // In femtoseconds
-} __attribute__((packed));
+} PACKED;
/**
* RSDP
diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h
index 3b545fd..052f3d2 100644
--- a/kernel/inc/fb.h
+++ b/kernel/inc/fb.h
@@ -6,7 +6,7 @@
#include <boot.h>
#include <mm.h>
-void fb_map_buffer(struct page_dir *dir, struct vid_info *boot);
-void fb_install(struct vid_info *boot);
+void fb_map_buffer(struct page_dir *dir, struct vid_info *boot) NONNULL;
+void fb_install(struct vid_info *boot) NONNULL;
#endif
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index 4b333ac..b6c30a2 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -19,15 +19,16 @@ struct device {
enum dev_type type;
struct vfs *vfs;
void *data;
- res (*read)(void *buf, u32 offset, u32 count, struct device *dev);
- res (*write)(void *buf, u32 offset, u32 count, struct device *dev);
- res (*ioctl)(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev);
+ res (*read)(void *buf, u32 offset, u32 count, struct device *dev) NONNULL;
+ res (*write)(void *buf, u32 offset, u32 count, struct device *dev) NONNULL;
+ res (*ioctl)(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev)
+ ATTR((nonnull(5)));
res (*ready)(void);
};
void device_install(void);
-void device_add(struct device *dev);
+void device_add(struct device *dev) NONNULL;
/**
* VFS
@@ -40,14 +41,15 @@ struct vfs {
enum vfs_type type;
int flags;
void *data;
- res (*read)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
- res (*write)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
+ res (*read)(const char *path, void *buf, u32 offset, u32 count, struct device *dev) NONNULL;
+ res (*write)(const char *path, void *buf, u32 offset, u32 count,
+ struct device *dev) NONNULL;
res (*ioctl)(const char *path, u32 request, void *arg1, void *arg2, void *arg3,
- struct device *dev);
- res (*stat)(const char *path, struct stat *buf, struct device *dev);
- res (*wait)(const char *path, u32 func_ptr, struct device *dev);
- res (*ready)(const char *path, struct device *dev);
- res (*perm)(const char *path, enum vfs_perm perm, struct device *dev);
+ struct device *dev) ATTR((nonnull(1, 6)));
+ res (*stat)(const char *path, struct stat *buf, struct device *dev) NONNULL;
+ res (*wait)(const char *path, u32 func_ptr, struct device *dev) NONNULL;
+ res (*ready)(const char *path, struct device *dev) NONNULL;
+ res (*perm)(const char *path, enum vfs_perm perm, struct device *dev) NONNULL;
};
struct mount_info {
@@ -57,21 +59,21 @@ struct mount_info {
void vfs_install(void);
-u8 vfs_mounted(struct device *dev, const char *path);
-res vfs_mount(struct device *dev, const char *path);
+u8 vfs_mounted(struct device *dev, const char *path) NONNULL;
+res vfs_mount(struct device *dev, const char *path) NONNULL;
-struct device *vfs_find_dev(const char *path);
+struct device *vfs_find_dev(const char *path) NONNULL;
-res vfs_read(const char *path, void *buf, u32 offset, u32 count);
-res vfs_write(const char *path, void *buf, u32 offset, u32 count);
-res vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3);
-res vfs_stat(const char *path, struct stat *buf);
-res vfs_wait(const char *path, u32 func_ptr);
-res vfs_poll(const char **files);
-res vfs_ready(const char *path);
+res vfs_read(const char *path, void *buf, u32 offset, u32 count) NONNULL;
+res vfs_write(const char *path, void *buf, u32 offset, u32 count) NONNULL;
+res vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3) ATTR((nonnull(1)));
+res vfs_stat(const char *path, struct stat *buf) NONNULL;
+res vfs_wait(const char *path, u32 func_ptr) NONNULL;
+res vfs_poll(const char **files) NONNULL;
+res vfs_ready(const char *path) NONNULL;
-struct device *device_get_by_name(const char *name);
-struct device *device_get_by_id(u32 id);
+struct device *device_get_by_name(const char *name) NONNULL;
+struct device *device_get_by_id(u32 id) NONNULL;
/**
* EXT2
@@ -175,9 +177,9 @@ struct ext2_file {
u32 curr_block_pos;
};
-res ext2_read(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
-res ext2_stat(const char *path, struct stat *buf, struct device *dev);
-res ext2_perm(const char *path, enum vfs_perm perm, struct device *dev);
-res ext2_ready(const char *path, struct device *dev);
+res ext2_read(const char *path, void *buf, u32 offset, u32 count, struct device *dev) NONNULL;
+res ext2_stat(const char *path, struct stat *buf, struct device *dev) NONNULL;
+res ext2_perm(const char *path, enum vfs_perm perm, struct device *dev) NONNULL;
+res ext2_ready(const char *path, struct device *dev) NONNULL;
#endif
diff --git a/kernel/inc/interrupts.h b/kernel/inc/interrupts.h
index fc00402..a22bebb 100644
--- a/kernel/inc/interrupts.h
+++ b/kernel/inc/interrupts.h
@@ -18,21 +18,21 @@ struct idt_entry {
u8 always0; // Always 0
u8 flags;
u16 base_high;
-} __attribute__((packed));
+} PACKED;
struct idt_ptr {
u16 limit;
void *base;
-} __attribute__((packed));
+} PACKED;
void idt_set_gate(u8 num, u32 base, u16 sel, u8 flags);
-void irq_install_handler(int irq, void (*handler)(struct regs *r));
+void irq_install_handler(int irq, void (*handler)(struct regs *r)) NONNULL;
void irq_uninstall_handler(int irq);
-void isr_install_handler(int isr, void (*handler)(struct regs *r));
+void isr_install_handler(int isr, void (*handler)(struct regs *r)) NONNULL;
void isr_uninstall_handler(int isr);
-void isr_panic(struct regs *r);
+void isr_panic(struct regs *r) NONNULL;
void interrupts_install(void);
diff --git a/kernel/inc/load.h b/kernel/inc/load.h
index 363a70f..365da79 100644
--- a/kernel/inc/load.h
+++ b/kernel/inc/load.h
@@ -105,6 +105,6 @@ struct elf_program {
u32 align;
};
-res elf_load(const char *path, struct proc *proc);
+res elf_load(const char *path, struct proc *proc) NONNULL;
#endif
diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h
index ae4e962..fa9211c 100644
--- a/kernel/inc/mm.h
+++ b/kernel/inc/mm.h
@@ -18,7 +18,7 @@ struct memory_range {
*/
void paging_enable(void);
-void page_fault_handler(struct regs *r);
+void page_fault_handler(struct regs *r) NONNULL;
/**
* Physical
@@ -81,14 +81,14 @@ struct page_dir {
union page_dir_entry entries[PAGE_COUNT];
} PACKED;
-u8 virtual_present(struct page_dir *dir, u32 vaddr);
-u32 virtual_to_physical(struct page_dir *dir, u32 vaddr);
-void virtual_map(struct page_dir *dir, struct memory_range prange, u32 vaddr, u32 flags);
+u8 virtual_present(struct page_dir *dir, u32 vaddr) NONNULL;
+u32 virtual_to_physical(struct page_dir *dir, u32 vaddr) NONNULL;
+void virtual_map(struct page_dir *dir, struct memory_range prange, u32 vaddr, u32 flags) NONNULL;
struct memory_range virtual_alloc(struct page_dir *dir, struct memory_range physical_range,
- u32 flags);
-void virtual_free(struct page_dir *dir, struct memory_range vrange);
+ u32 flags) NONNULL;
+void virtual_free(struct page_dir *dir, struct memory_range vrange) NONNULL;
struct page_dir *virtual_create_dir(void);
-void virtual_destroy_dir(struct page_dir *dir);
+void virtual_destroy_dir(struct page_dir *dir) NONNULL;
struct page_dir *virtual_kernel_dir(void);
/**
@@ -103,24 +103,24 @@ struct page_dir *virtual_kernel_dir(void);
struct memory_range memory_range_from(u32 base, u32 size);
struct memory_range memory_range_around(u32 base, u32 size);
-void *memory_alloc(struct page_dir *dir, u32 size, u32 flags);
-void *memory_alloc_identity(struct page_dir *dir, u32 flags);
-void memory_free(struct page_dir *dir, struct memory_range vrange);
-void memory_map_identity(struct page_dir *dir, struct memory_range prange, u32 flags);
-void memory_switch_dir(struct page_dir *dir);
-void memory_backup_dir(struct page_dir **backup);
+void *memory_alloc(struct page_dir *dir, u32 size, u32 flags) NONNULL;
+void *memory_alloc_identity(struct page_dir *dir, u32 flags) NONNULL;
+void memory_free(struct page_dir *dir, struct memory_range vrange) NONNULL;
+void memory_map_identity(struct page_dir *dir, struct memory_range prange, u32 flags) NONNULL;
+void memory_switch_dir(struct page_dir *dir) NONNULL;
+void memory_backup_dir(struct page_dir **backup) NONNULL;
// Bypass should almost never be used
void memory_bypass_enable(void);
void memory_bypass_disable(void);
u8 memory_is_user(u32 addr);
-u8 memory_valid(const void *addr);
+u8 memory_valid(const void *addr) NONNULL;
// User interface
-res memory_sys_alloc(struct page_dir *dir, u32 size, u32 *addr, u32 *id, u8 shared);
-res memory_sys_free(struct page_dir *dir, u32 addr);
-res memory_sys_shaccess(struct page_dir *dir, u32 id, u32 *addr, u32 *size);
+res memory_sys_alloc(struct page_dir *dir, u32 size, u32 *addr, u32 *id, u8 shared) NONNULL;
+res memory_sys_free(struct page_dir *dir, u32 addr) NONNULL;
+res memory_sys_shaccess(struct page_dir *dir, u32 id, u32 *addr, u32 *size) NONNULL;
-void memory_install(struct mem_info *mem_info, struct vid_info *vid_info);
+void memory_install(struct mem_info *mem_info, struct vid_info *vid_info) NONNULL;
#endif
diff --git a/kernel/inc/net.h b/kernel/inc/net.h
index 2852328..62ff5e5 100644
--- a/kernel/inc/net.h
+++ b/kernel/inc/net.h
@@ -53,7 +53,7 @@ struct ethernet_packet {
u8 src[6];
u16 type;
u8 data[];
-} __attribute__((packed));
+} PACKED;
struct arp_packet {
u16 hardware_type;
@@ -65,7 +65,7 @@ struct arp_packet {
u32 src_protocol_addr;
u8 dst_mac[6];
u32 dst_protocol_addr;
-} __attribute__((packed));
+} PACKED;
struct ip_packet {
u8 version_ihl;
@@ -79,7 +79,7 @@ struct ip_packet {
u32 src;
u32 dst;
u8 data[];
-} __attribute__((packed));
+} PACKED;
struct dhcp_packet {
u8 op;
@@ -98,7 +98,7 @@ struct dhcp_packet {
u8 server_name[64];
u8 file[128];
u8 options[64];
-} __attribute__((packed));
+} PACKED;
struct dns_packet {
u16 qid;
@@ -108,7 +108,7 @@ struct dns_packet {
u16 authorities;
u16 additional;
u8 data[];
-} __attribute__((packed));
+} PACKED;
struct udp_packet {
u16 src_port;
@@ -116,7 +116,7 @@ struct udp_packet {
u16 length;
u16 checksum;
u8 data[];
-} __attribute__((packed));
+} PACKED;
struct tcp_packet {
u16 src_port;
@@ -128,7 +128,7 @@ struct tcp_packet {
u16 checksum;
u16 urgent;
u8 data[];
-} __attribute__((packed));
+} PACKED;
struct tcp_pseudo_header {
u32 src;
@@ -145,7 +145,7 @@ struct icmp_packet {
u16 checksum;
u16 identifier;
u16 sequence;
-} __attribute__((packed));
+} PACKED;
// Other structs
@@ -154,13 +154,13 @@ struct arp_table_entry {
u64 mac_addr;
};
-void ethernet_handle_packet(struct ethernet_packet *packet, int len);
+void ethernet_handle_packet(struct ethernet_packet *packet, int len) NONNULL;
struct socket *net_open(enum socket_type type);
-int net_close(struct socket *socket);
-int net_connect(struct socket *socket, u32 ip_addr, u16 dst_port);
-void net_send(struct socket *socket, void *data, u32 len);
-int net_receive(struct socket *socket, void *buf, u32 len);
+int net_close(struct socket *socket) NONNULL;
+int net_connect(struct socket *socket, u32 ip_addr, u16 dst_port) NONNULL;
+void net_send(struct socket *socket, void *data, u32 len) NONNULL;
+int net_receive(struct socket *socket, void *buf, u32 len) NONNULL;
int net_installed(void);
void net_install(void);
diff --git a/kernel/inc/pci.h b/kernel/inc/pci.h
index 11fad6f..9429f29 100644
--- a/kernel/inc/pci.h
+++ b/kernel/inc/pci.h
@@ -91,11 +91,11 @@ static inline u32 pci_box_device(int bus, int slot, int func)
u32 pci_read_field(u32 device, int field, int size);
void pci_write_field(u32 device, int field, u32 value);
u16 pci_find_type(u32 dev);
-void pci_scan_hit(pci_func_t f, u32 dev, void *extra);
-void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void *extra);
-void pci_scan_slot(pci_func_t f, int type, int bus, int slot, void *extra);
-void pci_scan_bus(pci_func_t f, int type, int bus, void *extra);
-void pci_scan(pci_func_t f, int type, void *extra);
+void pci_scan_hit(pci_func_t f, u32 dev, void *extra) NONNULL;
+void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void *extra) NONNULL;
+void pci_scan_slot(pci_func_t f, int type, int bus, int slot, void *extra) NONNULL;
+void pci_scan_bus(pci_func_t f, int type, int bus, void *extra) NONNULL;
+void pci_scan(pci_func_t f, int type, void *extra) NONNULL;
int pci_get_interrupt(u32 device);
void pci_install(void);
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 71d1284..8a68131 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -61,18 +61,18 @@ struct proc {
struct list *memory;
};
-void scheduler(struct regs *regs);
+void scheduler(struct regs *regs) NONNULL;
void proc_init(void);
void proc_print(void);
struct proc *proc_current(void);
u8 proc_super(void);
struct proc *proc_from_pid(u32 pid);
-void proc_exit(struct proc *proc, s32 status);
-void proc_yield(struct regs *r);
+void proc_exit(struct proc *proc, s32 status) NONNULL;
+void proc_yield(struct regs *r) NONNULL;
void proc_clear_quantum(void);
void proc_enable_waiting(u32 id, enum proc_wait_type type);
void proc_wait_for(u32 id, enum proc_wait_type type, u32 func_ptr);
struct proc *proc_make(enum proc_priv priv);
-void proc_stack_push(struct proc *proc, u32 data);
+void proc_stack_push(struct proc *proc, u32 data) NONNULL;
#endif
diff --git a/kernel/inc/rtl8139.h b/kernel/inc/rtl8139.h
index bbb904e..0d748af 100644
--- a/kernel/inc/rtl8139.h
+++ b/kernel/inc/rtl8139.h
@@ -30,7 +30,7 @@
int rtl8139_install(void);
int rtl8139_installed(void);
-void rtl8139_send_packet(void *data, u32 len);
+void rtl8139_send_packet(void *data, u32 len) NONNULL;
u8 *rtl8139_get_mac(void);
#endif
diff --git a/kernel/inc/serial.h b/kernel/inc/serial.h
index 7ca5ac2..e96316a 100644
--- a/kernel/inc/serial.h
+++ b/kernel/inc/serial.h
@@ -3,8 +3,10 @@
#ifndef SERIAL_H
#define SERIAL_H
+#include <def.h>
+
void serial_install(void);
-void serial_print(const char *data);
+void serial_print(const char *data) NONNULL;
void serial_put(char ch);
#endif
diff --git a/kernel/inc/timer.h b/kernel/inc/timer.h
index 5d747d0..0712e37 100644
--- a/kernel/inc/timer.h
+++ b/kernel/inc/timer.h
@@ -9,7 +9,7 @@
u32 timer_get(void);
void timer_wait(u32 ticks);
void timer_install(void);
-void timer_handler(struct regs *r);
+void timer_handler(struct regs *r) NONNULL;
void scheduler_enable(void);
void scheduler_disable(void);