> On Mar 11, 2025, at 2:20 AM, Peter Skvarka <p...@softinengines.com> wrote:
> 
> Hello,
> I have created two sockets with socketpair() and one of them is put into 
> kernel module through ioctl.
> I need to work with passed socket in separate kernel thread.
> In my module ioctl handler I am able to retrieve file descriptor from user 
> mode descriptor (int user_sock) :
> file_fd = fd_getfile2(lewepe->l_proc, user_sock);
> and consequently pointer to socket structure:
> struct socket* so = file_fd->f_undata.fd_so;

Take a look at sys/kern/uipc_syscalls.c:do_sys_sendmsg().  That shows you the 
pattern of how to get the socket from the user file descriptor.  You can then 
use the socket directly in the kernel.  You will need to take an extra 
reference on the socket if you cache its pointer in the kernel.  That is left 
as an exercise for the reader.

-- thorpej

Reply via email to