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
This commit is contained in:
Kyle Evans 2020-11-07 03:28:32 +00:00
parent e25d8b67c3
commit 80083216cb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367439

View File

@ -580,24 +580,24 @@ imgact_binmisc_exec(struct image_params *imgp)
struct sbuf *sname; struct sbuf *sname;
char *s, *d; char *s, *d;
sname = NULL;
/* Do we have an interpreter for the given image header? */ /* Do we have an interpreter for the given image header? */
sx_slock(&interp_list_sx); sx_slock(&interp_list_sx);
if ((ibe = imgact_binmisc_find_interpreter(image_header)) == NULL) { if ((ibe = imgact_binmisc_find_interpreter(image_header)) == NULL) {
sx_sunlock(&interp_list_sx); error = -1;
return (-1); goto done;
} }
/* No interpreter nesting allowed. */ /* No interpreter nesting allowed. */
if (imgp->interpreted & IMGACT_BINMISC) { if (imgp->interpreted & IMGACT_BINMISC) {
sx_sunlock(&interp_list_sx); error = ENOEXEC;
return (ENOEXEC); goto done;
} }
imgp->interpreted |= IMGACT_BINMISC; imgp->interpreted |= IMGACT_BINMISC;
if (imgp->args->fname != NULL) { if (imgp->args->fname != NULL) {
fname = imgp->args->fname; fname = imgp->args->fname;
sname = NULL;
} else { } else {
/* Use the fdescfs(5) path for fexecve(2). */ /* Use the fdescfs(5) path for fexecve(2). */
sname = sbuf_new_auto(); sname = sbuf_new_auto();
@ -636,7 +636,6 @@ imgact_binmisc_exec(struct image_params *imgp)
default: default:
/* Hmm... This shouldn't happen. */ /* Hmm... This shouldn't happen. */
sx_sunlock(&interp_list_sx);
printf("%s: Unknown macro #%c sequence in " printf("%s: Unknown macro #%c sequence in "
"interpreter string\n", KMOD_NAME, *(s + 1)); "interpreter string\n", KMOD_NAME, *(s + 1));
error = EINVAL; error = EINVAL;
@ -648,7 +647,6 @@ imgact_binmisc_exec(struct image_params *imgp)
/* Make room for the interpreter */ /* Make room for the interpreter */
error = exec_args_adjust_args(imgp->args, 0, offset); error = exec_args_adjust_args(imgp->args, 0, offset);
if (error != 0) { if (error != 0) {
sx_sunlock(&interp_list_sx);
goto done; goto done;
} }
@ -698,11 +696,11 @@ imgact_binmisc_exec(struct image_params *imgp)
s++; s++;
} }
*d = '\0'; *d = '\0';
sx_sunlock(&interp_list_sx);
imgp->interpreter_name = imgp->args->begin_argv; imgp->interpreter_name = imgp->args->begin_argv;
done: done:
sx_sunlock(&interp_list_sx);
if (sname) if (sname)
sbuf_delete(sname); sbuf_delete(sname);
return (error); return (error);