Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6369123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:45:45+00:00 2026-05-25T00:45:45+00:00

I wrote kernel module which do nf_register_hook and use character device mechanism to get

  • 0

I wrote kernel module which do nf_register_hook and use character device mechanism to get grabbed packets to userspace with device read hooking. I use global buffer and buffersize vars that’s why i need to lock it when new packet comes or user reading my device.
I used splinlock_irqsave and spin_unlock_irqrestore(&locker,flags) but my module went into deadlock and system freezes.

unsigned int main_hook(unsigned int hooknum, struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
int(*okfn)(struct sk_buff*)) {
unsigned long flags;
spin_lock_irqsave(&locker,flags);
...
spin_unlock_irqrestore(&locker,flags);
}

ssize_t sniffer_dev_read(struct file *filep, char *buff, size_t count, loff_t *offp) {
spin_lock_irqsave(&locker,flags);
...
spin_unlock_irqrestore(&locker,flags);
}

main_hook is registered in nf_register_hook()
sniffer_dev_read is registered in register_chrdev

when the user read from device, system go to deadlock.
ideas?
or may be irq save/restore incompatible with netfiler hook/char device read and i must use special locking here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:45:46+00:00Added an answer on May 25, 2026 at 12:45 am

    First, you should recompile your kernel with the lock debugging options enabled and try it again. They can help point to the cause.

    There are several possible causes for a deadlock in spin_lock_irqsave. It could be recursive locking (that is, you are trying to call spin_lock_* again within the section of code where you hold the spin lock locked). It could be that you are sleeping with the spin lock locked (do not do this ever – for each function you call with the lock held, you must known whether it can sleep or not). It could be an AB/BA deadlock (one part of the code locks A first and then B; another part locks B first then A; if the first part locked A but not B and the second part locked B but not A you have a deadlock). And so on. The lock debugging options can detect and warn you about many of these.

    Since what you are locking is a “global buffer and buffersize vars”, try to reduce the locked area to a minimum. Instead of locking at the top of the function and unlocking at the end, do as much as possible outside the lock and lock only while manipulating your buffer. Ideally, the locked section would be just a few instructions with no function calls. It is much harder to deadlock in that case.


    Now that I said all that, my attempt at psychic debugging (i.e. guessing where the problem is): you are calling copy_to_user (which can sleep) with the spin lock held.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dealing with a problem in a kernel module that get data from userspace
I wrote a kernel module and a user that opens it with O_RDWR mode,
I need to write a kernel module that is not a device driver. That
I am using Ubuntu-11.04 OS. i wrote a basic interactive kernel module mid.c #include<linux/kernel.h>
I'm trying to write a kernel module, which prints some information about the objects
This situation always bother me: I wrote a kernel module, and sometimes it has
I am new to linux kernel programming. I wrote a simple kernel module and
I have written a kernel module which reads and writes /proc files, and it
I have a main kernel module with which other kernel modules communicate. I have
I wrote a windows service using VB that read some legacy data from Visual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.