Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

linux device driver - How to find task_struct for a given sock in a kernel module?

Does anybody happen to know how I can (efficiently) get a struct task_struct for a given struct sock in a kernel module (i.e. the process that created a given network layer socket) ?

I apologise if I am missing the obvious, it may be due to the fact that I am rather new to kernel development. But I've been trying to find that link for days now. My biggest hope was to use sk->sk_socket->file->f_owner.pid. I could then have used f_getown() to get the pid and from there. But somehow this idea didn't work out, at least for an AF_INET type socket. From looking at the kernel code in __sock_socket() and called functions, it seemes the f_owner member is never pointed to current.

So I thought file->f_owner maybe shouldn't be used any more, but I didn't find any such information. Actually, during my search, I found that sock_ioctl() is using f_setown() and f_getown(). So file->f_owner doesn't seem to be obsolete. Which leads to my second question: If file->f_owner is not obsolete, why wouldn't it be set during socket creation ?

Since then, I have only been hitting dead ends. Any hint in the right direction would be much appreciated. - Many thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...