0

So, here is the function that should create and write string into a /proc/minifwdb:

int write_to_file(char* rule)
{
    FILE* fin;

    fin = fopen("/proc/minifwdb", "a");

    if (!fin)
    {
        printf("Could not open the file /proc/minifwdb, exiting...\n");
        return 1;
    }

    if (fprintf(fin, "%s\n", rule) < 0)
        return 1;

    fclose(fin);

    return 0;
}

When fopen() is called, it returns NULL. And there is no such file as /proc/minifwdb currently. Do I need to create it using LKM, and then use it to write the info? I am also trying to create it from the user that has no root access. Any suggestions?

6
  • 4
    You can't from userspace, but why are you even trying? What are you trying to accomplish by creating a file in /proc?
    – Mat
    May 31, 2014 at 7:18
  • I need to pass a string from user space into the kernel. May 31, 2014 at 7:20
  • Then yes, you need to do that from the kernel side.
    – Mat
    May 31, 2014 at 7:23
  • I can write the module that will be loaded in this function using syscall, for example >syscall("sudo insmod create_file.ko"). The module will simply create a new file in procfs, and then I will write the string there. Does that sounds like something adequate? May 31, 2014 at 7:27
  • No that's not how you should do it. also the fact that you are trying to run a sudo command from syscall you REALLY don't seem to know what you are doing. Can you explain WHY you want to have something written in the kernel? What is your end goal, may be then we can help May 31, 2014 at 21:34

1 Answer 1

2

Files in /proc are used as an interface between user space and the kernel.

It is possible to use such a file to pass a string from user space into the kernel, but the kernel code that wants to receive it is responsible for creating the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.