From owner-svn-src-stable@freebsd.org Tue Nov 27 17:00:48 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A9D0D11543CB; Tue, 27 Nov 2018 17:00:48 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49FA186B50; Tue, 27 Nov 2018 17:00:48 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2B1051E1D9; Tue, 27 Nov 2018 17:00:48 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wARH0mXC045812; Tue, 27 Nov 2018 17:00:48 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wARH0lY5045808; Tue, 27 Nov 2018 17:00:47 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201811271700.wARH0lY5045808@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 27 Nov 2018 17:00:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r341079 - in stable/12: lib/libnv lib/libnv/tests sys/contrib/libnv X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12: lib/libnv lib/libnv/tests sys/contrib/libnv X-SVN-Commit-Revision: 341079 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 49FA186B50 X-Spamd-Result: default: False [1.18 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_SPAM_LONG(0.49)[0.488,0]; NEURAL_SPAM_SHORT(0.02)[0.019,0]; NEURAL_SPAM_MEDIUM(0.68)[0.676,0] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Nov 2018 17:00:49 -0000 Author: markj Date: Tue Nov 27 17:00:47 2018 New Revision: 341079 URL: https://svnweb.freebsd.org/changeset/base/341079 Log: MFC r340408: Ensure that libnv can be used when kern.trap_enotcap=1. Modified: stable/12/lib/libnv/common_impl.h stable/12/lib/libnv/msgio.c stable/12/lib/libnv/tests/nvlist_send_recv_test.c stable/12/sys/contrib/libnv/nvpair.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/libnv/common_impl.h ============================================================================== --- stable/12/lib/libnv/common_impl.h Tue Nov 27 16:59:12 2018 (r341078) +++ stable/12/lib/libnv/common_impl.h Tue Nov 27 17:00:47 2018 (r341079) @@ -34,6 +34,15 @@ #ifndef _COMMON_IMPL_H_ #define _COMMON_IMPL_H_ -#define fd_is_valid(fd) (fcntl((fd), F_GETFL) != -1 || errno != EBADF) +#include +#include +#include + +static inline bool +fd_is_valid(int fd) +{ + + return (fcntl(fd, F_GETFD) != -1 || errno != EBADF); +} #endif /* !_COMMON_IMPL_H_ */ Modified: stable/12/lib/libnv/msgio.c ============================================================================== --- stable/12/lib/libnv/msgio.c Tue Nov 27 16:59:12 2018 (r341078) +++ stable/12/lib/libnv/msgio.c Tue Nov 27 17:00:47 2018 (r341079) @@ -66,11 +66,6 @@ msghdr_add_fd(struct cmsghdr *cmsg, int fd) PJDLOG_ASSERT(fd >= 0); - if (!fd_is_valid(fd)) { - errno = EBADF; - return (-1); - } - cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); Modified: stable/12/lib/libnv/tests/nvlist_send_recv_test.c ============================================================================== --- stable/12/lib/libnv/tests/nvlist_send_recv_test.c Tue Nov 27 16:59:12 2018 (r341078) +++ stable/12/lib/libnv/tests/nvlist_send_recv_test.c Tue Nov 27 17:00:47 2018 (r341079) @@ -306,15 +306,12 @@ parent(int sock) CHECK(name == NULL); } -int -main(void) +static void +send_nvlist(void) { int status, socks[2]; pid_t pid; - printf("1..134\n"); - fflush(stdout); - if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0) err(1, "socketpair() failed"); pid = fork(); @@ -326,7 +323,7 @@ main(void) /* Child. */ close(socks[0]); child(socks[1]); - return (0); + _exit(0); default: /* Parent. */ close(socks[1]); @@ -336,6 +333,35 @@ main(void) if (waitpid(pid, &status, 0) < 0) err(1, "waitpid() failed"); +} + +static void +send_closed_fd(void) +{ + nvlist_t *nvl; + int error, socks[2]; + + if (socketpair(PF_UNIX, SOCK_STREAM, 0, socks) < 0) + err(1, "socketpair() failed"); + + nvl = nvlist_create(0); + nvlist_add_descriptor(nvl, "fd", 12345); + error = nvlist_error(nvl); + CHECK(error == EBADF); + + error = nvlist_send(socks[1], nvl); + CHECK(error != 0 && errno == EBADF); +} + +int +main(void) +{ + + printf("1..136\n"); + fflush(stdout); + + send_nvlist(); + send_closed_fd(); return (0); } Modified: stable/12/sys/contrib/libnv/nvpair.c ============================================================================== --- stable/12/sys/contrib/libnv/nvpair.c Tue Nov 27 16:59:12 2018 (r341078) +++ stable/12/sys/contrib/libnv/nvpair.c Tue Nov 27 17:00:47 2018 (r341079) @@ -1276,11 +1276,6 @@ nvpair_create_descriptor(const char *name, int value) { nvpair_t *nvp; - if (value < 0 || !fd_is_valid(value)) { - ERRNO_SET(EBADF); - return (NULL); - } - value = fcntl(value, F_DUPFD_CLOEXEC, 0); if (value < 0) return (NULL); @@ -1517,11 +1512,6 @@ nvpair_create_descriptor_array(const char *name, const if (value[ii] == -1) { fds[ii] = -1; } else { - if (!fd_is_valid(value[ii])) { - ERRNO_SET(EBADF); - goto fail; - } - fds[ii] = fcntl(value[ii], F_DUPFD_CLOEXEC, 0); if (fds[ii] == -1) goto fail; @@ -2035,10 +2025,6 @@ nvpair_append_descriptor_array(nvpair_t *nvp, const in NVPAIR_ASSERT(nvp); PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR_ARRAY); - if (value < 0 || !fd_is_valid(value)) { - ERRNO_SET(EBADF); - return -1; - } fd = fcntl(value, F_DUPFD_CLOEXEC, 0); if (fd == -1) { return (-1);