sctp: use SCTP_FUTURE_ASSOC for SCTP_PR_SUPPORTED sockopt
authorXin Long <lucien.xin@gmail.com>
Mon, 28 Jan 2019 07:08:30 +0000 (15:08 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Jan 2019 08:44:07 +0000 (00:44 -0800)
Check with SCTP_FUTURE_ASSOC instead in
sctp_set/getsockopt_pr_supported, it's compatible with 0.

It also adjusts some code to keep a same check form as other functions.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sctp/socket.c

index 1d49b7dfcba2d55a5b6b99f9a64bd6b3caf1347e..9e2b153189423392344084a1f2cc1693f8089bcd 100644 (file)
@@ -3965,6 +3965,7 @@ static int sctp_setsockopt_pr_supported(struct sock *sk,
                                        unsigned int optlen)
 {
        struct sctp_assoc_value params;
+       struct sctp_association *asoc;
 
        if (optlen != sizeof(params))
                return -EINVAL;
@@ -3972,6 +3973,11 @@ static int sctp_setsockopt_pr_supported(struct sock *sk,
        if (copy_from_user(&params, optval, optlen))
                return -EFAULT;
 
+       asoc = sctp_id2assoc(sk, params.assoc_id);
+       if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP))
+               return -EINVAL;
+
        sctp_sk(sk)->ep->prsctp_enable = !!params.assoc_value;
 
        return 0;
@@ -7084,17 +7090,15 @@ static int sctp_getsockopt_pr_supported(struct sock *sk, int len,
                goto out;
 
        asoc = sctp_id2assoc(sk, params.assoc_id);
-       if (asoc) {
-               params.assoc_value = asoc->prsctp_enable;
-       } else if (!params.assoc_id) {
-               struct sctp_sock *sp = sctp_sk(sk);
-
-               params.assoc_value = sp->ep->prsctp_enable;
-       } else {
+       if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+           sctp_style(sk, UDP)) {
                retval = -EINVAL;
                goto out;
        }
 
+       params.assoc_value = asoc ? asoc->prsctp_enable
+                                 : sctp_sk(sk)->ep->prsctp_enable;
+
        if (put_user(len, optlen))
                goto out;