From b518a50dd136bcaef2ad5988c1fe53f954d5ae5e Mon Sep 17 00:00:00 2001 From: kevans Date: Sat, 7 Nov 2020 03:28:32 +0000 Subject: [PATCH] imgact_binmisc: minor re-organization of imgact_binmisc_exec exits Notably, streamline error paths through the existing 'done' label, making it easier to quickly verify correct cleanup. Future work might add a kernel-only flag to indicate that a interpreter uses #a. Currently, all executions via imgact_binmisc pay the penalty of constructing sname/fname, even if they will not use it. qemu-user-static doesn't need it, the stock rc script for qemu-user-static certainly doesn't use it, and I suspect these are the vast majority of (if not the only) current users. MFC after: 1 week --- sys/kern/imgact_binmisc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sys/kern/imgact_binmisc.c b/sys/kern/imgact_binmisc.c index 082dd3076b5e..af8f78cee59b 100644 --- a/sys/kern/imgact_binmisc.c +++ b/sys/kern/imgact_binmisc.c @@ -580,24 +580,24 @@ imgact_binmisc_exec(struct image_params *imgp) struct sbuf *sname; char *s, *d; + sname = NULL; /* Do we have an interpreter for the given image header? */ sx_slock(&interp_list_sx); if ((ibe = imgact_binmisc_find_interpreter(image_header)) == NULL) { - sx_sunlock(&interp_list_sx); - return (-1); + error = -1; + goto done; } /* No interpreter nesting allowed. */ if (imgp->interpreted & IMGACT_BINMISC) { - sx_sunlock(&interp_list_sx); - return (ENOEXEC); + error = ENOEXEC; + goto done; } imgp->interpreted |= IMGACT_BINMISC; if (imgp->args->fname != NULL) { fname = imgp->args->fname; - sname = NULL; } else { /* Use the fdescfs(5) path for fexecve(2). */ sname = sbuf_new_auto(); @@ -636,7 +636,6 @@ imgact_binmisc_exec(struct image_params *imgp) default: /* Hmm... This shouldn't happen. */ - sx_sunlock(&interp_list_sx); printf("%s: Unknown macro #%c sequence in " "interpreter string\n", KMOD_NAME, *(s + 1)); error = EINVAL; @@ -648,7 +647,6 @@ imgact_binmisc_exec(struct image_params *imgp) /* Make room for the interpreter */ error = exec_args_adjust_args(imgp->args, 0, offset); if (error != 0) { - sx_sunlock(&interp_list_sx); goto done; } @@ -698,11 +696,11 @@ imgact_binmisc_exec(struct image_params *imgp) s++; } *d = '\0'; - sx_sunlock(&interp_list_sx); imgp->interpreter_name = imgp->args->begin_argv; done: + sx_sunlock(&interp_list_sx); if (sname) sbuf_delete(sname); return (error);