All of lore.kernel.org
 help / color / mirror / Atom feed
* adding 32 bit compatibility layer in custom kernel module
@ 2017-01-04  4:04 Pradeepa Kumar
  2017-01-04  5:37 ` Anish Kumar
       [not found] ` <210705.1483504806@turing-police.cc.vt.edu>
  0 siblings, 2 replies; 7+ messages in thread
From: Pradeepa Kumar @ 2017-01-04  4:04 UTC (permalink / raw)
  To: kernelnewbies

Hi experts

down votefavorite
<http://stackoverflow.com/questions/41455943/adding-32-bit-compatibility-layer-in-custom-kernel-module#>

in my 64 bit kernel, I have a custom kernel module providing new protocol
and providing socket system calls.

it works fine when 64 bit app runs.

i am seeing issues when 32 bit app runs (for exp recvmsg() call does not
work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit
and 64 bit).

This is because my custom kernel module does not have 32 bit compatibility
layer ( but linux kernel has this in compat.c etc).

   -

   is it simple to add compatibility layer to my custom kernel module
   -

   how do i do this (any links ?)

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170104/6f56f08e/attachment-0001.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* adding 32 bit compatibility layer in custom kernel module
  2017-01-04  4:04 adding 32 bit compatibility layer in custom kernel module Pradeepa Kumar
@ 2017-01-04  5:37 ` Anish Kumar
  2017-01-04  6:03   ` Pradeepa Kumar
       [not found] ` <210705.1483504806@turing-police.cc.vt.edu>
  1 sibling, 1 reply; 7+ messages in thread
From: Anish Kumar @ 2017-01-04  5:37 UTC (permalink / raw)
  To: kernelnewbies



> On Jan 3, 2017, at 8:04 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
> 
> Hi experts
> 
> down vote
> favorite
> in my 64 bit kernel, I have a custom kernel module providing new protocol and providing socket system calls.
> 
> it works fine when 64 bit app runs.
> 
> i am seeing issues when 32 bit app runs (for exp recvmsg() call does not work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit and 64 bit).
> 
> This is because my custom kernel module does not have 32 bit compatibility layer ( but linux kernel has this in compat.c etc).
> 
> is it simple to add compatibility layer to my custom kernel module
> 
> All you have to do is add compat_ioctl call to your driver.
> how do i do this (any links ?)
> 
> You can see many drivers supports compat call.
> Thanks
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170103/d2d8c9a1/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* adding 32 bit compatibility layer in custom kernel module
       [not found] ` <210705.1483504806@turing-police.cc.vt.edu>
@ 2017-01-04  5:39   ` Pradeepa Kumar
  0 siblings, 0 replies; 7+ messages in thread
From: Pradeepa Kumar @ 2017-01-04  5:39 UTC (permalink / raw)
  To: kernelnewbies

Thanks Valdis.
Yes ,  custom kernel module has struct proto_ops pointing to the routines
in the module.
my kernel module routines  do not cal any of linux provided socket* calls.
it gets data from different app and provide that data back to app calling
socket* APIs.

i understand linux kernel calls 32 bit version of syscall handler from sys
call table .
https://kernel.org/doc/html/latest/process/adding-syscalls.html

but how do i do this in custom kernel module.
how to differentiate 32 bit and 64 app in my kernel module.

do i need all stuff from compat.h and compat.c (if i use same files will
 that work) ?
do i need to change some files in std kernel files too like syscall_32.tbl
file , and recompile kernel ?

It would be great if there is any example / any web links for this to
understad
Thanks




On Wed, Jan 4, 2017 at 10:10 AM, <Valdis.Kletnieks@vt.edu> wrote:

> On Wed, 04 Jan 2017 09:34:58 +0530, Pradeepa Kumar said:
>
> >  I have a custom kernel module providing new protocol and providing
> socket system calls.
>
> In general, a loadable module can provide a new protocol, but can't add new
> syscalls.  However, adding support for socket(), connect(), recvmsg() and
> so on for a new protocol *can* be done from a module, as long as the
> protocol provides a suitable struct proto_ops pointing to the routines
> in the module.
>
> > i am seeing issues when 32 bit app runs (for exp recvmsg() call does not
> > work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit
> > and 64 bit).
>
> That's a good reason to double-check your code to ensure that you don't
> make that same mistake.
>
> > This is because my custom kernel module does not have 32 bit
> compatibility
> > layer ( but linux kernel has this in compat.c etc).
>
> Hold that thought.
>
> >    is it simple to add compatibility layer to my custom kernel module
>
> Given your previous sentence, you should be able to figure that out.
>
> >    how do i do this (any links ?)
>
> /*
>  *  linux/kernel/compat.c
>  *
>  *  Kernel compatibililty routines for e.g. 32 bit syscall support
>  *  on 64 bit kernels.
>  *
>  *  Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation
>
> May already have the functions you need.  If not, use the code as a guide
> to writing the stuff you're still lacking.
>
> Note that in particular, recvmsg() combatability is already done for you
> via
> this chunk of code in net/compat.c:
>
> COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *,
> msg, unsigned int, flags)
> {
>         return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags |
> MSG_CMSG_COMPAT);
> }
>
> Go look and see what the MSG_CMSG_COMPAT flag does if you want the gory
> details.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170104/5d3700e8/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* adding 32 bit compatibility layer in custom kernel module
  2017-01-04  5:37 ` Anish Kumar
