Getting 'bad file number' error writing to device driver

Daniel Baluta daniel.baluta at gmail.com
Mon Oct 17 11:59:41 EDT 2011


On Mon, Oct 17, 2011 at 6:49 PM, Philip Anil-QBW348
<anil.philip at motorolasolutions.com> wrote:
> -----Original Message-----
> From: Daniel Baluta [mailto:daniel.baluta at gmail.com]
> Sent: Saturday, October 15, 2011 3:34 AM
> To: Philip Anil-QBW348
> Cc: kernelnewbies at kernelnewbies.org
> Subject: Re: Getting 'bad file number' error writing to device driver
>
> On Sat, Oct 15, 2011 at 2:42 AM, Philip Anil-QBW348
> <anil.philip at motorolasolutions.com> wrote:
>> I am calling the driver from an Android program (OMAP4/Blaze). It calls a
>> c++ program via JNI which then calls the device driver.
>> Someone suggested it might be a permissions problem - the program is running
>> in user mode.
>>
>> on Blaze board, /system/bin
>> # ls -l
>> -rwxrwxrwx system   system       7636 2011-09-30 03:53 mydriver
>>
>> Will strace still be useful?
>> In general, in Linux, how does one enable a user program to call a custom
>> device driver?
>
> Please don't top post! :)
>
> strace will be useful to check the parameters for open, write system calls.
>
> EBADF  fd is not a valid file descriptor or is not open for writing.
> Ok, so either open fails, or you don't have the permission to write
> into /dev/mydriver file.
>
> ------
> I apologize for 'top-posting' (I did not know that was undesirable - most email clients and also Google newsgroups put one's reply at the top.).
> Yes, the /dev/mydriver had permissions 600. I did a chmod to 666 and it worked.
> I am performing security testing and want to see if a program running in user mode can elevate its privileges to call the device driver which has permissions 600.
> Any ideas how it can?
> Anil

Maybe setuid bit can help you ([1]). When this bit is set, a certain program
can run with the privileges of its owner.

thanks,
Daniel.

[1] http://en.wikipedia.org/wiki/Setuid



More information about the Kernelnewbies mailing list