How would I code a Write to a proc file from within the kernel without reading anything from user space?
Michael Ellerman
mpe at ellerman.id.au
Thu Aug 6 11:30:20 AEST 2020
thefirst ECS <ecs_dn at yahoo.com> writes:
> In order to help debug a certain discrepancy, I need to "simulate" an "echo 1 > /proc/file" but doing it from kernel even when root file system is unavailable.
>
> I have simulated it just fine via call_usermodehelper (with argv etc of "echo 1 > /proc/file") from inside the kernel which triggers:
> [ee897ec0] [c0122704] proc_reg_write+0x80/0xb4
> [ee897ef0] [c00d3b7c] vfs_write+0xb4/0x184
>
> just as I had wanted. But now I need to trigger the "vfs_write" and "proc_reg_write" but without using call_usermodehelper since I will be doing it when root "/" is unavailable and so I can no longer access /bin/echo and call the usermodehelper etc. So my question is how can I do that in kernel?
>
> Not sure if I'm supposed to look in fs read_write.c and fs.h and write a method based on those or if there's some other way etc.
You don't say which proc file, which would be useful information.
I'll assume it's /proc/sysrq-trigger based on your previous mail.
Rather than trying to invoke the write path from inside the kernel, the
simplest option is to just call __handle_sysrq() directly.
cheers
More information about the Linuxppc-dev
mailing list