提交 b4772ef8 编写于 作者: E Eyal Birger 提交者: David S. Miller

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: NEyal Birger <eyal.birger@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 2472d761
...@@ -2078,6 +2078,9 @@ static inline int sock_intr_errno(long timeo) ...@@ -2078,6 +2078,9 @@ static inline int sock_intr_errno(long timeo)
return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR; return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR;
} }
#define sock_skb_cb_check_size(size) \
BUILD_BUG_ON((size) > FIELD_SIZEOF(struct sk_buff, cb))
void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
struct sk_buff *skb); struct sk_buff *skb);
void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk, void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
......
...@@ -711,10 +711,9 @@ EXPORT_SYMBOL_GPL(bt_debugfs); ...@@ -711,10 +711,9 @@ EXPORT_SYMBOL_GPL(bt_debugfs);
static int __init bt_init(void) static int __init bt_init(void)
{ {
struct sk_buff *skb;
int err; int err;
BUILD_BUG_ON(sizeof(struct bt_skb_cb) > sizeof(skb->cb)); sock_skb_cb_check_size(sizeof(struct bt_skb_cb));
BT_INFO("Core ver %s", VERSION); BT_INFO("Core ver %s", VERSION);
......
...@@ -328,7 +328,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head, ...@@ -328,7 +328,7 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
* containing the interface index. * containing the interface index.
*/ */
BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can)); sock_skb_cb_check_size(sizeof(struct sockaddr_can));
addr = (struct sockaddr_can *)skb->cb; addr = (struct sockaddr_can *)skb->cb;
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
addr->can_family = AF_CAN; addr->can_family = AF_CAN;
......
...@@ -95,8 +95,8 @@ struct raw_sock { ...@@ -95,8 +95,8 @@ struct raw_sock {
*/ */
static inline unsigned int *raw_flags(struct sk_buff *skb) static inline unsigned int *raw_flags(struct sk_buff *skb)
{ {
BUILD_BUG_ON(sizeof(skb->cb) <= (sizeof(struct sockaddr_can) + sock_skb_cb_check_size(sizeof(struct sockaddr_can) +
sizeof(unsigned int))); sizeof(unsigned int));
/* return pointer after struct sockaddr_can */ /* return pointer after struct sockaddr_can */
return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]); return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]);
...@@ -135,7 +135,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data) ...@@ -135,7 +135,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
* containing the interface index. * containing the interface index.
*/ */
BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can)); sock_skb_cb_check_size(sizeof(struct sockaddr_can));
addr = (struct sockaddr_can *)skb->cb; addr = (struct sockaddr_can *)skb->cb;
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
addr->can_family = AF_CAN; addr->can_family = AF_CAN;
......
...@@ -1675,7 +1675,7 @@ static int __init inet_init(void) ...@@ -1675,7 +1675,7 @@ static int __init inet_init(void)
struct list_head *r; struct list_head *r;
int rc = -EINVAL; int rc = -EINVAL;
BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb)); sock_skb_cb_check_size(sizeof(struct inet_skb_parm));
rc = proto_register(&tcp_prot, 1); rc = proto_register(&tcp_prot, 1);
if (rc) if (rc)
......
...@@ -3005,12 +3005,11 @@ static void __init tcp_init_mem(void) ...@@ -3005,12 +3005,11 @@ static void __init tcp_init_mem(void)
void __init tcp_init(void) void __init tcp_init(void)
{ {
struct sk_buff *skb = NULL;
unsigned long limit; unsigned long limit;
int max_rshare, max_wshare, cnt; int max_rshare, max_wshare, cnt;
unsigned int i; unsigned int i;
BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); sock_skb_cb_check_size(sizeof(struct tcp_skb_cb));
percpu_counter_init(&tcp_sockets_allocated, 0, GFP_KERNEL); percpu_counter_init(&tcp_sockets_allocated, 0, GFP_KERNEL);
percpu_counter_init(&tcp_orphan_count, 0, GFP_KERNEL); percpu_counter_init(&tcp_orphan_count, 0, GFP_KERNEL);
......
...@@ -824,7 +824,7 @@ static int __init inet6_init(void) ...@@ -824,7 +824,7 @@ static int __init inet6_init(void)
struct list_head *r; struct list_head *r;
int err = 0; int err = 0;
BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb)); sock_skb_cb_check_size(sizeof(struct inet6_skb_parm));
/* Register the socket-side information for inet6_create. */ /* Register the socket-side information for inet6_create. */
for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r) for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
......
...@@ -1816,8 +1816,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -1816,8 +1816,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
skb = nskb; skb = nskb;
} }
BUILD_BUG_ON(sizeof(*PACKET_SKB_CB(skb)) + MAX_ADDR_LEN - 8 > sock_skb_cb_check_size(sizeof(*PACKET_SKB_CB(skb)) + MAX_ADDR_LEN - 8);
sizeof(skb->cb));
sll = &PACKET_SKB_CB(skb)->sa.ll; sll = &PACKET_SKB_CB(skb)->sa.ll;
sll->sll_hatype = dev->type; sll->sll_hatype = dev->type;
......
...@@ -1322,8 +1322,7 @@ static __init int sctp_init(void) ...@@ -1322,8 +1322,7 @@ static __init int sctp_init(void)
int max_share; int max_share;
int order; int order;
BUILD_BUG_ON(sizeof(struct sctp_ulpevent) > sock_skb_cb_check_size(sizeof(struct sctp_ulpevent));
sizeof(((struct sk_buff *) 0)->cb));
/* Allocate bind_bucket and chunk caches. */ /* Allocate bind_bucket and chunk caches. */
status = -ENOBUFS; status = -ENOBUFS;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册