Module Name:    src
Committed By:   riastradh
Date:           Fri Dec  6 16:19:41 UTC 2024

Modified Files:
        src/sys/kern: exec_aout.c exec_ecoff.c exec_elf.c exec_elf32.c
            exec_elf64.c exec_script.c exec_subr.c kern_exec.c

Log Message:
sys/kern/kern_exec.c, exec_*.c: Sprinkle SET_ERROR dtrace probes.

PR kern/58378: Kernel error code origination lacks dtrace probes


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/kern/exec_aout.c
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/exec_ecoff.c
cvs rdiff -u -r1.106 -r1.107 src/sys/kern/exec_elf.c
cvs rdiff -u -r1.143 -r1.144 src/sys/kern/exec_elf32.c
cvs rdiff -u -r1.8 -r1.9 src/sys/kern/exec_elf64.c
cvs rdiff -u -r1.84 -r1.85 src/sys/kern/exec_script.c
cvs rdiff -u -r1.89 -r1.90 src/sys/kern/exec_subr.c
cvs rdiff -u -r1.523 -r1.524 src/sys/kern/kern_exec.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/exec_aout.c
diff -u src/sys/kern/exec_aout.c:1.42 src/sys/kern/exec_aout.c:1.43
--- src/sys/kern/exec_aout.c:1.42	Fri Dec  6 16:18:41 2024
+++ src/sys/kern/exec_aout.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_aout.c,v 1.42 2024/12/06 16:18:41 riastradh Exp $	*/
+/*	$NetBSD: exec_aout.c,v 1.43 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_aout.c,v 1.42 2024/12/06 16:18:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_aout.c,v 1.43 2024/12/06 16:19:41 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: exec_aout.c,
 #include <sys/module.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
+#include <sys/sdt.h>
 #include <sys/systm.h>
 #include <sys/vnode.h>
 
@@ -75,7 +76,7 @@ exec_aout_modcmd(modcmd_t cmd, void *arg
 		return exec_remove(&exec_aout_execsw, 1);
 
 	default:
-		return ENOTTY;
+		return SET_ERROR(ENOTTY);
         }
 }
 
@@ -100,7 +101,7 @@ exec_aout_makecmds(struct lwp *l, struct
 	struct exec *execp = epp->ep_hdr;
 
 	if (epp->ep_hdrvalid < sizeof(struct exec))
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 
 	midmag = ntohl(execp->a_midmag);
 	mid = (midmag >> 16) & 0x3ff;

Index: src/sys/kern/exec_ecoff.c
diff -u src/sys/kern/exec_ecoff.c:1.33 src/sys/kern/exec_ecoff.c:1.34
--- src/sys/kern/exec_ecoff.c:1.33	Fri Dec  6 16:18:41 2024
+++ src/sys/kern/exec_ecoff.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_ecoff.c,v 1.33 2024/12/06 16:18:41 riastradh Exp $	*/
+/*	$NetBSD: exec_ecoff.c,v 1.34 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1994 Adam Glass
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_ecoff.c,v 1.33 2024/12/06 16:18:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_ecoff.c,v 1.34 2024/12/06 16:19:41 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: exec_ecoff.c
 #include <sys/module.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
+#include <sys/sdt.h>
 #include <sys/systm.h>
 #include <sys/vnode.h>
 
@@ -75,7 +76,7 @@ exec_ecoff_modcmd(modcmd_t cmd, void *ar
 		return exec_remove(&exec_ecoff_execsw, 1);
 
 	default:
-		return ENOTTY;
+		return SET_ERROR(ENOTTY);
         }
 }
 
@@ -97,10 +98,10 @@ exec_ecoff_makecmds(struct lwp *l, struc
 	struct ecoff_exechdr *execp = epp->ep_hdr;
 
 	if (epp->ep_hdrvalid < ECOFF_HDR_SIZE)
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 
 	if (ECOFF_BADMAG(execp))
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 
 	error = (*epp->ep_esch->u.ecoff_probe_func)(l, epp);
 
@@ -130,7 +131,7 @@ exec_ecoff_makecmds(struct lwp *l, struc
 		   epp->ep_vp);
 		break;
 	default:
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	/* set up the stack */

