netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems
@ 2009-08-10 17:03 cndougla
  2009-08-10 17:17 ` Patrick McHardy
  2009-08-11  1:06 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: cndougla @ 2009-08-10 17:03 UTC (permalink / raw)
  To: netdev

PACKET_MMAP sets up a ring buffer at a memory location so that kernel  
and user space can read from it without extra overhead. However, the  
data is written with a header, struct tpacket_hdr, which begins with  
an unsigned long field, tp_status. This means in a split 64-bit/32-bit  
environment the kernel- and user-space reads from the mmap'd region  
will be different, since in kernel-space the field is 64-bit while in  
user-space the field is 32-bit.

The following patch makes the size of the structure constant by  
changing the tp_status field to 32-bits. It does not appear to need  
64-bits, since only 4-bits are actually used throughout the AF_PACKET  
code.

Signed-off-by: Chase Douglas <cndougla@linux.vnet.ibm.com>
--- a/include/linux/if_packet.h   2009-08-10 16:53:11.000000000 +0000
+++ b/include/linux/if_packet.h   2009-08-10 16:53:28.000000000 +0000
@@ -65,7 +65,7 @@ struct tpacket_auxdata

  struct tpacket_hdr
  {
-       unsigned long   tp_status;
+       unsigned int    tp_status;
  #define TP_STATUS_KERNEL       0
  #define TP_STATUS_USER         1
  #define TP_STATUS_COPY         2


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

* Re: [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems
  2009-08-10 17:03 [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems cndougla
@ 2009-08-10 17:17 ` Patrick McHardy
  2009-08-10 18:52   ` Chase Douglas
  2009-08-11  1:06 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Patrick McHardy @ 2009-08-10 17:17 UTC (permalink / raw)
  To: cndougla; +Cc: netdev

cndougla@linux.vnet.ibm.com wrote:
> PACKET_MMAP sets up a ring buffer at a memory location so that kernel
> and user space can read from it without extra overhead. However, the
> data is written with a header, struct tpacket_hdr, which begins with an
> unsigned long field, tp_status. This means in a split 64-bit/32-bit
> environment the kernel- and user-space reads from the mmap'd region will
> be different, since in kernel-space the field is 64-bit while in
> user-space the field is 32-bit.
> 
> The following patch makes the size of the structure constant by changing
> the tp_status field to 32-bits. It does not appear to need 64-bits,
> since only 4-bits are actually used throughout the AF_PACKET code.
> 
> Signed-off-by: Chase Douglas <cndougla@linux.vnet.ibm.com>
> --- a/include/linux/if_packet.h   2009-08-10 16:53:11.000000000 +0000
> +++ b/include/linux/if_packet.h   2009-08-10 16:53:28.000000000 +0000
> @@ -65,7 +65,7 @@ struct tpacket_auxdata
> 
>  struct tpacket_hdr
>  {
> -       unsigned long   tp_status;
> +       unsigned int    tp_status;

This changes the layout on 64 bit and thus breaks compatibility.
The tpacket2_hdr doesn't suffer from this problem.

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

* Re: [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems
  2009-08-10 17:17 ` Patrick McHardy
@ 2009-08-10 18:52   ` Chase Douglas
  0 siblings, 0 replies; 4+ messages in thread
From: Chase Douglas @ 2009-08-10 18:52 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netdev

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

On Aug 10, 2009, at 1:17 PM, Patrick McHardy wrote:
> The tpacket2_hdr doesn't suffer from this problem.

I hadn't noticed the new header version. I've grabbed the latest  
version of libpcap which utilizes tpacket2_hdr where available, and  
everything is fixed again.

Thanks

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3892 bytes --]

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

* Re: [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems
  2009-08-10 17:03 [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems cndougla
  2009-08-10 17:17 ` Patrick McHardy
@ 2009-08-11  1:06 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2009-08-11  1:06 UTC (permalink / raw)
  To: cndougla; +Cc: netdev


You can't make that change without breaking all existing
64-bit binaries running on 64-bit kernels.

Secondarily, we're already fully aware of this problem, that's why
there is a second version of the data structure named tpacket2_hdr
which was created in a way which fixes the problem without breaking
existing setups.

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

end of thread, other threads:[~2009-08-11  1:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-10 17:03 [PATCH] AF_PACKET: Fix PACKET_MMAP on 64-bit kernel/32-bit user systems cndougla
2009-08-10 17:17 ` Patrick McHardy
2009-08-10 18:52   ` Chase Douglas
2009-08-11  1:06 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).