lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20100105220553.GE30921@redhat.com>
Date:	Wed, 6 Jan 2010 00:05:53 +0200
From:	"Michael S. Tsirkin" <mst@...hat.com>
To:	David Miller <davem@...emloft.net>
Cc:	cfriesen@...tel.com, eric.dumazet@...il.com, nhorman@...driver.com,
	linux-kernel@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH] net: packet: option to only pass skb protocol

On Tue, Jan 05, 2010 at 11:45:24PM +0200, Michael S. Tsirkin wrote:
> On Tue, Jan 05, 2010 at 01:42:18PM -0800, David Miller wrote:
> > From: "Chris Friesen" <cfriesen@...tel.com>
> > Date: Tue, 05 Jan 2010 15:28:22 -0600
> > 
> > > On 01/05/2010 12:57 PM, Michael S. Tsirkin wrote:
> > >> When sending packets with a packet socket it is often necessary to set
> > >> protocol in msg_name: otherwise the protocol field in the skb will not
> > >> be set correctly.
> > > 
> > > What about automatically detecting the protocol from the data being sent
> > > to avoid the necessity of specifying it in the first place?
> > 
> > This limits packet socket usage to only protocols the kernel is aware
> > of, defeating part of the usefulness of the packet socket facility.
> 
> We could do this if the protocol is ETH_P_ALL -  skbs end up with this
> protocol currently when sendmsg does not have msgname and when socket is
> set up to listen for all packets.  It's not a valid protocol value, is
> it?

Something like this (if we want to support this for all device types,
we would probably need to add get_proto callback to net_device_ops),
and call it instead of eth_hdr(skb)->h_proto.

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index a81dae8..a23d4b2 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -845,7 +845,6 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 
 	ph.raw = frame;
 
-	skb->protocol = proto;
 	skb->dev = dev;
 	skb->priority = po->sk.sk_priority;
 	skb->mark = po->sk.sk_mark;
@@ -924,6 +923,11 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 		len = ((to_write > len_max) ? len_max : to_write);
 	}
 
+	if (proto == htons(ETH_P_ALL) && dev->type == ARPHRD_ETHER)
+		skb->protocol = eth_hdr(skb)->h_proto;
+	else
+		skb->protocol = proto;
+
 	return tp_len;
 }
 
@@ -1113,7 +1117,10 @@ static int packet_snd(struct socket *sock,
 	if (err)
 		goto out_free;
 
-	skb->protocol = proto;
+	if (proto == htons(ETH_P_ALL) && dev->type == ARPHRD_ETHER)
+		skb->protocol = eth_hdr(skb)->h_proto;
+	else
+		skb->protocol = proto;
 	skb->dev = dev;
 	skb->priority = sk->sk_priority;
 	skb->mark = sk->sk_mark;
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