@ 2017-01-04  6:03   ` Pradeepa Kumar
  2017-01-04  6:48     ` Anish Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: Pradeepa Kumar @ 2017-01-04  6:03 UTC (permalink / raw)
  To: kernelnewbies

Please see inline below

On Wed, Jan 4, 2017 at 11:07 AM, Anish Kumar <anish198519851985@gmail.com>
wrote:

>
>
> On Jan 3, 2017, at 8:04 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
>
> Hi experts
>
> down votefavorite
> <http://stackoverflow.com/questions/41455943/adding-32-bit-compatibility-layer-in-custom-kernel-module#>
>
> in my 64 bit kernel, I have a custom kernel module providing new protocol
> and providing socket system calls.
>
> it works fine when 64 bit app runs.
>
> i am seeing issues when 32 bit app runs (for exp recvmsg() call does not
> work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit
> and 64 bit).
>
> This is because my custom kernel module does not have 32 bit compatibility
> layer ( but linux kernel has this in compat.c etc).
>
>    -
>
>    is it simple to add compatibility layer to my custom kernel module
>
>
>    All you have to do is add compat_ioctl call to your driver.
>
> my kernel module provides recvmsg() but i dont see any 'compat_recvmsg' in
struct proto_ops.
had there been  'compat_recvmsg' it would have been possible for me to
define recvmsg() for 32 bit apps.
please let me know if i am missing anything


>    -
>
>    how do i do this (any links ?)
>
>
>    You can see many drivers supports compat call.
>
> Thanks
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170104/e6680e3c/attachment-0001.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* adding 32 bit compatibility layer in custom kernel module
  2017-01-04  6:03   ` Pradeepa Kumar
@ 2017-01-04  6:48     ` Anish Kumar
  2017-01-04  6:59       ` Pradeepa Kumar
  0 siblings, 1 reply; 7+ messages in thread
From: Anish Kumar @ 2017-01-04  6:48 UTC (permalink / raw)
  To: kernelnewbies



> On Jan 3, 2017, at 10:03 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
> 
> Please see inline below
> 
>> On Wed, Jan 4, 2017 at 11:07 AM, Anish Kumar <anish198519851985@gmail.com> wrote:
>> 
>> 
>>> On Jan 3, 2017, at 8:04 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
>>> 
>>> Hi experts
>>> 
>>> down vote
>>> favorite
>>> in my 64 bit kernel, I have a custom kernel module providing new protocol and providing socket system calls.
>>> 
>>> it works fine when 64 bit app runs.
>>> 
>>> i am seeing issues when 32 bit app runs (for exp recvmsg() call does not work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit and 64 bit).
>>> 
>>> This is because my custom kernel module does not have 32 bit compatibility layer ( but linux kernel has this in compat.c etc).
>>> 
>>> is it simple to add compatibility layer to my custom kernel module
>>> 
>>> All you have to do is add compat_ioctl call to your driver.
> my kernel module provides recvmsg() but i dont see any 'compat_recvmsg' in struct proto_ops.

Try to wrap your text in 80 characters.

Your application is crashing? Right?
Have you figured where it is crashing exactly?

I understood that your application is crashing as 
It not able to function with 64 bit kernel.

This happens because of the data being passed
to kernel is not in the right format. You need to
look at what you are passing to the driver and
if needed write the compat_ioctl callback in your
driver fops.
> had there been  'compat_recvmsg' it would have been possible for me to define recvmsg() for 32 bit apps.
> please let me know if i am missing anything
> 
>>> how do i do this (any links ?)
>>> 
>>> You can see many drivers supports compat call.
>>> Thanks
>>> 
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170103/06ce4f46/attachment-0001.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* adding 32 bit compatibility layer in custom kernel module
  2017-01-04  6:48     ` Anish Kumar
