*** This bug is a security vulnerability ***

You have been subscribed to a public security bug by Seth Arnold (seth-arnold):

sock_hold(sk) is invoked in pep_sock_accept(),but __sock_put() is not
invoked in subsequent failure branches(pep_accept_conn() != 0).

static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,
                                    bool kern)
{
        struct pep_sock *pn = pep_sk(sk), *newpn;
        struct sock *newsk = NULL;
        struct sk_buff *skb;
        struct pnpipehdr *hdr;
        struct sockaddr_pn dst, src;
        int err;
        u16 peer_type;
        u8 pipe_handle, enabled, n_sb;
        u8 aligned = 0;
...
        newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot,
                         kern);
        if (!newsk) {
                pep_reject_conn(sk, skb, PN_PIPE_ERR_OVERLOAD, GFP_KERNEL);
                err = -ENOBUFS;
                goto drop;
        }
...
        sock_hold(sk);    <---- here,sk->sk_refcnt++
        newpn->listener = sk;
        skb_queue_head_init(&newpn->ctrlreq_queue);
        newpn->pipe_handle = pipe_handle;
        atomic_set(&newpn->tx_credits, 0);
        newpn->ifindex = 0;
        newpn->peer_type = peer_type;
        newpn->rx_credits = 0;
        newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
        newpn->init_enable = enabled;
        newpn->aligned = aligned;

        err = pep_accept_conn(newsk, skb);
        if (err) {
                sock_put(newsk);    <---- before sock_put(newsk) may need 
sk->sk_refcnt--
                newsk = NULL;
                goto drop;
        }
        sk_add_node(newsk, &pn->hlist);
drop:
        release_sock(sk);
        kfree_skb(skb);
        *errp = err;
        return newsk;
}


My suggestion for the patch:

static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp,
                                    bool kern)
{
...
        err = pep_accept_conn(newsk, skb);
        if (err) {
+++             __sock_put(sk);
                sock_put(newsk);   
                newsk = NULL;
                goto drop;
        }
        sk_add_node(newsk, &pn->hlist);
drop:
        release_sock(sk);
        kfree_skb(skb);
        *errp = err;
        return newsk;
}

** Affects: linux (Ubuntu)
     Importance: Undecided
         Status: New

-- 
refcount leak in pep_sock_accept
https://bugs.launchpad.net/bugs/1953022
You received this bug notification because you are a member of Ubuntu Bugs, 
which is subscribed to the bug report.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to