net: remove unsafe skb_insert()
Subsystems (3)
PATCH 1/1 net: remove unsafe skb_insert()
I do not see how one can effectively use skb_insert() without holding some kind of lock. Otherwise other cpus could have changed the list right before we have a chance of acquiring list->lock.
Only existing user is in drivers/infiniband/hw/nes/nes_mgt.c and this one probably meant to use __skb_insert() since it appears nesqp->pau_list is protected by nesqp->pau_lock. This looks like nesqp->pau_lock could be removed, since nesqp->pau_list.lock could be used instead.
--- drivers/infiniband/hw/nes/nes_mgt.c | 4 ++-- include/linux/skbuff.h | 2 -- net/core/skbuff.c | 22 ---------------------- 3 files changed, 2 insertions(+), 26 deletions(-)
drivers/infiniband/hw/nes/nes_mgt.c +2 -2
@@ -551,14 +551,14 @@ static void queue_fpdus(struct sk_buff *skb, struct nes_vnic *nesvnic, struct ne/* Queue skb by sequence number */ if (skb_queue_len (&nesqp->pau_list) ==0 ) { -skb_queue_head (&nesqp->pau_list, skb); +__skb_queue_head (&nesqp->pau_list, skb); }else { skb_queue_walk(&nesqp->pau_list, tmpskb) { cb = (struct nes_rskb_cb *)&tmpskb->cb[0 ];if (before (seqnum, cb->seqnum))break ; } -skb_insert (tmpskb, skb, &nesqp->pau_list); +__skb_insert (tmpskb, skb, &nesqp->pau_list); }if (nesqp->pau_state ==PAU_READY ) process_it = true;
include/linux/skbuff.h +0 -2
@@ -1749,8 +1749,6 @@ static inline void skb_queue_head_init_class(struct sk_buff_head *list,* The "__skb_xxxx()" functions are the non-atomic ones that * can only be called with interrupts disabled. */ -void skb_insert (struct sk_buff *old,struct sk_buff *newsk, -struct sk_buff_head *list);static inline void __skb_insert (struct sk_buff *newsk,struct sk_buff *prev,struct sk_buff *next,struct sk_buff_head *list)
net/core/skbuff.c +0 -22
@@ -2990,28 +2990,6 @@ void skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head }EXPORT_SYMBOL (skb_append); -/** -* skb_insert - insert a buffer -* @old: buffer to insert before -* @newsk: buffer to insert -* @list: list to use -* -* Place a packet before a given packet in a list. The list locks are -* taken and this function is atomic with respect to other list locked -* calls. -* -* A buffer cannot be placed on two lists at the same time. -*/ -void skb_insert (struct sk_buff *old,struct sk_buff *newsk,struct sk_buff_head *list) -{ -unsigned long flags; - -spin_lock_irqsave (&list->lock, flags); -__skb_insert (newsk, old->prev, old, list); -spin_unlock_irqrestore (&list->lock, flags); -} -EXPORT_SYMBOL (skb_insert); -static inline void skb_split_inside_header (struct sk_buff *skb,struct sk_buff * skb1,const u32 len,const int pos)
Signature · 1 line
2.20.0.rc0.387.gc7a69e6b6c-goog
From: Eric Dumazet <[email protected]>
Date: Sun, 25 Nov 2018 08:26:23 -0800
Quoted 10 lines
I do not see how one can effectively use
skb_insert()without holding some kind of lock. Otherwise other cpus could have changed the list right before we have a chance of acquiringlist->lock.Only existing user is in
drivers/infiniband/hw/nes/nes_mgt.cand this one probably meant to use__skb_insert()since it appearsnesqp->pau_listis protected bynesqp->pau_lock. This looks likenesqp->pau_lockcould be removed, sincenesqp->pau_list.lockcould be used instead.Signed-off-by Eric Dumazet <[email protected]>
Good find.
Indeed, any of the queue SKB manipulation functions that take two SKBs as an argument are suspect in this manner.
Applied, thanks Eric.
kbuild test robot
build botI love your patch! Yet something to improve:
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Eric-Dumazet/net-remove-unsafe-skb_insert/20181126-061342
config: x86_64-randconfig-x009-201847 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All errors (new ones prefixed by >>):
drivers/infiniband//hw/nes/nes_mgt.c: In function 'queue_fpdus':
>> drivers/infiniband//hw/nes/nes_mgt.c:561:29: error: passing argument 3 of '__skb_insert' from incompatible pointer type [-Werror=incompatible-pointer-types]
__skb_insert(tmpskb, skb, &nesqp->pau_list);
^
In file included from drivers/infiniband//hw/nes/nes_mgt.c:34:0:
include/linux/skbuff.h:1752:20: note: expected 'struct sk_buff *' but argument is of type 'struct sk_buff_head *'
static inline void __skb_insert(struct sk_buff *newsk,
^~~~~~~~~~~~
>> drivers/infiniband//hw/nes/nes_mgt.c:561:3: error: too few arguments to function '__skb_insert'
__skb_insert(tmpskb, skb, &nesqp->pau_list);
^~~~~~~~~~~~ In file included from drivers/infiniband//hw/nes/nes_mgt.c:34:0:
include/linux/skbuff.h:1752:20: note: declared here
static inline void __skb_insert(struct sk_buff *newsk,
^~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/__skb_insert +561 drivers/infiniband//hw/nes/nes_mgt.c
503
504 /**
505 * queue_fpdus - Handle fpdu's that hw passed up to sw
506 */
507 static void queue_fpdus(struct sk_buff *skb, struct nes_vnic *nesvnic, struct nes_qp *nesqp)
508 {
509 struct sk_buff *tmpskb;
510 struct nes_rskb_cb *cb;
511 struct iphdr *iph;
512 struct tcphdr *tcph;
513 unsigned char *tcph_end;
514 u32 rcv_nxt;
515 u32 rcv_wnd;
516 u32 seqnum;
517 u32 len;
518 bool process_it = false;
519 unsigned long flags;
520
521 /* Move data ptr to after tcp header */
522 iph = (struct iphdr *)skb->data;
523 tcph = (struct tcphdr *)(((char *)iph) + (4 * iph->ihl));
524 seqnum = be32_to_cpu(tcph->seq);
525 tcph_end = (((char *)tcph) + (4 * tcph->doff));
526
527 len = be16_to_cpu(iph->tot_len);
528 if (skb->len > len)
529 skb_trim(skb, len);
530 skb_pull(skb, tcph_end - skb->data);
531
532 /* Initialize tracking values */
533 cb = (struct nes_rskb_cb *)&skb->cb[0];
534 cb->seqnum = seqnum;
535
536 /* Make sure data is in the receive window */
537 rcv_nxt = nesqp->pau_rcv_nxt;
538 rcv_wnd = le32_to_cpu(nesqp->nesqp_context->rcv_wnd);
539 if (!between(seqnum, rcv_nxt, (rcv_nxt + rcv_wnd))) {
540 nes_mgt_free_skb(nesvnic->nesdev, skb, PCI_DMA_TODEVICE);
541 nes_rem_ref_cm_node(nesqp->cm_node);
542 return;
543 }
544
545 spin_lock_irqsave(&nesqp->pau_lock, flags);
546
547 if (nesqp->pau_busy)
548 nesqp->pau_pending = 1;
549 else
550 nesqp->pau_busy = 1;
551
552 /* Queue skb by sequence number */
553 if (skb_queue_len(&nesqp->pau_list) == 0) {
554 __skb_queue_head(&nesqp->pau_list, skb);
555 } else {
556 skb_queue_walk(&nesqp->pau_list, tmpskb) {
557 cb = (struct nes_rskb_cb *)&tmpskb->cb[0];
558 if (before(seqnum, cb->seqnum))
559 break;
560 }
> 561 __skb_insert(tmpskb, skb, &nesqp->pau_list);
562 }
563 if (nesqp->pau_state == PAU_READY)
564 process_it = true;
565 spin_unlock_irqrestore(&nesqp->pau_lock, flags);
566
567 if (process_it)
568 process_fpdus(nesvnic, nesqp);
569
570 return;
571 }
572
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 13 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Sun, 25 Nov 2018 08:26:23 -0800Quoted 9 lines
I do not see how one can effectively use
skb_insert()without holding some kind of lock. Otherwise other cpus could have changed the list right before we have a chance of acquiringlist->lock.Only existing user is in
drivers/infiniband/hw/nes/nes_mgt.cand this one probably meant to use__skb_insert()since it appearsnesqp->pau_listis protected bynesqp->pau_lock. This looks likenesqp->pau_lockcould be removed, sincenesqp->pau_list.lockcould be used instead.
Quoted 8 lines
Quoted 1 line
Signed-off-by Eric Dumazet <[email protected]>Good find.
Indeed, any of the queue SKB manipulation functions that take two SKBs as an argument are suspect in this manner.
Applied, thanks Eric.
Oh well, this does not build.
Since you have not pushed your tree yet, maybe we can replace this with a version that actually compiles.
Please let me know if a relative patch or a v2 is needed, thanks.
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Sun, 25 Nov 2018 15:37:43 -0800
Quoted 21 lines · David Miller
Quoted 20 lines
From: Eric Dumazet <[email protected]>
Date: Sun, 25 Nov 2018 08:26:23 -0800Quoted 10 lines
I do not see how one can effectively use
skb_insert()without holding some kind of lock. Otherwise other cpus could have changed the list right before we have a chance of acquiringlist->lock.Only existing user is in
drivers/infiniband/hw/nes/nes_mgt.cand this one probably meant to use__skb_insert()since it appearsnesqp->pau_listis protected bynesqp->pau_lock. This looks likenesqp->pau_lockcould be removed, sincenesqp->pau_list.lockcould be used instead.Signed-off-by Eric Dumazet <[email protected]>Good find.
Indeed, any of the queue SKB manipulation functions that take two SKBs as an argument are suspect in this manner.
Quoted 8 lines
Quoted 1 line
Applied, thanks Eric.
Oh well, this does not build.
Since you have not pushed your tree yet, maybe we can replace this with a version that actually compiles.
Please let me know if a relative patch or a v2 is needed, thanks.
I fixed up the build in your original patch and am about to push that out.
Quoted 3 lines · David Miller
I fixed up the build in your original patch and am about to push that out.
Thanks David, sorry for this, I should have compiled the damn thing :/