Re: Associating driver to the existing device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/31/05, Vishal Linux <vishal.linux@xxxxxxxxx> wrote:
> 
> 
> On 5/30/05, Tyler <tyler@xxxxxxxx> wrote:
> > Vishal Linux a écrit :
> > > Hi all,
> > >
> > Hi
> > > I am trying to associate a driver to the '/dev/mem' device (the major
> > > no. and minor no. of device is 1,1.)
> > >
> > > [vishal@vishalsoni ~]$ ll /dev/mem 
> > > crw-r----- 1 root kmem 1, 1 May 30 2005 /dev/mem
> > >
> > Don't use 1 as major number. It's probably used by another driver (null
> > driver on my computer).
> > Try to allocate dynamically a major number or get one that is not used. 
> 
>  This is actually, what i don't intend to do... i want to associate my
> driver to /dev/mem device.. so that any read/write/mmap done to this
> device.. give control to my driver.
>  
> > I think that's the problem. So when you open the /dev/mem device, in
> > fact it doesn't use "your open" method but another. 
> 
>  Yeah , it should give  an error then, which i am not getting..
>  as my device registration is successful.

I think kernel registeration function should give an error if we are
trying to register the driver for a device for which already a driver
exists, else anybody can change the drivers by inserting there module
and can put the system at risk. As Arjan also mentioned in his mail
eralier that this is the probable approach for rootkits.

The problem I find with your module initialization is that you are
directly calling cdev_add() function without calling
register_chrdev_region() function before it.

As described in LDD3 in chapter 3, driver first need to get the majo
number allocated from kernel using kernel function
register_chrdev_region() and then only it should register its cdev
structure with kernel using kernel function cdev_add()

So you need to first request major number 1 from kernel with function
register_chrdev_region() and then only later you should register your
cdev structure to kernel and if you do so I think kernel will give you
an error when you request for major number 1 as for that device
already a driver is registered.

-Gaurav

>  
> 
>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux