Skip to content

Commit ceb4fc4

Browse files
ebiggersgregkh
authored andcommitted
llc: fix sk_buff leak in llc_conn_service()
commit b74555d upstream. syzbot reported: BUG: memory leak unreferenced object 0xffff88811eb3de00 (size 224): comm "syz-executor559", pid 7315, jiffies 4294943019 (age 10.300s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 a0 38 24 81 88 ff ff 00 c0 f2 15 81 88 ff ff ..8$............ backtrace: [<000000008d1c66a1>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline] [<000000008d1c66a1>] slab_post_alloc_hook mm/slab.h:439 [inline] [<000000008d1c66a1>] slab_alloc_node mm/slab.c:3269 [inline] [<000000008d1c66a1>] kmem_cache_alloc_node+0x153/0x2a0 mm/slab.c:3579 [<00000000447d9496>] __alloc_skb+0x6e/0x210 net/core/skbuff.c:198 [<000000000cdbf82f>] alloc_skb include/linux/skbuff.h:1058 [inline] [<000000000cdbf82f>] llc_alloc_frame+0x66/0x110 net/llc/llc_sap.c:54 [<000000002418b52e>] llc_conn_ac_send_sabme_cmd_p_set_x+0x2f/0x140 net/llc/llc_c_ac.c:777 [<000000001372ae17>] llc_exec_conn_trans_actions net/llc/llc_conn.c:475 [inline] [<000000001372ae17>] llc_conn_service net/llc/llc_conn.c:400 [inline] [<000000001372ae17>] llc_conn_state_process+0x1ac/0x640 net/llc/llc_conn.c:75 [<00000000f27e53c1>] llc_establish_connection+0x110/0x170 net/llc/llc_if.c:109 [<00000000291b2ca0>] llc_ui_connect+0x10e/0x370 net/llc/af_llc.c:477 [<000000000f9c740b>] __sys_connect+0x11d/0x170 net/socket.c:1840 [...] The bug is that most callers of llc_conn_send_pdu() assume it consumes a reference to the skb, when actually due to commit b85ab56 ("llc: properly handle dev_queue_xmit() return value") it doesn't. Revert most of that commit, and instead make the few places that need llc_conn_send_pdu() to *not* consume a reference call skb_get() before. Fixes: b85ab56 ("llc: properly handle dev_queue_xmit() return value") Reported-by: syzbot+6b825a6494a04cc0e3f7@syzkaller.appspotmail.com Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a95b751 commit ceb4fc4

3 files changed

Lines changed: 16 additions & 26 deletions

File tree

‎include/net/llc_conn.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void llc_sk_reset(struct sock *sk);
104104

105105
/* Access to a connection */
106106
int llc_conn_state_process(struct sock *sk, struct sk_buff *skb);
107-
int llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb);
107+
void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb);
108108
void llc_conn_rtn_pdu(struct sock *sk, struct sk_buff *skb);
109109
void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit);
110110
void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit);

‎net/llc/llc_c_ac.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
372372
llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
373373
rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
374374
if (likely(!rc)) {
375+
skb_get(skb);
375376
llc_conn_send_pdu(sk, skb);
376377
llc_conn_ac_inc_vs_by_1(sk, skb);
377378
}
@@ -389,7 +390,8 @@ static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
389390
llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
390391
rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
391392
if (likely(!rc)) {
392-
rc = llc_conn_send_pdu(sk, skb);
393+
skb_get(skb);
394+
llc_conn_send_pdu(sk, skb);
393395
llc_conn_ac_inc_vs_by_1(sk, skb);
394396
}
395397
return rc;
@@ -406,6 +408,7 @@ int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
406408
llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
407409
rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
408410
if (likely(!rc)) {
411+
skb_get(skb);
409412
llc_conn_send_pdu(sk, skb);
410413
llc_conn_ac_inc_vs_by_1(sk, skb);
411414
}
@@ -916,7 +919,8 @@ static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
916919
llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
917920
rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
918921
if (likely(!rc)) {
919-
rc = llc_conn_send_pdu(sk, skb);
922+
skb_get(skb);
923+
llc_conn_send_pdu(sk, skb);
920924
llc_conn_ac_inc_vs_by_1(sk, skb);
921925
}
922926
return rc;

