0

I doubt it but in the kernel code, can I get the file name for an fd(file descriptor) that was passed by a syscall?
In a situation, I get syscall from user space and in do_el0_svc(struct pt_regs *regs) function (arch/arm64/kernel/syscall.c, linux-5.10.0-rc5), I can print the fd value which is in x0. But can I know the file name from the fd value? The syscall list for arm64 is here with number and function, arguments.

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • Why not solving it in a library with LD_PRELOAD? It seems you are just debugging and not using the fd in kernel, right? – Giacomo Catenazzi Sep 08 '22 at 10:29
  • *"I doubt it"* - why? if anyone has this information it's the kernel :') a bit of googling yields this which you may find useful: https://gist.github.com/larytet/f870e2ca5607876e24b529705e9cdb1b – Marco Bonelli Sep 08 '22 at 10:39
  • @GiacomoCatenazzi How can I use LD_PRELOAD? (I guess by replacing the function using a .so file?) But I forgot to mention that my board doesn't boot to the shell and this problem is arising while starting /bin/sh of busybox.. – Chan Kim Sep 08 '22 at 11:15
  • @MarcoBonelli that seems nice. I was following from the busybox side but I could try that method. (I'm about to go out on a 4-day long holiday in Korea, so after that.. ) thanks. – Chan Kim Sep 08 '22 at 11:18
  • @ChanKim can't use `LD_PRELOAD` in your environment, that's an environment variable used by the dynamic loader, which you do not have as you are working with busybox. See https://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick – Marco Bonelli Sep 08 '22 at 12:38
  • 2
    From the file descriptor you could obtain `struct fd` object using `fdget_pos()` function. Field `file` of that object is a `struct file` representing a file. [That question](https://stackoverflow.com/questions/17885676/in-linux-how-can-i-get-the-filename-from-the-struct-file-structure-while-ste) and its answers describe how to get name of the file from `struct file` object. – Tsyvarev Sep 08 '22 at 13:05

0 Answers0