sctp/lksctp-tools

Some function tests returned error

jijianwen opened this issue · 3 comments

Commit eaf7032 fixed the compilation error. My system is rhel-7.5 which has /usr/include/linux/sctp.h,but when compiling lksctp-tools, it uses src/include/linux/sctp.h as default. After compilation, I got some error when executing test programs under func_tests directory. The reason should be that some structures are different between 2 header files. For example:
setsockopt(SCTP_EVENTS) in test_1_to_1_events returned Invalid arguments.

I think kernel checked the size of relevant struct and returned error for there are more fields in src/include/linux/sctp.h than /usr/include/linux/sctp.h

Your reasoning is correct. This exhibits a backward compatibility issue that was already there: newer lksctp-tools, with updated structs, also wouldn't work with kernels not having those fields in struct sctp_event_subscribe.

We should fix this at kernel level, with something like:

--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2320,7 +2320,7 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
        struct sctp_ulpevent *event;

        if (optlen > sizeof(struct sctp_event_subscribe))
-               return -EINVAL;
+               optlen = sizeof(struct sctp_event_subscribe);
        if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
                return -EFAULT;

@@ -2342,7 +2342,7 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
                }
        }

-       return 0;
+       return optlen;
 }

 /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE)

Still need to check for other possible occurrences of similar issues.

Scratch my previous comment. The issue is that the local copy is always being used, even where it should be using the system UAPI one. I fixed issue #22 and issue #23 wrongly. Instead, the library needs to probe what the kernel supports while building and only use that.
I'll use this issue to fix all this.