From nobody Wed Jun 29 16:43:14 2022 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 ACE2686BB18; Wed, 29 Jun 2022 16:43:15 +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 4LY6hz0tHfz3N5t; Wed, 29 Jun 2022 16:43:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656520995; 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=9+7vSvvO+CXOvq5W1QOyrMh26CSj3976oDQyRMI5DZw=; b=uERg2Yi3/JRmdLuD4EvboFkFgWZuJyp7i+cYKNZyD94xITghJx+SY6ZH0+SKJuObMqMM8j XBp2iBjZ62p4yDLwqnu5BAbxR8fLbXmce7/q/t16Irb8NxS9IxSGZxG1BVXsse3pdLOXTq LrgLEyli3qrXiYiInFKOs3opFZIysoCGskK3lucOQlUijElv9ldaJbMPM+/ZpDx2A/rL9U 4cClL7CPDXgAN5It2GMHJrQbUEZ9DsKRkc/YP05UV/7s/SjgRuHGG6THqkRgeOx6IdDpi3 cm+bfux8tDSph2HCZQpCHV1gUkApyrCjNo7yxvIS1OAou2txA/6wkIA3sFCufQ== 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 E910715798; Wed, 29 Jun 2022 16:43:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25TGhEwG003746; Wed, 29 Jun 2022 16:43:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25TGhEih003745; Wed, 29 Jun 2022 16:43:14 GMT (envelope-from git) Date: Wed, 29 Jun 2022 16:43:14 GMT Message-Id: <202206291643.25TGhEih003745@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: 48a55bbfe95b - main - unix: change error code for recvmsg() failed due to RLIMIT_NOFILE 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: 48a55bbfe95bc7b32d37673839edc2f365ffc028 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656520995; 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=9+7vSvvO+CXOvq5W1QOyrMh26CSj3976oDQyRMI5DZw=; b=WVRpe+YK0hawddS8D1lSfF61uAFKgItInR0m8bXsspFMOqtY36JY8y3sSzt7R7/DUEwoCR W7KOE7all/uRWH+I2YgDcgL88IzwD5u6gxuarQSPL+p4eCimcwFReN/H2b00xJeIEsed5J As5sHofLFgevNdo5uVo360qAZDEpZSZg2n00XxI/hWA4Ul3YBw7OeotZa3SqDjmnizi1S/ w4nHRbxhaMwmZqVtwV1ym8tiCc2iK9x6VjUxJ8pO/GaL9ScyXTt++exljqzCwFz2yVBcfP L5R89jqnLW2nrs8aOhmUg8jqXds2pTG01ualajl6q3mgcQp8NLbaA/S6dxOCSw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656520995; a=rsa-sha256; cv=none; b=NCl3uxFJH1mbM+VGJEftL1jBKxIX2oa4OYW8ESaKC1580HMZUFKnwDQoGcgVPquc5Ka8XG 7k59y4mm+zqmPLzXZG8oS2ZOlkJZTFPUxZCZSc/fZLAdhncA9Kvi/xlmT+sdvxZzVtovmP Cdb3bLb1OZdFn1nuUDr+BrpJtKHqyV405F8P9gxYmaX3Bmwsd1q00wzUEhBXxuo5zj6zoW 14yfVGSdA/qNSw0WrUp0Elj/j59LPznVUgoBtd59NeOdezCD5mFut5wsHb4Hc4CAdtY2Rx UjU1uYMw1wfLBaC8urIWS3RFw0FoACxVGUr7RE5+tF9CHPYkEgzIMi6YEdEDGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=48a55bbfe95bc7b32d37673839edc2f365ffc028 commit 48a55bbfe95bc7b32d37673839edc2f365ffc028 Author: Gleb Smirnoff AuthorDate: 2022-06-29 16:42:58 +0000 Commit: Gleb Smirnoff CommitDate: 2022-06-29 16:42:58 +0000 unix: change error code for recvmsg() failed due to RLIMIT_NOFILE Instead of returning EMSGSIZE pass the error code from fdallocn() directly to userland. That would be EMFILE, which makes much more sense. This error code is not listed in the specification[1], but the specification doesn't cover such edge case at all. Meanwhile the specification lists EMSGSIZE as the error code for invalid value of msg_iovlen, and FreeBSD follows that, see sys_recmsg(). Differentiating these two cases will make a developer/admin life much easier when debugging. [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35640 --- lib/libc/sys/recv.2 | 19 +++++++++++++++---- sys/kern/uipc_usrreq.c | 3 +-- tests/sys/kern/unix_passfd_test.c | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/libc/sys/recv.2 b/lib/libc/sys/recv.2 index 46e0cf8163dd..1f3bf531c3e7 100644 --- a/lib/libc/sys/recv.2 +++ b/lib/libc/sys/recv.2 @@ -28,7 +28,7 @@ .\" @(#)recv.2 8.3 (Berkeley) 2/21/94 .\" $FreeBSD$ .\" -.Dd August 19, 2018 +.Dd June 29, 2022 .Dt RECV 2 .Os .Sh NAME @@ -332,7 +332,7 @@ and The argument .Fa s does not refer to a socket. -.It Bq Er EMSGSIZE +.It Bq Er EMFILE The .Fn recvmsg system call @@ -340,9 +340,20 @@ was used to receive rights (file descriptors) that were in flight on the connection. However, the receiving program did not have enough free file descriptor slots to accept them. -In this case the descriptors are -closed, any pending data can be returned by another call to +In this case the descriptors are closed, with pending data either discarded +in the case of the unreliable datagram protocol or preserved in the case of a +reliable protocol. +The pending data can be retrieved with another call to .Fn recvmsg . +.It Bq Er EMSGSIZE +The +.Fa msg_iovlen +member of the +.Fa msghdr +structure pointed to by +.Fa msg +is less than or equal to 0, or is greater than +.Va IOV_MAX . .It Bq Er EAGAIN The socket is marked non-blocking and the receive operation would block, or diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 2eb9db632a11..b0661c0d0daf 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -2547,9 +2547,8 @@ unp_externalize(struct mbuf *control, struct mbuf **controlp, int flags) fdp = (int *) CMSG_DATA(mtod(*controlp, struct cmsghdr *)); - if (fdallocn(td, 0, fdp, newfds) != 0) { + if ((error = fdallocn(td, 0, fdp, newfds))) { FILEDESC_XUNLOCK(fdesc); - error = EMSGSIZE; unp_freerights(fdep, newfds); m_freem(*controlp); *controlp = NULL; diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c index bbd298f9a26f..dc017db4f1ce 100644 --- a/tests/sys/kern/unix_passfd_test.c +++ b/tests/sys/kern/unix_passfd_test.c @@ -428,8 +428,8 @@ ATF_TC_BODY(send_a_lot, tc) msghdr.msg_controllen = CMSG_LEN(sizeof(int)); ATF_REQUIRE(sendmsg(fd[0], &msghdr, 0) == 1); ATF_REQUIRE(recvmsg(fd[1], &msghdr, 0) == -1); - /* Such attempt shall fail with EMSGSIZE. */ - ATF_REQUIRE(errno == EMSGSIZE); + /* Such attempt shall fail with EMFILE. */ + ATF_REQUIRE(errno == EMFILE); ATF_REQUIRE(getnfds() == nfds); #if TEST_PROTO == SOCK_STREAM /*