net/packet: fix memory leak in packet_set_ring()
authorEric Dumazet <edumazet@google.com>
Mon, 24 Jun 2019 09:38:20 +0000 (02:38 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 24 Jun 2019 14:57:59 +0000 (07:57 -0700)
syzbot found we can leak memory in packet_set_ring(), if user application
provides buggy parameters.

Fixes: 7f953ab2ba46 ("af_packet: TX_RING support for TPACKET_V3")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/packet/af_packet.c

index a29d66da7394bb48c4012b29ff2ad3d256cf7bff..0b4cf94f0233f86c196e767dc0179c38330ecca7 100644 (file)
@@ -4314,7 +4314,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                                    req3->tp_sizeof_priv ||
                                    req3->tp_feature_req_word) {
                                        err = -EINVAL;
-                                       goto out;
+                                       goto out_free_pg_vec;
                                }
                        }
                        break;
@@ -4378,6 +4378,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
                        prb_shutdown_retire_blk_timer(po, rb_queue);
        }
 
+out_free_pg_vec:
        if (pg_vec)
                free_pg_vec(pg_vec, order, req->tp_block_nr);
 out: