xsk: lock the control mutex in sock_diag interface
authorBjörn Töpel <bjorn.topel@intel.com>
Wed, 4 Sep 2019 11:49:13 +0000 (13:49 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 5 Sep 2019 12:11:52 +0000 (14:11 +0200)
When accessing the members of an XDP socket, the control mutex should
be held. This commit fixes that.

Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Fixes: a36b38aa2af6 ("xsk: add sock_diag interface for AF_XDP")
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/xdp/xsk_diag.c

index 9986a759fe06eae833dc40207510d6b4c8061b78..f59791ba43a04c08e6d486edf418c63e267a0220 100644 (file)
@@ -97,6 +97,7 @@ static int xsk_diag_fill(struct sock *sk, struct sk_buff *nlskb,
        msg->xdiag_ino = sk_ino;
        sock_diag_save_cookie(sk, msg->xdiag_cookie);
 
+       mutex_lock(&xs->mutex);
        if ((req->xdiag_show & XDP_SHOW_INFO) && xsk_diag_put_info(xs, nlskb))
                goto out_nlmsg_trim;
 
@@ -117,10 +118,12 @@ static int xsk_diag_fill(struct sock *sk, struct sk_buff *nlskb,
            sock_diag_put_meminfo(sk, nlskb, XDP_DIAG_MEMINFO))
                goto out_nlmsg_trim;
 
+       mutex_unlock(&xs->mutex);
        nlmsg_end(nlskb, nlh);
        return 0;
 
 out_nlmsg_trim:
+       mutex_unlock(&xs->mutex);
        nlmsg_cancel(nlskb, nlh);
        return -EMSGSIZE;
 }