‎net/llc/llc_conn.c‎

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#endif
3131

3232
static int llc_find_offset(int state, int ev_type);
33-
static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *skb);
33+
static void llc_conn_send_pdus(struct sock *sk);
3434
static int llc_conn_service(struct sock *sk, struct sk_buff *skb);
3535
static int llc_exec_conn_trans_actions(struct sock *sk,
3636
struct llc_conn_state_trans *trans,
@@ -193,11 +193,11 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
193193
return rc;
194194
}
195195

196-
int llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
196+
void llc_conn_send_pdu(struct sock *sk, struct sk_buff *skb)
197197
{
198198
/* queue PDU to send to MAC layer */
199199
skb_queue_tail(&sk->sk_write_queue, skb);
200-
return llc_conn_send_pdus(sk, skb);
200+
llc_conn_send_pdus(sk);
201201
}
202202

203203
/**
@@ -255,7 +255,7 @@ void llc_conn_resend_i_pdu_as_cmd(struct sock *sk, u8 nr, u8 first_p_bit)
255255
if (howmany_resend > 0)
256256
llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
257257
/* any PDUs to re-send are queued up; start sending to MAC */
258-
llc_conn_send_pdus(sk, NULL);
258+
llc_conn_send_pdus(sk);
259259
out:;
260260
}
261261

@@ -296,7 +296,7 @@ void llc_conn_resend_i_pdu_as_rsp(struct sock *sk, u8 nr, u8 first_f_bit)
296296
if (howmany_resend > 0)
297297
llc->vS = (llc->vS + 1) % LLC_2_SEQ_NBR_MODULO;
298298
/* any PDUs to re-send are queued up; start sending to MAC */
299-
llc_conn_send_pdus(sk, NULL);
299+
llc_conn_send_pdus(sk);
300300
out:;
301301
}
302302

@@ -340,16 +340,12 @@ int llc_conn_remove_acked_pdus(struct sock *sk, u8 nr, u16 *how_many_unacked)
340340
/**
341341
* llc_conn_send_pdus - Sends queued PDUs
342342
* @sk: active connection
343-
* @hold_skb: the skb held by caller, or NULL if does not care
344343
*
345-
* Sends queued pdus to MAC layer for transmission. When @hold_skb is
346-
* NULL, always return 0. Otherwise, return 0 if @hold_skb is sent
347-
* successfully, or 1 for failure.
344+
* Sends queued pdus to MAC layer for transmission.
348345
*/
349-
static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *hold_skb)
346+
static void llc_conn_send_pdus(struct sock *sk)
350347
{
351348
struct sk_buff *skb;
352-
int ret = 0;
353349

354350
while ((skb = skb_dequeue(&sk->sk_write_queue)) != NULL) {
355351
struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
@@ -361,20 +357,10 @@ static int llc_conn_send_pdus(struct sock *sk, struct sk_buff *hold_skb)
361357
skb_queue_tail(&llc_sk(sk)->pdu_unack_q, skb);
362358
if (!skb2)
363359
break;
364-
dev_queue_xmit(skb2);
365-
} else {
366-
bool is_target = skb == hold_skb;
367-
int rc;
368-
369-
if (is_target)
370-
skb_get(skb);
371-
rc = dev_queue_xmit(skb);
372-
if (is_target)
373-
ret = rc;
360+
skb = skb2;
374361
}
362+
dev_queue_xmit(skb);
375363
}
376-
377-
return ret;
378364
}
379365

380366
/**

0 commit comments

Comments
 (0)