Skip to content

Commit 58691e5

Browse files
wdebruijgregkh
authored andcommitted
net: introduce device min_header_len
[ Upstream commit 217e6fa24ce28ec87fca8da93c9016cb78028612 ] The stack must not pass packets to device drivers that are shorter than the minimum link layer header length. Previously, packet sockets would drop packets smaller than or equal to dev->hard_header_len, but this has false positives. Zero length payload is used over Ethernet. Other link layer protocols support variable length headers. Support for validation of these protocols removed the min length check for all protocols. Introduce an explicit dev->min_header_len parameter and drop all packets below this value. Initially, set it to non-zero only for Ethernet and loopback. Other protocols can follow in a patch to net-next. Fixes: 9ed988cd5915 ("packet: validate variable length ll headers") Reported-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Signed-off-by: Willem de Bruijn <willemb@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Acked-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6f99825 commit 58691e5

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/net/loopback.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static void loopback_setup(struct net_device *dev)
164164
{
165165
dev->mtu = 64 * 1024;
166166
dev->hard_header_len = ETH_HLEN; /* 14 */
167+
dev->min_header_len = ETH_HLEN; /* 14 */
167168
dev->addr_len = ETH_ALEN; /* 6 */
168169
dev->type = ARPHRD_LOOPBACK; /* 0x0001*/
169170
dev->flags = IFF_LOOPBACK;

include/linux/netdevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ enum netdev_priv_flags {
13991399
* @mtu: Interface MTU value
14001400
* @type: Interface hardware type
14011401
* @hard_header_len: Maximum hardware header length.
1402+
* @min_header_len: Minimum hardware header length
14021403
*
14031404
* @needed_headroom: Extra headroom the hardware may need, but not in all
14041405
* cases can this be guaranteed
@@ -1619,6 +1620,7 @@ struct net_device {
16191620
unsigned int mtu;
16201621
unsigned short type;
16211622
unsigned short hard_header_len;
1623+
unsigned short min_header_len;
16221624

16231625
unsigned short needed_headroom;
16241626
unsigned short needed_tailroom;
@@ -2541,6 +2543,8 @@ static inline bool dev_validate_header(const struct net_device *dev,
25412543
{
25422544
if (likely(len >= dev->hard_header_len))
25432545
return true;
2546+
if (len < dev->min_header_len)
2547+
return false;
25442548

25452549
if (capable(CAP_SYS_RAWIO)) {
25462550
memset(ll_header + len, 0, dev->hard_header_len - len);

net/ethernet/eth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ void ether_setup(struct net_device *dev)
353353
dev->header_ops = &eth_header_ops;
354354
dev->type = ARPHRD_ETHER;
355355
dev->hard_header_len = ETH_HLEN;
356+
dev->min_header_len = ETH_HLEN;
356357
dev->mtu = ETH_DATA_LEN;
357358
dev->addr_len = ETH_ALEN;
358359
dev->tx_queue_len = 1000; /* Ethernet wants good queues */

0 commit comments

Comments
 (0)