Module Name: src Committed By: mgorny Date: Sat Oct 24 09:01:56 UTC 2020
Modified Files: src/sys/compat/linux/common: linux_socket.c Log Message: 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.150 -r1.151 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.150 src/sys/compat/linux/common/linux_socket.c:1.151 --- src/sys/compat/linux/common/linux_socket.c:1.150 Thu Jul 16 15:02:08 2020 +++ src/sys/compat/linux/common/linux_socket.c Sat Oct 24 09:01:56 2020 @@ -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 @@ 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);