Skip to content

Commit b774134

Browse files
Hoang Lekuba-moo
authored andcommitted
tipc: fix NULL deref in tipc_link_xmit()
The buffer list can have zero skb as following path: tipc_named_node_up()->tipc_node_xmit()->tipc_link_xmit(), so we need to check the list before casting an &sk_buff. Fault report: [] tipc: Bulk publication failure [] general protection fault, probably for non-canonical [#1] PREEMPT [...] [] KASAN: null-ptr-deref in range [0x00000000000000c8-0x00000000000000cf] [] CPU: 0 PID: 0 Comm: swapper/0 Kdump: loaded Not tainted 5.10.0-rc4+ #2 [] Hardware name: Bochs ..., BIOS Bochs 01/01/2011 [] RIP: 0010:tipc_link_xmit+0xc1/0x2180 [] Code: 24 b8 00 00 00 00 4d 39 ec 4c 0f 44 e8 e8 d7 0a 10 f9 48 [...] [] RSP: 0018:ffffc90000006ea0 EFLAGS: 00010202 [] RAX: dffffc0000000000 RBX: ffff8880224da000 RCX: 1ffff11003d3cc0d [] RDX: 0000000000000019 RSI: ffffffff886007b9 RDI: 00000000000000c8 [] RBP: ffffc90000007018 R08: 0000000000000001 R09: fffff52000000ded [] R10: 0000000000000003 R11: fffff52000000dec R12: ffffc90000007148 [] R13: 0000000000000000 R14: 0000000000000000 R15: ffffc90000007018 [] FS: 0000000000000000(0000) GS:ffff888037400000(0000) knlGS:000[...] [] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [] CR2: 00007fffd2db5000 CR3: 000000002b08f000 CR4: 00000000000006f0 Fixes: af9b028 ("tipc: make media xmit call outside node spinlock context") Acked-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au> Link: https://lore.kernel.org/r/20210108071337.3598-1-hoang.h.le@dektech.com.au Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3502bd9 commit b774134

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

net/tipc/link.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,21 +1030,25 @@ void tipc_link_reset(struct tipc_link *l)
10301030
int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
10311031
struct sk_buff_head *xmitq)
10321032
{
1033-
struct tipc_msg *hdr = buf_msg(skb_peek(list));
10341033
struct sk_buff_head *backlogq = &l->backlogq;
10351034
struct sk_buff_head *transmq = &l->transmq;
10361035
struct sk_buff *skb, *_skb;
10371036
u16 bc_ack = l->bc_rcvlink->rcv_nxt - 1;
10381037
u16 ack = l->rcv_nxt - 1;
10391038
u16 seqno = l->snd_nxt;
10401039
int pkt_cnt = skb_queue_len(list);
1041-
int imp = msg_importance(hdr);
10421040
unsigned int mss = tipc_link_mss(l);
10431041
unsigned int cwin = l->window;
10441042
unsigned int mtu = l->mtu;
1043+
struct tipc_msg *hdr;
10451044
bool new_bundle;
10461045
int rc = 0;
1046+
int imp;
1047+
1048+
if (pkt_cnt <= 0)
1049+
return 0;
10471050

1051+
hdr = buf_msg(skb_peek(list));
10481052
if (unlikely(msg_size(hdr) > mtu)) {
10491053
pr_warn("Too large msg, purging xmit list %d %d %d %d %d!\n",
10501054
skb_queue_len(list), msg_user(hdr),
@@ -1053,6 +1057,7 @@ int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
10531057
return -EMSGSIZE;
10541058
}
10551059

1060+
imp = msg_importance(hdr);
10561061
/* Allow oversubscription of one data msg per source at congestion */
10571062
if (unlikely(l->backlog[imp].len >= l->backlog[imp].limit)) {
10581063
if (imp == TIPC_SYSTEM_IMPORTANCE) {

0 commit comments

Comments
 (0)