Index: src/sys/kern/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.106 src/sys/kern/exec_elf.c:1.107
--- src/sys/kern/exec_elf.c:1.106	Fri Dec  6 16:18:41 2024
+++ src/sys/kern/exec_elf.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf.c,v 1.106 2024/12/06 16:18:41 riastradh Exp $	*/
+/*	$NetBSD: exec_elf.c,v 1.107 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1994, 2000, 2005, 2015, 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.106 2024/12/06 16:18:41 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.107 2024/12/06 16:19:41 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -76,6 +76,7 @@ __KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v
 #include <sys/namei.h>
 #include <sys/pax.h>
 #include <sys/proc.h>
+#include <sys/sdt.h>
 #include <sys/signalvar.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
@@ -140,7 +141,7 @@ elf_placedynexec(struct exec_package *ep
 	if ((offset & (align - 1)) != 0) {
 		DPRINTF("bad offset=%#jx align=%#jx",
 		    (uintmax_t)offset, (uintmax_t)align);
-		return EINVAL;
+		return SET_ERROR(EINVAL);
 	}
 
 	for (i = 0; i < eh->e_phnum; i++)
@@ -292,7 +293,7 @@ elf_check_header(Elf_Ehdr *eh)
 		    "e_ident[EI_CLASS] %#x", eh->e_ident[EI_MAG0],
 		    eh->e_ident[EI_MAG1], eh->e_ident[EI_MAG2],
 		    eh->e_ident[EI_MAG3], eh->e_ident[EI_CLASS]);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	switch (eh->e_machine) {
@@ -301,17 +302,17 @@ elf_check_header(Elf_Ehdr *eh)
 
 	default:
 		DPRINTF("bad machine %#x", eh->e_machine);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	if (ELF_EHDR_FLAGS_OK(eh) == 0) {
 		DPRINTF("bad flags %#x", eh->e_flags);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	if (eh->e_shnum > ELF_MAXSHNUM || eh->e_phnum > ELF_MAXPHNUM) {
 		DPRINTF("bad shnum/phnum %#x/%#x", eh->e_shnum, eh->e_phnum);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	return 0;
@@ -347,7 +348,7 @@ elf_load_psection(struct exec_vmcmd_set 
 			DPRINTF("bad alignment %#jx != %#jx\n",
 			    (uintptr_t)(*addr - diff),
 			    (uintptr_t)ELF_TRUNC(*addr, ph->p_align));
-			return EINVAL;
+			return SET_ERROR(EINVAL);
 		}
 		/*
 		 * But make sure to not map any pages before the start of the
@@ -462,7 +463,7 @@ elf_load_interp(struct lwp *l, struct ex
 	 * file, we don't allow it to be used.
 	 */
 	if (vp->v_type != VREG) {
-		error = EACCES;
+		error = SET_ERROR(EACCES);
 		goto bad;
 	}
 	if ((error = VOP_ACCESS(vp, VEXEC, l->l_cred)) != 0)
@@ -474,7 +475,7 @@ elf_load_interp(struct lwp *l, struct ex
 	 * disallows execution or set-id-ness, we punt or kill the set-id.
 	 */
 	if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
-		error = EACCES;
+		error = SET_ERROR(EACCES);
 		goto bad;
 	}
 	if (vp->v_mount->mnt_flag & MNT_NOSUID)
