Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/compat/linux/common Pull up following revision(s) (re...



details:   https://anonhg.NetBSD.org/src/rev/70ad43c8e164
branches:  netbsd-9
changeset: 964187:70ad43c8e164
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Nov 08 08:39:12 2020 +0000

description:
Pull up following revision(s) (requested by kamil in ticket #1127):

        sys/compat/linux/common/linux_socket.c: revision 1.151

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 d3d59c2588d4 -r 70ad43c8e164 sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c    Thu Nov 05 08:11:37 2020 +0000
+++ b/sys/compat/linux/common/linux_socket.c    Sun Nov 08 08:39:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_socket.c,v 1.145.4.2 2020/07/17 15:24:48 martin Exp $    */
+/*     $NetBSD: linux_socket.c,v 1.145.4.3 2020/11/08 08:39:12 martin 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.145.4.2 2020/07/17 15:24:48 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.145.4.3 2020/11/08 08:39:12 martin 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