The branch stable/13 has been updated by dchagin:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d238be002e4250de80d197895ea409ef85572c95

commit d238be002e4250de80d197895ea409ef85572c95
Author:     Dmitry Chagin <[email protected]>
AuthorDate: 2023-08-14 12:46:12 +0000
Commit:     Dmitry Chagin <[email protected]>
CommitDate: 2023-08-21 10:39:04 +0000

    linux(4): Skip unsupported anxiliary message
    
    Instead of returning error, skip unsupported anxiliary messages and
    fail if no one handled.
    
    MFC after:      1 week
    
    (cherry picked from commit bbaa5523c01a11e1e322928639522b9ccfd19978)
---
 sys/compat/linux/linux_socket.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 063e542f9d83..7bcefcd2d81b 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -1723,7 +1723,7 @@ linux_recvmsg_common(struct thread *td, l_int s, struct 
l_msghdr *msghdr,
        struct sockaddr *sa;
        caddr_t outbuf;
        void *data, *udata;
-       int error;
+       int error, skiped;
 
        error = copyin(msghdr, &l_msghdr, sizeof(l_msghdr));
        if (error != 0)
@@ -1789,7 +1789,7 @@ linux_recvmsg_common(struct thread *td, l_int s, struct 
l_msghdr *msghdr,
        msg->msg_control = mtod(control, struct cmsghdr *);
        msg->msg_controllen = control->m_len;
        outbuf = PTRIN(l_msghdr.msg_control);
-       outlen = 0;
+       skiped = outlen = 0;
        for (m = control; m != NULL; m = m->m_next) {
                cm = mtod(m, struct cmsghdr *);
                lcm->cmsg_type = bsd_to_linux_cmsg_type(p, cm->cmsg_type,
@@ -1809,12 +1809,13 @@ linux_recvmsg_common(struct thread *td, l_int s, struct 
l_msghdr *msghdr,
                }
 
                if (lcm->cmsg_type == -1 ||
-                   cm->cmsg_level != SOL_SOCKET) {
+                   cm->cmsg_level == -1) {
                        LINUX_RATELIMIT_MSG_OPT2(
                            "unsupported recvmsg cmsg level %d type %d",
                            cm->cmsg_level, cm->cmsg_type);
-                       error = EINVAL;
-                       goto bad;
+                       /* Skip unsupported messages */
+                       skiped++;
+                       continue;
                }
 
                switch (cm->cmsg_type) {
@@ -1872,6 +1873,10 @@ err:
                if (error != 0)
                        goto bad;
        }
+       if (outlen == 0 && skiped > 0) {
+               error = EINVAL;
+               goto bad;
+       }
        l_msghdr.msg_controllen = outlen;
 
 out:

Reply via email to