@ 2017-01-04  6:59       ` Pradeepa Kumar
  2017-01-04  7:26         ` anish singh
  0 siblings, 1 reply; 7+ messages in thread
From: Pradeepa Kumar @ 2017-01-04  6:59 UTC (permalink / raw)
  To: kernelnewbies

my app is crashing as it is trying iterate cmsghdrs
it got after call to recvmsg();
To give some context
below is the flow

32 bit app  <--> my kernel module <--> 64 bit app
my kernel module implements new protocol and
provides 'struct proto_ops'
it never calls __sys_socket* calls.
once 32 bit app calls recvmsg(),
kernel module gets required data from another 64 bit app
via netlink msg.
issue here is the struct msghdr and strcu cmsgdr sizes
and members are of different lenghts.
so kernel module needs to give data to 32 bit app
in proper struct which are of correct sizes in 32 bit mode.
so kernel module needs a way to figure out
it is 32 bit app that made recvmsg() call and process accordingly.
i dont see compat_recv in struct proto_ops



On Wed, Jan 4, 2017 at 12:18 PM, Anish Kumar <anish198519851985@gmail.com>
wrote:

>
>
> On Jan 3, 2017, at 10:03 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
>
> Please see inline below
>
> On Wed, Jan 4, 2017 at 11:07 AM, Anish Kumar <anish198519851985@gmail.com>
> wrote:
>
>>
>>
>> On Jan 3, 2017, at 8:04 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
>>
>> Hi experts
>>
>> down votefavorite
>> <http://stackoverflow.com/questions/41455943/adding-32-bit-compatibility-layer-in-custom-kernel-module#>
>>
>> in my 64 bit kernel, I have a custom kernel module providing new protocol
>> and providing socket system calls.
>>
>> it works fine when 64 bit app runs.
>>
>> i am seeing issues when 32 bit app runs (for exp recvmsg() call does not
>> work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit
>> and 64 bit).
>>
>> This is because my custom kernel module does not have 32 bit
>> compatibility layer ( but linux kernel has this in compat.c etc).
>>
>>    -
>>
>>    is it simple to add compatibility layer to my custom kernel module
>>
>>
>>    All you have to do is add compat_ioctl call to your driver.
>>
>> my kernel module provides recvmsg() but i dont see any 'compat_recvmsg'
> in struct proto_ops.
>
>
> Try to wrap your text in 80 characters.
>
> Your application is crashing? Right?
> Have you figured where it is crashing exactly?
>
> I understood that your application is crashing as
> It not able to function with 64 bit kernel.
>
> This happens because of the data being passed
> to kernel is not in the right format. You need to
> look at what you are passing to the driver and
> if needed write the compat_ioctl callback in your
> driver fops.
>
> had there been  'compat_recvmsg' it would have been possible for me to
> define recvmsg() for 32 bit apps.
> please let me know if i am missing anything
>
>
>>    -
>>
>>    how do i do this (any links ?)
>>
>>
>>    You can see many drivers supports compat call.
>>
>> Thanks
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170104/162a3ac6/attachment.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* adding 32 bit compatibility layer in custom kernel module
  2017-01-04  6:59       ` Pradeepa Kumar
@ 2017-01-04  7:26         ` anish singh
  0 siblings, 0 replies; 7+ messages in thread
