summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2019-10-06 17:24:24 -0400
committerJakub Kicinski <jakub.kicinski@netronome.com>2019-10-08 16:23:05 -0400
commitc6ee11c39fcc1fb55130748990a8f199e76263b4 (patch)
treedb07cff6f94701215324c9b31aa7eb3bf2c21249
parent503c9addef613c872679e24fc8a78f3febeb5a08 (diff)
llc: fix sk_buff leak in llc_sap_state_process()
syzbot reported: BUG: memory leak unreferenced object 0xffff888116270800 (size 224): comm "syz-executor641", pid 7047, jiffies 4294947360 (age 13.860s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 20 e1 2a 81 88 ff ff 00 40 3d 2a 81 88 ff ff . .*.....@=*.... backtrace: [<000000004d41b4cc>] kmemleak_alloc_recursive include/linux/kmemleak.h:55 [inline] [<000000004d41b4cc>] slab_post_alloc_hook mm/slab.h:439 [inline] [<000000004d41b4cc>] slab_alloc_node mm/slab.c:3269 [inline] [<000000004d41b4cc>] kmem_cache_alloc_node+0x153/0x2a0 mm/slab.c:3579 [<00000000506a5965>] __alloc_skb+0x6e/0x210 net/core/skbuff.c:198 [<000000001ba5a161>] alloc_skb include/linux/skbuff.h:1058 [inline] [<000000001ba5a161>] alloc_skb_with_frags+0x5f/0x250 net/core/skbuff.c:5327 [<0000000047d9c78b>] sock_alloc_send_pskb+0x269/0x2a0 net/core/sock.c:2225 [<000000003828fe54>] sock_alloc_send_skb+0x32/0x40 net/core/sock.c:2242 [<00000000e34d94f9>] llc_ui_sendmsg+0x10a/0x540 net/llc/af_llc.c:933 [<00000000de2de3fb>] sock_sendmsg_nosec net/socket.c:652 [inline] [<00000000de2de3fb>] sock_sendmsg+0x54/0x70 net/socket.c:671 [<000000008fe16e7a>] __sys_sendto+0x148/0x1f0 net/socket.c:1964 [...] The bug is that llc_sap_state_process() always takes an extra reference to the skb, but sometimes neither llc_sap_next_state() nor llc_sap_state_process() itself drops this reference. Fix it by changing llc_sap_next_state() to never consume a reference to the skb, rather than sometimes do so and sometimes not. Then remove the extra skb_get() and kfree_skb() from llc_sap_state_process(). Reported-by: syzbot+6bf095f9becf5efef645@syzkaller.appspotmail.com Reported-by: syzbot+31c16aa4202dace3812e@syzkaller.appspotmail.com Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
-rw-r--r--net/llc/llc_s_ac.c12
-rw-r--r--net/llc/llc_sap.c23
2 files changed, 17 insertions, 18 deletions
diff --git a/net/llc/llc_s_ac.c b/net/llc/llc_s_ac.c
index a94bd56bcac6..7ae4cc684d3a 100644
--- a/net/llc/llc_s_ac.c
+++ b/net/llc/llc_s_ac.c
@@ -58,8 +58,10 @@ int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
58 ev->daddr.lsap, LLC_PDU_CMD); 58 ev->daddr.lsap, LLC_PDU_CMD);
59 llc_pdu_init_as_ui_cmd(skb); 59 llc_pdu_init_as_ui_cmd(skb);
60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
61 if (likely(!rc)) 61 if (likely(!rc)) {
62 skb_get(skb);
62 rc = dev_queue_xmit(skb); 63 rc = dev_queue_xmit(skb);
64 }
63 return rc; 65 return rc;
64} 66}
65 67
@@ -81,8 +83,10 @@ int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
81 ev->daddr.lsap, LLC_PDU_CMD); 83 ev->daddr.lsap, LLC_PDU_CMD);
82 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0); 84 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
83 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 85 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
84 if (likely(!rc)) 86 if (likely(!rc)) {
87 skb_get(skb);
85 rc = dev_queue_xmit(skb); 88 rc = dev_queue_xmit(skb);
89 }
86 return rc; 90 return rc;
87} 91}
88 92
@@ -135,8 +139,10 @@ int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
135 ev->daddr.lsap, LLC_PDU_CMD); 139 ev->daddr.lsap, LLC_PDU_CMD);
136 llc_pdu_init_as_test_cmd(skb); 140 llc_pdu_init_as_test_cmd(skb);
137 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 141 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
138 if (likely(!rc)) 142 if (likely(!rc)) {
143 skb_get(skb);
139 rc = dev_queue_xmit(skb); 144 rc = dev_queue_xmit(skb);
145 }
140 return rc; 146 return rc;
141} 147}
142 148
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
index a7f7b8ff4729..be419062e19a 100644
--- a/net/llc/llc_sap.c
+++ b/net/llc/llc_sap.c
@@ -197,29 +197,22 @@ out:
197 * After executing actions of the event, upper layer will be indicated 197 * After executing actions of the event, upper layer will be indicated
198 * if needed(on receiving an UI frame). sk can be null for the 198 * if needed(on receiving an UI frame). sk can be null for the
199 * datalink_proto case. 199 * datalink_proto case.
200 *
201 * This function always consumes a reference to the skb.
200 */ 202 */
201static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb) 203static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
202{ 204{
203 struct llc_sap_state_ev *ev = llc_sap_ev(skb); 205 struct llc_sap_state_ev *ev = llc_sap_ev(skb);
204 206
205 /*
206 * We have to hold the skb, because llc_sap_next_state
207 * will kfree it in the sending path and we need to
208 * look at the skb->cb, where we encode llc_sap_state_ev.
209 */
210 skb_get(skb);
211 ev->ind_cfm_flag = 0; 207 ev->ind_cfm_flag = 0;
212 llc_sap_next_state(sap, skb); 208 llc_sap_next_state(sap, skb);
213 if (ev->ind_cfm_flag == LLC_IND) {
214 if (skb->sk->sk_state == TCP_LISTEN)
215 kfree_skb(skb);
216 else {
217 llc_save_primitive(skb->sk, skb, ev->prim);
218 209
219 /* queue skb to the user. */ 210 if (ev->ind_cfm_flag == LLC_IND && skb->sk->sk_state != TCP_LISTEN) {
220 if (sock_queue_rcv_skb(skb->sk, skb)) 211 llc_save_primitive(skb->sk, skb, ev->prim);
221 kfree_skb(skb); 212
222 } 213 /* queue skb to the user. */
214 if (sock_queue_rcv_skb(skb->sk, skb) == 0)
215 return;
223 } 216 }
224 kfree_skb(skb); 217 kfree_skb(skb);
225} 218}