septical
septical

Reputation: 440

OpenBSD Kernel module calling network functions

As a proof-of-concept, plus a handy paranoid tool, I'm writing an OpenBSD LKM that will connect to an IRC channel, and report when hooked syscalls are executed.

This is so I can essentially have a 'live' update of filesystem changes, user logons, etc., when I'm offsite but have internet access.

I've gotten as far as connecting the socket, but am stuck at trying to perform the equivalent of a getaddrinfo or even inet_addr call with a hardcoded address.

As these are userland functions, any attempts to use them will result in undefined references - fair enough. The trouble is, after a while of Googling and grep'ing the openbsd source, I cannot find any equivalent kernel functions to do this; the best recommendation has been to reimplement them in the module.

This means I need to also implement things like islower, isxdigit and isspace (and probably others as I progress), which gets a bit much to perform something so simple; is anyone aware of a workaround or alternative for this, or am I stuck c+p code from the net files?

Upvotes: 1

Views: 470

Answers (1)

Michael McConville
Michael McConville

Reputation: 46

This is definitely better done in userspace. Regardless, OpenBSD no longer supports kernel modules.

Not that you're working on this project anymore. I just wanted to answer so that this could be closed, and so that I could clarify how to use some stdlib functions in the kernel.

In response to this:

This means I need to also implement things like islower, isxdigit and isspace (and probably others as I progress), which gets a bit much to perform something so simple; is anyone aware of a workaround or alternative for this, or am I stuck c+p code from the net files?

Some C stdlib functions are available from libkern (see libkern(9)). Others, including many of the ctype functions like islower(), are available from libsa. To use these, you need something like:

#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>

libsa contains a handful of headers (found in /usr/src/sys/lib/libsa/), so include each one you need.

Upvotes: 2

Related Questions