From: anish singh @ 2017-01-04  7:26 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Jan 3, 2017 at 10:59 PM, Pradeepa Kumar <cdpradeepa@gmail.com>
wrote:

> my app is crashing as it is trying iterate cmsghdrs
> it got after call to recvmsg();
> To give some context
> below is the flow
>
> 32 bit app  <--> my kernel module <--> 64 bit app
> my kernel module implements new protocol and
> provides 'struct proto_ops'
> it never calls __sys_socket* calls.
> once 32 bit app calls recvmsg(),
> kernel module gets required data from another 64 bit app
> via netlink msg.
> issue here is the struct msghdr and strcu cmsgdr sizes
> and members are of different lenghts.
> so kernel module needs to give data to 32 bit app
> in proper struct which are of correct sizes in 32 bit mode.
> so kernel module needs a way to figure out
> it is 32 bit app that made recvmsg() call and process accordingly.
> i dont see compat_recv in struct proto_ops
>

Don't top post.
I suggest sending mail to netdev kernel mailing list
with all the relevant information as I doubt if networking
layer in kernel doesn't handle 32/64 bit properly.

>
>
>
> On Wed, Jan 4, 2017 at 12:18 PM, Anish Kumar <anish198519851985@gmail.com>
> wrote:
>
>>
>>
>> On Jan 3, 2017, at 10:03 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
>>
>> Please see inline below
>>
>> On Wed, Jan 4, 2017 at 11:07 AM, Anish Kumar <anish198519851985@gmail.com
>> > wrote:
>>
>>>
>>>
>>> On Jan 3, 2017, at 8:04 PM, Pradeepa Kumar <cdpradeepa@gmail.com> wrote:
>>>
>>> Hi experts
>>>
>>> down votefavorite
>>> <http://stackoverflow.com/questions/41455943/adding-32-bit-compatibility-layer-in-custom-kernel-module#>
>>>
>>> in my 64 bit kernel, I have a custom kernel module providing new
>>> protocol and providing socket system calls.
>>>
>>> it works fine when 64 bit app runs.
>>>
>>> i am seeing issues when 32 bit app runs (for exp recvmsg() call does not
>>> work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit
>>> and 64 bit).
>>>
>>> This is because my custom kernel module does not have 32 bit
>>> compatibility layer ( but linux kernel has this in compat.c etc).
>>>
>>>    -
>>>
>>>    is it simple to add compatibility layer to my custom kernel module
>>>
>>>
>>>    All you have to do is add compat_ioctl call to your driver.
>>>
>>> my kernel module provides recvmsg() but i dont see any 'compat_recvmsg'
>> in struct proto_ops.
>>
>>
>> Try to wrap your text in 80 characters.
>>
>> Your application is crashing? Right?
>> Have you figured where it is crashing exactly?
>>
>> I understood that your application is crashing as
>> It not able to function with 64 bit kernel.
>>
>> This happens because of the data being passed
>> to kernel is not in the right format. You need to
>> look at what you are passing to the driver and
>> if needed write the compat_ioctl callback in your
>> driver fops.
>>
>> had there been  'compat_recvmsg' it would have been possible for me to
>> define recvmsg() for 32 bit apps.
>> please let me know if i am missing anything
>>
>>
>>>    -
>>>
>>>    how do i do this (any links ?)
>>>
>>>
>>>    You can see many drivers supports compat call.
>>>
>>> Thanks
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170103/b94db475/attachment-0001.html 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-01-04  7:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-04  4:04 adding 32 bit compatibility layer in custom kernel module Pradeepa Kumar
2017-01-04  5:37 ` Anish Kumar
2017-01-04  6:03   ` Pradeepa Kumar
2017-01-04  6:48     ` Anish Kumar
2017-01-04  6:59       ` Pradeepa Kumar
2017-01-04  7:26         ` anish singh
     [not found] ` <210705.1483504806@turing-police.cc.vt.edu>
2017-01-04  5:39   ` Pradeepa Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.