NetBSD Problem Report #55780

From bernd@niob.bersie.loc  Tue Nov  3 19:35:24 2020
Return-Path: <bernd@niob.bersie.loc>
Received: from ( [])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "", Issuer " CA" (not verified))
	by (Postfix) with ESMTPS id D1CF41A921F
	for <>; Tue,  3 Nov 2020 19:35:24 +0000 (UTC)
Message-Id: <20201103181919.2B921236904@niob.bersie.loc>
Date: Tue,  3 Nov 2020 19:19:19 +0100 (CET)
From: bernd@niob.bersie.loc
Reply-To: bernd@niob.bersie.loc
Subject: setsockopt in Linux emulation misses some options
X-Send-Pr-Version: 3.95

>Number:         55780
>Category:       kern
>Synopsis:       setsockopt in Linux emulation misses some options
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 03 19:40:00 +0000 2020
>Last-Modified:  Tue Nov 03 22:10:01 +0000 2020
>Release:        NetBSD 9.1
System: NetBSD niob.bersie.loc 9.1 NetBSD 9.1 (NIOB) #25: Fri Oct 16 18:27:33 CEST 2020 bernd@niob.bersie.loc:/usr/src/sys/arch/amd64/compile/NIOB amd64
Architecture: x86_64
Machine: amd64
When Linux programs running under the Linux emulation try to set certain socket options (such as receive timeout), the call fails, causing limited functionality of the Linux program, even though NetBSD implements the option.

It turns out that linux_socket.c misses a few cases of SO options in linux_to_bsd_so_sockopt, notably LINUX_SO_RCVTIMEO and SO_RCVTIMEO, returning EINVAL to the calling Linux program, causing some problems, e. g. with the folding-at-home client.

Several further options may also be missing, but RCVTIMEO was the one I noticed. linux_socket_generic.h defines many more than linux_to_bsd_so_sockopt is mapping. I guess the code just hasn't been touched in a long time.

Run a Linux program which tries to set socket receive timeout in NetBSD's Linux emulation, e. g. Folding at Home Client 7.6.21.
Apply the following patch, recompile the kernel and reboot:

--- sys/compat/linux/common/linux_socket.c.orig 2020-11-03 17:27:47.055555944 +0100
+++ sys/compat/linux/common/linux_socket.c      2020-11-03 18:28:20.184244766 +0100
@@ -884,6 +884,10 @@
                return SO_SNDLOWAT;
        case LINUX_SO_RCVLOWAT:
                return SO_RCVLOWAT;
+       case LINUX_SO_RCVTIMEO:
+               return SO_RCVTIMEO;
+       case LINUX_SO_SNDTIMEO:
+               return SO_SNDTIMEO;
        case LINUX_SO_KEEPALIVE:
                return SO_KEEPALIVE;
        case LINUX_SO_OOBINLINE:

From: "Christos Zoulas" <>
Subject: PR/55780 CVS commit: src/sys/compat/linux/common
Date: Tue, 3 Nov 2020 17:08:44 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Tue Nov  3 22:08:44 UTC 2020

 Modified Files:
 	src/sys/compat/linux/common: linux_socket.c

 Log Message:
 PR/55780: Bernd Sieker: setsockopt in Linux emulation misses some options

 To generate a diff of this commit:
 cvs rdiff -u -r1.151 -r1.152 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.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD:,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.