Module Name: src Committed By: martin Date: Sun Nov 8 08:39:13 UTC 2020
Modified Files: src/sys/compat/linux/common [netbsd-9]: linux_socket.c Log Message: 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 To generate a diff of this commit: cvs rdiff -u -r1.145.4.2 -r1.145.4.3 \ src/sys/compat/linux/common/linux_socket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/linux/common/linux_socket.c diff -u src/sys/compat/linux/common/linux_socket.c:1.145.4.2 src/sys/compat/linux/common/linux_socket.c:1.145.4.3 --- src/sys/compat/linux/common/linux_socket.c:1.145.4.2 Fri Jul 17 15:24:48 2020 +++ src/sys/compat/linux/common/linux_socket.c Sun Nov 8 08:39:12 2020 @@ -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 @@ linux_get_sa(struct lwp *l, int s, struc 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);