From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 18 21:00:09 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 48926922 for ; Mon, 18 Mar 2013 21:00:09 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id CF0DCA73 for ; Mon, 18 Mar 2013 21:00:08 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r2IKxwQ0055823; Mon, 18 Mar 2013 22:59:58 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.0 kib.kiev.ua r2IKxwQ0055823 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r2IKxv1N055822; Mon, 18 Mar 2013 22:59:57 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 18 Mar 2013 22:59:57 +0200 From: Konstantin Belousov To: Jilles Tjoelker Subject: Re: [patch] SOCK_CLOEXEC, SOCK_NONBLOCK and MSG_CMSG_CLOEXEC Message-ID: <20130318205957.GM3794@kib.kiev.ua> References: <20130317212353.GD65525@stack.nl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="YLnPAZt6hMJRJaYl" Content-Disposition: inline In-Reply-To: <20130317212353.GD65525@stack.nl> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Mar 2013 21:00:09 -0000 --YLnPAZt6hMJRJaYl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 17, 2013 at 10:23:53PM +0100, Jilles Tjoelker wrote: > Here are some more modifications to allow creating file descriptors with > close-on-exec set. Like in linux/glibc, SOCK_CLOEXEC and SOCK_NONBLOCK > can be OR'ed in socket() and socketpair()'s type parameter, and > MSG_CMSG_CLOEXEC to recvmsg() makes file descriptors (SCM_RIGHTS) > atomically close-on-exec. >=20 > The numerical values for SOCK_CLOEXEC and SOCK_NONBLOCK are as in > NetBSD. MSG_CMSG_CLOEXEC is the first free bit for MSG_*. >=20 > I do not pass the SOCK_* flags to MAC because this may cause incorrect > failures and can be done later via fcntl() anyway. I expect audit to > cope with the new flags. >=20 > For MSG_CMSG_CLOEXEC, I had to change unp_externalize to take a flags > argument. This looks fine to me. The only note I have, which is not directly related to your patch, is the recvmsg(2) behaviour when the undefined flag is passed. The syscall silently ignores the flags. I think this is quite wrong, and would cause interesting (security) implications if the program using the MSG_CMSG_CLOEXEC is run on older kernel which does not interpret the flag. Might be, we should start returning EINVAL for unknown flag, despite SUSv4 not specifying the condition ? --YLnPAZt6hMJRJaYl Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRR4BNAAoJEJDCuSvBvK1BYTwQAJG6hk1PePBZhmAzMo+QMc7J yfZG+dTpSeqz+/KXRz/+unuL5MgaRtirMEFKfIFk0SgXbLN0BR6OC9XdGKeBH+xZ Fc0wm4wzdmzvC79NJjV+kNBEm/lYr3zRdr2CFpkDf/YsAdP828tyTpjWqqe4bVrk slFuWBu/cUFGwlK3xRTtIpNeKFh1f5g7Xcl9eAscqK9HupbhcKVPItvhL+zoN6FF a2qBXDC7BBmNDgxExrcyZwIELkcRGa33vdVjln4foaeidkquu+RZ9AgqqcvW/S6S F0gd+GuCTv+72ZDDy3zjMm39JJqHJa7Cy/+Bq8+j2kcelvGfE2I5RWQ0dAo4GACV 1pW5ZeqPD9O4vOjUrG/jrpKokz/dnKdsumUubqN/WMZWkhKg0md0ummpI2vXi4XO MPoJZBsnTBR/tHyCJBiX+Ej8ReZSMt/ADCMD/cq4ZraE6719HU+V2wxR8kI/6ivY S/z8MQeO2wmDhLa5YOdo1NsvlKqaSEgKthay3yc3QBEJItrv1Ht9ycsVWRkh2og7 7twEBY1J2vRcBUcnD2WamJubkH4af5Vk+PhwbUzQwpOEs/J1QPASbDTbsTX3e7uS eQNKOV260i7hXNSk4VRc7qn2syvCl6UElEsrT2zVeQGAWTWK5dNHrU59YUcW/ZPI oYo/csOt11C65hWMb75f =nwSl -----END PGP SIGNATURE----- --YLnPAZt6hMJRJaYl--