diff options
author | Eyal Birger <eyal.birger@gmail.com> | 2015-03-01 07:58:29 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-02 00:19:30 -0500 |
commit | b4772ef879a8f7d8c56118c2ae5a296fcf6f81d2 (patch) | |
tree | b4498c776c28e5c87cdeebf17577d002bcd21d47 | |
parent | 2472d7613bd3bae40a7dc75539c0858d5b9e795a (diff) |
net: use common macro for assering skb->cb[] available size in protocol families
As part of an effort to move skb->dropcount to skb->cb[] use a common
macro in protocol families using skb->cb[] for ancillary data to
validate available room in skb->cb[].
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/sock.h | 3 | ||||
-rw-r--r-- | net/bluetooth/af_bluetooth.c | 3 | ||||
-rw-r--r-- | net/can/bcm.c | 2 | ||||
-rw-r--r-- | net/can/raw.c | 6 | ||||
-rw-r--r-- | net/ipv4/af_inet.c | 2 | ||||
-rw-r--r-- | net/ipv4/tcp.c | 3 | ||||
-rw-r--r-- | net/ipv6/af_inet6.c | 2 | ||||
-rw-r--r-- | net/packet/af_packet.c | 3 | ||||
-rw-r--r-- | net/sctp/protocol.c | 3 |
9 files changed, 13 insertions, 14 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index ab186b1d31ff..a2502d248641 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -2078,6 +2078,9 @@ static inline int sock_intr_errno(long timeo) | |||
2078 | return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; | 2078 | return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; |
2079 | } | 2079 | } |
2080 | 2080 | ||
2081 | #define sock_skb_cb_check_size(size) \ | ||
2082 | BUILD_BUG_ON((size) > FIELD_SIZEOF(struct sk_buff, cb)) | ||
2083 | |||
2081 | void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, | 2084 | void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, |
2082 | struct sk_buff *skb); | 2085 | struct sk_buff *skb); |
2083 | void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk, | 2086 | void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk, |
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index ce22e0cfa923..4b904c97a068 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c | |||
@@ -711,10 +711,9 @@ EXPORT_SYMBOL_GPL(bt_debugfs); | |||
711 | 711 | ||
712 | static int __init bt_init(void) | 712 | static int __init bt_init(void) |
713 | { | 713 | { |
714 | struct sk_buff *skb; | ||
715 | int err; | 714 | int err; |
716 | 715 | ||
717 | BUILD_BUG_ON(sizeof(struct bt_skb_cb) > sizeof(skb->cb)); | 716 | sock_skb_cb_check_size(sizeof(struct bt_skb_cb)); |
718 | 717 | ||
719 | BT_INFO("Core ver %s", VERSION); | 718 | BT_INFO("Core ver %s", VERSION); |
720 | 719 | ||
diff --git a/net/can/bcm.c b/net/can/bcm.c index ee9ffd956552..d559f922326d 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c | |||
@@ -328,7 +328,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head, | |||
328 | * containing the interface index. | 328 | * containing the interface index. |
329 | */ | 329 | */ |
330 | 330 | ||
331 | BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can)); | 331 | sock_skb_cb_check_size(sizeof(struct sockaddr_can)); |
332 | addr = (struct sockaddr_can *)skb->cb; | 332 | addr = (struct sockaddr_can *)skb->cb; |
333 | memset(addr, 0, sizeof(*addr)); | 333 | memset(addr, 0, sizeof(*addr)); |
334 | addr->can_family = AF_CAN; | 334 | addr->can_family = AF_CAN; |
diff --git a/net/can/raw.c b/net/can/raw.c index 00c13ef23661..94601b7ff0a3 100644 --- a/net/can/raw.c +++ b/net/can/raw.c | |||
@@ -95,8 +95,8 @@ struct raw_sock { | |||
95 | */ | 95 | */ |
96 | static inline unsigned int *raw_flags(struct sk_buff *skb) | 96 | static inline unsigned int *raw_flags(struct sk_buff *skb) |
97 | { | 97 | { |
98 | BUILD_BUG_ON(sizeof(skb->cb) <= (sizeof(struct sockaddr_can) + | 98 | sock_skb_cb_check_size(sizeof(struct sockaddr_can) + |
99 | sizeof(unsigned int))); | 99 | sizeof(unsigned int)); |
100 | 100 | ||
101 | /* return pointer after struct sockaddr_can */ | 101 | /* return pointer after struct sockaddr_can */ |
102 | return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]); | 102 | return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]); |
@@ -135,7 +135,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data) | |||
135 | * containing the interface index. | 135 | * containing the interface index. |
136 | */ | 136 | */ |
137 | 137 | ||
138 | BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can)); | 138 | sock_skb_cb_check_size(sizeof(struct sockaddr_can)); |
139 | addr = (struct sockaddr_can *)skb->cb; | 139 | addr = (struct sockaddr_can *)skb->cb; |
140 | memset(addr, 0, sizeof(*addr)); | 140 | memset(addr, 0, sizeof(*addr)); |
141 | addr->can_family = AF_CAN; | 141 | addr->can_family = AF_CAN; |
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index d2e49baaff63..4ce954cc94a4 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c | |||
@@ -1675,7 +1675,7 @@ static int __init inet_init(void) | |||
1675 | struct list_head *r; | 1675 | struct list_head *r; |
1676 | int rc = -EINVAL; | 1676 | int rc = -EINVAL; |
1677 | 1677 | ||
1678 | BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb)); | 1678 | sock_skb_cb_check_size(sizeof(struct inet_skb_parm)); |
1679 | 1679 | ||
1680 | rc = proto_register(&tcp_prot, 1); | 1680 | rc = proto_register(&tcp_prot, 1); |
1681 | if (rc) | 1681 | if (rc) |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 9d72a0fcd928..4b57ea8dabc7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -3005,12 +3005,11 @@ static void __init tcp_init_mem(void) | |||
3005 | 3005 | ||
3006 | void __init tcp_init(void) | 3006 | void __init tcp_init(void) |
3007 | { | 3007 | { |
3008 | struct sk_buff *skb = NULL; | ||
3009 | unsigned long limit; | 3008 | unsigned long limit; |
3010 | int max_rshare, max_wshare, cnt; | 3009 | int max_rshare, max_wshare, cnt; |
3011 | unsigned int i; | 3010 | unsigned int i; |
3012 | 3011 | ||
3013 | BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); | 3012 | sock_skb_cb_check_size(sizeof(struct tcp_skb_cb)); |
3014 | 3013 | ||
3015 | percpu_counter_init(&tcp_sockets_allocated, 0, GFP_KERNEL); | 3014 | percpu_counter_init(&tcp_sockets_allocated, 0, GFP_KERNEL); |
3016 | percpu_counter_init(&tcp_orphan_count, 0, GFP_KERNEL); | 3015 | percpu_counter_init(&tcp_orphan_count, 0, GFP_KERNEL); |
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index e8c4400f23e9..6bafcc2c79e3 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c | |||
@@ -824,7 +824,7 @@ static int __init inet6_init(void) | |||
824 | struct list_head *r; | 824 | struct list_head *r; |
825 | int err = 0; | 825 | int err = 0; |
826 | 826 | ||
827 | BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb)); | 827 | sock_skb_cb_check_size(sizeof(struct inet6_skb_parm)); |
828 | 828 | ||
829 | /* Register the socket-side information for inet6_create. */ | 829 | /* Register the socket-side information for inet6_create. */ |
830 | for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r) | 830 | for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r) |
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 7eea30b9c8e5..9cdb414cd231 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -1816,8 +1816,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, | |||
1816 | skb = nskb; | 1816 | skb = nskb; |
1817 | } | 1817 | } |
1818 | 1818 | ||
1819 | BUILD_BUG_ON(sizeof(*PACKET_SKB_CB(skb)) + MAX_ADDR_LEN - 8 > | 1819 | sock_skb_cb_check_size(sizeof(*PACKET_SKB_CB(skb)) + MAX_ADDR_LEN - 8); |
1820 | sizeof(skb->cb)); | ||
1821 | 1820 | ||
1822 | sll = &PACKET_SKB_CB(skb)->sa.ll; | 1821 | sll = &PACKET_SKB_CB(skb)->sa.ll; |
1823 | sll->sll_hatype = dev->type; | 1822 | sll->sll_hatype = dev->type; |
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 8f34b27d5775..53b7acde9aa3 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c | |||
@@ -1322,8 +1322,7 @@ static __init int sctp_init(void) | |||
1322 | int max_share; | 1322 | int max_share; |
1323 | int order; | 1323 | int order; |
1324 | 1324 | ||
1325 | BUILD_BUG_ON(sizeof(struct sctp_ulpevent) > | 1325 | sock_skb_cb_check_size(sizeof(struct sctp_ulpevent)); |
1326 | sizeof(((struct sk_buff *) 0)->cb)); | ||
1327 | 1326 | ||
1328 | /* Allocate bind_bucket and chunk caches. */ | 1327 | /* Allocate bind_bucket and chunk caches. */ |
1329 | status = -ENOBUFS; | 1328 | status = -ENOBUFS; |