@@ -492,7 +493,7 @@ elf_load_interp(struct lwp *l, struct ex
 		goto bad;
 	if (eh.e_type != ET_DYN || eh.e_phnum == 0) {
 		DPRINTF("bad interpreter type %#x", eh.e_type);
-		error = ENOEXEC;
+		error = SET_ERROR(ENOEXEC);
 		goto bad;
 	}
 
@@ -538,7 +539,7 @@ elf_load_interp(struct lwp *l, struct ex
 
 		if (base_ph == NULL) {
 			DPRINTF("no interpreter loadable sections");
-			error = ENOEXEC;
+			error = SET_ERROR(ENOEXEC);
 			goto bad;
 		}
 
@@ -659,7 +660,7 @@ exec_elf_makecmds(struct lwp *l, struct 
 
 	if (epp->ep_hdrvalid < sizeof(Elf_Ehdr)) {
 		DPRINTF("small header %#x", epp->ep_hdrvalid);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 	if ((error = elf_check_header(eh)) != 0)
 		return error;
@@ -669,12 +670,12 @@ exec_elf_makecmds(struct lwp *l, struct 
 		is_dyn = true;
 	else if (eh->e_type != ET_EXEC) {
 		DPRINTF("bad type %#x", eh->e_type);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	if (eh->e_phnum == 0) {
 		DPRINTF("no program headers");
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	/* XXX only LK_EXCLUSIVE to match all others - allow spinning */
@@ -708,7 +709,7 @@ exec_elf_makecmds(struct lwp *l, struct 
 			if (pp->p_filesz < 2 || pp->p_filesz > MAXPATHLEN) {
 				DPRINTF("bad interpreter namelen %#jx",
 				    (uintmax_t)pp->p_filesz);
-				error = ENOEXEC;
+				error = SET_ERROR(ENOEXEC);
 				VOP_UNLOCK(epp->ep_vp);
 				goto bad;
 			}
@@ -722,7 +723,7 @@ exec_elf_makecmds(struct lwp *l, struct 
 			/* Ensure interp is NUL-terminated and of the expected length */
 			if (strnlen(interp, pp->p_filesz) != pp->p_filesz - 1) {
 				DPRINTF("bad interpreter name");
-				error = ENOEXEC;
+				error = SET_ERROR(ENOEXEC);
 				VOP_UNLOCK(epp->ep_vp);
 				goto bad;
 			}
@@ -820,7 +821,7 @@ exec_elf_makecmds(struct lwp *l, struct 
 		/* No VMCMD; there was no PT_LOAD section, or those
 		 * sections were empty */
 		DPRINTF("no vmcommands");
-		error = ENOEXEC;
+		error = SET_ERROR(ENOEXEC);
 		goto bad;
 	}
 
@@ -844,7 +845,7 @@ exec_elf_makecmds(struct lwp *l, struct 
 		if (epp->ep_vmcmds.evs_used == nused) {
 			/* elf_load_interp() has not set up any new VMCMD */
 			DPRINTF("no vmcommands for interpreter");
-			error = ENOEXEC;
+			error = SET_ERROR(ENOEXEC);
 			goto bad;
 		}
 
@@ -910,7 +911,7 @@ netbsd_elf_signature(struct lwp *l, stru
 
 	if (eh->e_phnum > ELF_MAXPHNUM || eh->e_phnum == 0) {
 		DPRINTF("no signature %#x", eh->e_phnum);
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	}
 
 	phsize = eh->e_phnum * sizeof(Elf_Phdr);
@@ -969,7 +970,7 @@ netbsd_elf_signature(struct lwp *l, stru
 	}
 	kmem_free(nbuf, ELF_MAXNOTESIZE);
 
-	error = isnetbsd ? 0 : ENOEXEC;
+	error = isnetbsd ? 0 : SET_ERROR(ENOEXEC);
 #ifdef DEBUG_ELF
 	if (error)
 		DPRINTF("not netbsd");

Index: src/sys/kern/exec_elf32.c
diff -u src/sys/kern/exec_elf32.c:1.143 src/sys/kern/exec_elf32.c:1.144
--- src/sys/kern/exec_elf32.c:1.143	Wed Nov 20 19:37:53 2019
+++ src/sys/kern/exec_elf32.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf32.c,v 1.143 2019/11/20 19:37:53 pgoyette Exp $	*/
+/*	$NetBSD: exec_elf32.c,v 1.144 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_elf32.c,v 1.143 2019/11/20 19:37:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_elf32.c,v 1.144 2024/12/06 16:19:41 riastradh Exp $");
 
 #define	ELFSIZE	32
 
@@ -100,7 +100,7 @@ exec_elf32_modcmd(modcmd_t cmd, void *ar
 	case MODULE_CMD_FINI:
 		return 0;
 	default:
-		return ENOTTY;
+		return SET_ERROR(ENOTTY);
 	}
 #else /* ARCH_ELFSIZE == 64 */
 	switch (cmd) {
@@ -113,7 +113,7 @@ exec_elf32_modcmd(modcmd_t cmd, void *ar
 		    __arraycount(exec_elf32_execsw));
 
 	default:
-		return ENOTTY;
+		return SET_ERROR(ENOTTY);
         }
 #endif /* ARCH_ELFSIZE == 64 */
 }

Index: src/sys/kern/exec_elf64.c
diff -u src/sys/kern/exec_elf64.c:1.8 src/sys/kern/exec_elf64.c:1.9
--- src/sys/kern/exec_elf64.c:1.8	Wed Nov 20 19:37:53 2019
+++ src/sys/kern/exec_elf64.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_elf64.c,v 1.8 2019/11/20 19:37:53 pgoyette Exp $	*/
+/*	$NetBSD: exec_elf64.c,v 1.9 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_elf64.c,v 1.8 2019/11/20 19:37:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_elf64.c,v 1.9 2024/12/06 16:19:41 riastradh Exp $");
 
 #define	ELFSIZE	64
 
@@ -94,6 +94,6 @@ exec_elf64_modcmd(modcmd_t cmd, void *ar
 		    __arraycount(exec_elf64_execsw));
 
 	default:
-		return ENOTTY;
+		return SET_ERROR(ENOTTY);
         }
 }

Index: src/sys/kern/exec_script.c
diff -u src/sys/kern/exec_script.c:1.84 src/sys/kern/exec_script.c:1.85
--- src/sys/kern/exec_script.c:1.84	Fri Dec  6 16:18:41 2024
+++ src/sys/kern/exec_script.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_script.c,v 1.84 2024/12/06 16:18:41 riastradh Exp $	*/
+/*	$NetBSD: exec_script.c,v 1.85 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.84 2024/12/06 16:18:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.85 2024/12/06 16:19:41 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_script.h"
@@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: exec_script.
 #include <sys/namei.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
+#include <sys/sdt.h>
 #ifdef SETUIDSCRIPTS
 #include <sys/stat.h>
 #endif
@@ -97,10 +98,10 @@ exec_script_modcmd(modcmd_t cmd, void *a
 		 * often.  Return EBUSY here to prevent this module from
 		 * ping-ponging in and out of the kernel.
 		 */
-		return EBUSY;
+		return SET_ERROR(EBUSY);
 
 	default:
-		return ENOTTY;
+		return SET_ERROR(ENOTTY);
 	}
 }
 
@@ -141,7 +142,7 @@ exec_script_makecmds(struct lwp *l, stru
 	if ((epp->ep_flags & EXEC_INDIR) != 0 ||
 	    epp->ep_hdrvalid < EXEC_SCRIPT_MAGICLEN ||
 	    strncmp(hdrstr, EXEC_SCRIPT_MAGIC, EXEC_SCRIPT_MAGICLEN))
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 
 	/*
 	 * Check that the shell spec is terminated by a newline, and that
@@ -156,14 +157,14 @@ exec_script_makecmds(struct lwp *l, stru
 		}
 	}
 	if (cp >= hdrstr + hdrlinelen)
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 
 	/* strip spaces before the shell name */
 	for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; *cp == ' ' || *cp == '\t';
 	    cp++)
 		;
 	if (*cp == '\0')
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 
 	shellarg = NULL;
 	shellarglen = 0;

Index: src/sys/kern/exec_subr.c
diff -u src/sys/kern/exec_subr.c:1.89 src/sys/kern/exec_subr.c:1.90
--- src/sys/kern/exec_subr.c:1.89	Fri Dec  6 16:18:41 2024
+++ src/sys/kern/exec_subr.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_subr.c,v 1.89 2024/12/06 16:18:41 riastradh Exp $	*/
+/*	$NetBSD: exec_subr.c,v 1.90 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.89 2024/12/06 16:18:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.90 2024/12/06 16:19:41 riastradh Exp $");
 
 #include "opt_pax.h"
 
@@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: exec_subr.c,
 #include <sys/pax.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
+#include <sys/sdt.h>
 #include <sys/systm.h>
 #include <sys/vnode.h>
 
@@ -170,7 +171,7 @@ vmcmd_get_prot(struct lwp *l, const stru
 	*maxprot = PAX_MPROTECT_MAXPROTECT(l, *prot, extraprot, UVM_PROT_ALL);
 
 	if ((*prot & *maxprot) != *prot)
-		return EACCES;
+		return SET_ERROR(EACCES);
 	return PAX_MPROTECT_VALIDATE(l, *prot);
 }
 
@@ -192,11 +193,11 @@ vmcmd_map_pagedvn(struct lwp *l, struct 
 	if (cmd->ev_len == 0)
 		return 0;
 	if (cmd->ev_offset & PAGE_MASK)
-		return EINVAL;
+		return SET_ERROR(EINVAL);
 	if (cmd->ev_addr & PAGE_MASK)
-		return EINVAL;
+		return SET_ERROR(EINVAL);
 	if (cmd->ev_len & PAGE_MASK)
-		return EINVAL;
+		return SET_ERROR(EINVAL);
 
 	if ((error = vmcmd_get_prot(l, cmd, &prot, &maxprot)) != 0)
 		return error;
@@ -368,7 +369,7 @@ exec_read(struct lwp *l, struct vnode *v
 	 * See if we got all of it
 	 */
 	if (resid != 0)
-		return ENOEXEC;
+		return SET_ERROR(ENOEXEC);
 	return 0;
 }
 

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.523 src/sys/kern/kern_exec.c:1.524
--- src/sys/kern/kern_exec.c:1.523	Fri Dec  6 16:18:41 2024
+++ src/sys/kern/kern_exec.c	Fri Dec  6 16:19:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.523 2024/12/06 16:18:41 riastradh Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.524 2024/12/06 16:19:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.523 2024/12/06 16:18:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.524 2024/12/06 16:19:41 riastradh Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -407,7 +407,7 @@ check_exec(struct lwp *l, struct exec_pa
 
 	/* check access and type */
 	if (vp->v_type != VREG) {
-		error = EACCES;
+		error = SET_ERROR(EACCES);
 		goto bad1;
 	}
 	if ((error = VOP_ACCESS(vp, VEXEC, l->l_cred)) != 0)
@@ -420,7 +420,7 @@ check_exec(struct lwp *l, struct exec_pa
 
 	/* Check mount point */
 	if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
-		error = EACCES;
+		error = SET_ERROR(EACCES);
 		goto bad1;
 	}
 	if (vp->v_mount->mnt_flag & MNT_NOSUID)
@@ -467,7 +467,7 @@ check_exec(struct lwp *l, struct exec_pa
 	 * set up the vmcmds for creation of the process
 	 * address space
 	 */
-	error = ENOEXEC;
+	error = nexecs == 0 ? SET_ERROR(ENOEXEC) : ENOEXEC;
 	for (i = 0; i < nexecs; i++) {
 		int newerror;
 
@@ -483,7 +483,7 @@ check_exec(struct lwp *l, struct exec_pa
 					 __func__, (void *)epp->ep_entry,
 					 (void *)epp->ep_vm_maxaddr);
 #endif
-				error = ENOEXEC;
+				error = SET_ERROR(ENOEXEC);
 				break;
 			}
 			/* Seems ok: check that entry point is not too low */
@@ -494,7 +494,7 @@ check_exec(struct lwp *l, struct exec_pa
 				     __func__, (void *)epp->ep_entry,
 				     (void *)epp->ep_vm_minaddr);
 #endif
-				error = ENOEXEC;
+				error = SET_ERROR(ENOEXEC);
 				break;
 			}
 
@@ -509,7 +509,7 @@ check_exec(struct lwp *l, struct exec_pa
 				    (uintmax_t)epp->ep_tsize,
 				    (uintmax_t)MAXTSIZ);
 #endif
-				error = ENOMEM;
+				error = SET_ERROR(ENOMEM);
 				break;
 			}
 #endif
@@ -521,7 +521,7 @@ check_exec(struct lwp *l, struct exec_pa
 				    (uintmax_t)epp->ep_dsize,
 				    (uintmax_t)dlimit);
 #endif
-				error = ENOMEM;
+				error = SET_ERROR(ENOMEM);
 				break;
 			}
 			return 0;
@@ -701,7 +701,7 @@ exec_makepathbuf(struct lwp *l, const ch
 
 	len++;
 	if (len + 1 >= MAXPATHLEN) {
-		error = ENAMETOOLONG;
+		error = SET_ERROR(ENAMETOOLONG);
 		goto err;
 	}
 	bp = path + MAXPATHLEN - len;
@@ -780,12 +780,12 @@ execve_loadvm(struct lwp *l, bool has_pa
  retry:
 	if (p->p_flag & PK_SUGID) {
 		if (kauth_authorize_process(l->l_cred, KAUTH_PROCESS_RLIMIT,
-		     p, KAUTH_ARG(KAUTH_REQ_PROCESS_RLIMIT_BYPASS),
-		     &p->p_rlimit[RLIMIT_NPROC],
-		     KAUTH_ARG(RLIMIT_NPROC)) != 0 &&
+			p, KAUTH_ARG(KAUTH_REQ_PROCESS_RLIMIT_BYPASS),
+			&p->p_rlimit[RLIMIT_NPROC],
+			KAUTH_ARG(RLIMIT_NPROC)) != 0 &&
 		    chgproccnt(kauth_cred_getuid(l->l_cred), 0) >
-		     p->p_rlimit[RLIMIT_NPROC].rlim_cur)
-		return EAGAIN;
+		    p->p_rlimit[RLIMIT_NPROC].rlim_cur)
+			return SET_ERROR(EAGAIN);
 	}
 
 	/*
@@ -886,7 +886,7 @@ execve_loadvm(struct lwp *l, bool has_pa
 	if (len > epp->ep_ssize) {
 		/* in effect, compare to initial limit */
 		DPRINTF(("%s: stack limit exceeded %zu\n", __func__, len));
-		error = ENOMEM;
+		error = SET_ERROR(ENOMEM);
 		goto bad;
 	}
 	/* adjust "active stack depth" for process VSZ */
@@ -1067,7 +1067,7 @@ credexec(struct lwp *l, struct execve_da
 			DPRINTF((
 			    "%s: not executing set[ug]id binary with no args\n",
 			    __func__));
-			return EINVAL;
+			return SET_ERROR(EINVAL);
 		}
 
 		/* Make sure file descriptors 0..2 are in use. */
@@ -1642,7 +1642,7 @@ copyinargs(struct execve_data * restrict
 				}
 				kmem_free(epp->ep_fa, epp->ep_fa_len);
 				epp->ep_flags &= ~EXEC_HASARGL;
-				return E2BIG;
+				return SET_ERROR(E2BIG);
 			}
 			ktrexecarg(fa->fa_arg, len - 1);
 			dp += len;
@@ -1661,7 +1661,7 @@ copyinargs(struct execve_data * restrict
 
 	if (args == NULL) {
 		DPRINTF(("%s: null args\n", __func__));
-		return EINVAL;
+		return SET_ERROR(EINVAL);
 	}
 	if (epp->ep_flags & EXEC_SKIPARG)
 		args = (const void *)((const char *)args + fromptrsz(epp));
@@ -1718,7 +1718,7 @@ copyinargstrs(struct execve_data * restr
 			break;
 		if ((error = copyinstr(sp, dp, maxlen, &len)) != 0) {
 			if (error == ENAMETOOLONG)
-				error = E2BIG;
+				error = SET_ERROR(E2BIG);
 			return error;
 		}
 		if (__predict_false(ktrace_on))
@@ -1835,7 +1835,7 @@ exec_add(struct execsw *esp, int count)
 			    esp[i].u.elf_probe_func &&
 			    it->ex_sw->es_emul == esp[i].es_emul) {
 				rw_exit(&exec_lock);
-				return EEXIST;
+				return SET_ERROR(EEXIST);
 			}
 		}
 	}
@@ -1893,7 +1893,7 @@ exec_remove(struct execsw *esp, int coun
 				if (p->p_execsw == &esp[i]) {
 					mutex_exit(&proc_lock);
 					rw_exit(&exec_lock);
-					return EBUSY;
+					return SET_ERROR(EBUSY);
 				}
 			}
 		}
@@ -2191,7 +2191,7 @@ handle_posix_spawn_file_actions(struct p
 			break;
 		case FAE_CLOSE:
 			if (fd_getfile(fae->fae_fildes) == NULL) {
-				return EBADF;
+				return SET_ERROR(EBADF);
 			}
 			error = fd_close(fae->fae_fildes);
 			break;
@@ -2477,7 +2477,7 @@ posix_spawn_fa_alloc(struct posix_spawn_
 
 	if (fa->len > lim) {
 		kmem_free(fa, sizeof(*fa));
-		return EINVAL;
+		return SET_ERROR(EINVAL);
 	}
 
 	fa->size = fa->len;
@@ -2537,7 +2537,7 @@ check_posix_spawn(struct lwp *l1)
 
 	if (error) {
 		atomic_dec_uint(&nprocs);
-		return EAGAIN;
+		return SET_ERROR(EAGAIN);
 	}
 
 	/*
@@ -2550,7 +2550,7 @@ check_posix_spawn(struct lwp *l1)
 	    __predict_false(count > p1->p_rlimit[RLIMIT_NPROC].rlim_cur)) {
 		(void)chgproccnt(uid, -1);
 		atomic_dec_uint(&nprocs);
-		return EAGAIN;
+		return SET_ERROR(EAGAIN);
 	}
 
 	return 0;
@@ -2601,7 +2601,7 @@ do_posix_spawn(struct lwp *l1, pid_t *pi
 	 */
 	uaddr = uvm_uarea_alloc();
 	if (__predict_false(uaddr == 0)) {
-		error = ENOMEM;
+		error = SET_ERROR(ENOMEM);
 		goto error_exit;
 	}
 	
@@ -2613,7 +2613,7 @@ do_posix_spawn(struct lwp *l1, pid_t *pi
 	p2 = proc_alloc();
 	if (p2 == NULL) {
 		/* We were unable to allocate a process ID. */
-		error = EAGAIN;
+		error = SET_ERROR(EAGAIN);
 		goto error_exit;
 	}
 

Reply via email to