Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/linux/common Fix compat with Linux programs that ...



details:   https://anonhg.NetBSD.org/src/rev/95cf3bc60b9a
branches:  trunk
changeset: 941572:95cf3bc60b9a
user:      mgorny <mgorny%NetBSD.org@localhost>
date:      Sat Oct 24 09:01:56 2020 +0000

description:
Fix compat with Linux programs that use longer namelen for sockets

Linux is less strict than NetBSD and permits namelen to be larger
than valid struct sockaddr_in*.  If this is the case, truncate the value
to the correct size, so that NetBSD networking does not return an error.

Reviewed by kamil

diffstat:

 sys/compat/linux/common/linux_socket.c |  19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diffs (40 lines):

diff -r a44ca8692a50 -r 95cf3bc60b9a sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c    Sat Oct 24 09:00:35 2020 +0000
+++ b/sys/compat/linux/common/linux_socket.c    Sat Oct 24 09:01:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_socket.c,v 1.150 2020/07/16 15:02:08 msaitoh Exp $       */
+/*     $NetBSD: linux_socket.c,v 1.151 2020/10/24 09:01:56 mgorny Exp $        */
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.150 2020/07/16 15:02:08 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.151 2020/10/24 09:01:56 mgorny Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1612,6 +1612,21 @@
                sin6->sin6_scope_id = 0;
        }
 
+       /*
+        * Linux is less strict than NetBSD and permits namelen to be larger
+        * than valid struct sockaddr_in*.  If this is the case, truncate
+        * the value to the correct size, so that NetBSD networking does not
+        * return an error.
+        */
+       switch (bdom) {
+       case AF_INET:
+               namelen = MIN(namelen, sizeof(struct sockaddr_in));
+               break;
+       case AF_INET6:
+               namelen = MIN(namelen, sizeof(struct sockaddr_in6));
+               break;
+       }
+
        sb->sb_family = bdom;
        sb->sb_len = namelen;
        ktrkuser("mbsoname", sb, namelen);



Home | Main Index | Thread Index | Old Index