From nobody Mon Aug 14 19:57:12 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RPlY42sYgz4TxK7; Mon, 14 Aug 2023 19:57:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RPlY42GHvz4Nn8; Mon, 14 Aug 2023 19:57:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692043032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rklU+1sn2cuzBS5c3PErPEiH6P7HxoNHsgD8grz/l9E=; b=MzWicq8WPb2ZKxPwbEgGobc8M2tynSM7Q/HoWMso1TWkBbLDHRT+8uW+BddhDmGWKMC6Va 61+pXBx0awS7Sp8fQt8KBzaXJ7aYOlwR82JwaGmhJbf62wdFtPp0je+deiKSYSnULfdped JbfcF0REJRQDe51W0lTa+HjFw43v+0MTkfw9s2eDHTWZ60a3QGz1lJICOqmubA0+1juLix qIwMjUHBwFSSZre/5CcssS7jZ+vwqanbcoxk0WGNSiqY9HLPRH6V83y7twNTjeLyscNwWg PRUWqnTqfPfjIXXdu5iggFUK8WuqTSQgsH3vt8eHJCa+qKUl1DVXTXjORwEShg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692043032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rklU+1sn2cuzBS5c3PErPEiH6P7HxoNHsgD8grz/l9E=; b=Gegph/zcIeuJK93eieussnR29wAL29anR8feWtIboyq1KTNhgO4WKi7K0Y5E+bNIcUD0bL 3te5Z7tQ//gPrCyrT+ZQ9FUN2sWWNdNAhMBe+I5SHqVPdVht12NV9qcb/pJypgvQAr3XVj RlQILUfRTkNB6s1wqSo2Wx+dqRCDypUUnB/zBD4pc5NLxvYMO5/9lMvDFuNw3Yb6ekBOLQ TaZT8A79lJFAph1IyXXcMxUx60Q4Hktj0zZqBXGPzt4QZGrXSHNT+hQ5Auu5KKikumAOSV NmDP5tA3qC4QhUY7IdO7/7NuMkX9IpU0r5NZp77G7UoQMhKffiYbN2EgCUCQTQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692043032; a=rsa-sha256; cv=none; b=Ccn+gcG620lZgWf0n88Cyys/3TS5tIbb20t+R7EYaMqjd1KVRAaZO78V9cPa06o3d6jpcx kldyjm5+HluIsxmXsC1pndGPUKcChNtSJBLJcgC2dNE36IDVt6qXnsfgcNFOEX2+ETn8k/ B0+G4QZEbtDorszoD5jVdGLFrEi1rxml0xdUXd2JVbYozEPqKAVIFRxq14Lj7fFH/YA1RX ovQuqT4IfR+0NOMT9HwfinCLLg2ZivO8jONZUb5QiCYyWJdwPF7+5sQ2M8PwPveThSHNtV uaVs5HOwTVhZ4JiKcY3u9c9m+YCA7lMHE5QED5Sttv0SGWbXV6mt86YxxlM0Qg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RPlY41KTlzhC3; Mon, 14 Aug 2023 19:57:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37EJvCjU060378; Mon, 14 Aug 2023 19:57:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37EJvCSP060375; Mon, 14 Aug 2023 19:57:12 GMT (envelope-from git) Date: Mon, 14 Aug 2023 19:57:12 GMT Message-Id: <202308141957.37EJvCSP060375@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: d29b95ecc0d0 - main - sockets: on accept(2) don't copy all of so_options to new socket List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d29b95ecc0d049406d27a6c11939d40a46658733 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=d29b95ecc0d049406d27a6c11939d40a46658733 commit d29b95ecc0d049406d27a6c11939d40a46658733 Author: Gleb Smirnoff AuthorDate: 2023-08-14 19:56:07 +0000 Commit: Gleb Smirnoff CommitDate: 2023-08-14 19:56:08 +0000 sockets: on accept(2) don't copy all of so_options to new socket As uncovered by e3ba0d6adde3 we are copying lots of irrelevant options from the listener to an accepted socket, even those that aren't relevant to a non-listener, e.g. SO_REUSE*, SO_ACCEPTFILTER. Stop doing that and provide a fixed opt-in list for options to be inherited. Ideally we shall not inherit anything at all. For compatibility inherit a set of options that are meaningful for a non-listening socket of a protocol that can listen(2). Differential Revision: https://reviews.freebsd.org/D41412 Fixes: e3ba0d6adde3c694f46a30b3b67eba43a7099395 --- sys/kern/uipc_socket.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index eaff57d50d78..f111ec9d0780 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -750,7 +750,19 @@ solisten_clone(struct socket *head) } so->so_listen = head; so->so_type = head->so_type; - so->so_options = head->so_options & ~SO_ACCEPTCONN; + /* + * POSIX is ambiguous on what options an accept(2)ed socket should + * inherit from the listener. Words "create a new socket" may be + * interpreted as not inheriting anything. Best programming practice + * for application developers is to not rely on such inheritance. + * FreeBSD had historically inherited all so_options excluding + * SO_ACCEPTCONN, which virtually means all SOL_SOCKET level options, + * including those completely irrelevant to a new born socket. For + * compatibility with older versions we will inherit a list of + * meaningful options. + */ + so->so_options = head->so_options & (SO_KEEPALIVE | SO_DONTROUTE | + SO_LINGER | SO_OOBINLINE | SO_NOSIGPIPE); so->so_linger = head->so_linger; so->so_state = head->so_state; so->so_fibnum = head->so_fibnum;