Module Name:    src
Committed By:   dholland
Date:           Wed Jun 30 17:51:49 UTC 2021

Modified Files:
        src/sys/kern: vfs_vnops.c

Log Message:
Improve Christos's vn_open fix.

- assert about api misuse up front (suggested by riastradh)
- restore the behavior of returning EOPNOTSUPP if ret_fd is NULL and we
  get a fd back (otherwise things like ktruss -o /dev/stderr panic)
- clear error to 0 for the EDUPFD and EMOVEFD cases so opening a
  cloner succeeds


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/sys/kern/vfs_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_vnops.c
diff -u src/sys/kern/vfs_vnops.c:1.217 src/sys/kern/vfs_vnops.c:1.218
--- src/sys/kern/vfs_vnops.c:1.217	Wed Jun 30 11:20:32 2021
+++ src/sys/kern/vfs_vnops.c	Wed Jun 30 17:51:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_vnops.c,v 1.217 2021/06/30 11:20:32 christos Exp $	*/
+/*	$NetBSD: vfs_vnops.c,v 1.218 2021/06/30 17:51:49 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.217 2021/06/30 11:20:32 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.218 2021/06/30 17:51:49 dholland Exp $");
 
 #include "veriexec.h"
 
@@ -173,6 +173,9 @@ vn_open(struct vnode *at_dvp, struct pat
 
 	KASSERT((nmode & (TRYEMULROOT | NOCHROOT)) == nmode);
 
+	KASSERT(ret_vp != NULL);
+	KASSERT((ret_domove == NULL) == (ret_fd == NULL));
+
 	if ((fmode & (O_CREAT | O_DIRECTORY)) == (O_CREAT | O_DIRECTORY))
 		return EINVAL;
 
@@ -332,9 +335,11 @@ out:
 	case EDUPFD:
 	case EMOVEFD:
 		/* if the caller isn't prepared to handle fds, fail for them */
-		KASSERTMSG(ret_domove && ret_fd,
-		    "caller did not supply ret_domove and ret_fd for %d",
-		    error);
+		if (ret_fd == NULL) {
+			error = EOPNOTSUPP;
+			break;
+		}
+		error = 0;
 		*ret_vp = NULL;
 		*ret_domove = error == EMOVEFD;
 		*ret_fd = l->l_dupfd;

Reply via email to