Module Name: src
Committed By: martin
Date: Fri Sep 9 18:24:20 UTC 2022
Modified Files:
src/sys/kern [netbsd-8]: kern_core.c
Log Message:
Pull up following revision(s) (requested by christos in ticket #1760):
sys/kern/kern_core.c: revision 1.36
Don't forget to free the cred we just held.
Thanks to Chris J-D (chris at accessvector dot net)
While here, de-duplicate the mutex exit sequence.
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.24.10.1 src/sys/kern/kern_core.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/kern_core.c
diff -u src/sys/kern/kern_core.c:1.24 src/sys/kern/kern_core.c:1.24.10.1
--- src/sys/kern/kern_core.c:1.24 Thu Jul 7 06:55:43 2016
+++ src/sys/kern/kern_core.c Fri Sep 9 18:24:20 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_core.c,v 1.24 2016/07/07 06:55:43 msaitoh Exp $ */
+/* $NetBSD: kern_core.c,v 1.24.10.1 2022/09/09 18:24:20 martin Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.24 2016/07/07 06:55:43 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.24.10.1 2022/09/09 18:24:20 martin Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
@@ -95,7 +95,7 @@ coredump(struct lwp *l, const char *patt
struct vnode *vp;
struct proc *p;
struct vmspace *vm;
- kauth_cred_t cred;
+ kauth_cred_t cred = NULL;
struct pathbuf *pb;
struct nameidata nd;
struct vattr vattr;
@@ -120,9 +120,7 @@ coredump(struct lwp *l, const char *patt
if (USPACE + ctob(vm->vm_dsize + vm->vm_ssize) >=
p->p_rlimit[RLIMIT_CORE].rlim_cur) {
error = EFBIG; /* better error code? */
- mutex_exit(p->p_lock);
- mutex_exit(proc_lock);
- goto done;
+ goto release;
}
/*
@@ -139,9 +137,7 @@ coredump(struct lwp *l, const char *patt
if (p->p_flag & PK_SUGID) {
if (!security_setidcore_dump) {
error = EPERM;
- mutex_exit(p->p_lock);
- mutex_exit(proc_lock);
- goto done;
+ goto release;
}
pattern = security_setidcore_path;
}
@@ -155,11 +151,8 @@ coredump(struct lwp *l, const char *patt
error = coredump_buildname(p, name, pattern, MAXPATHLEN);
mutex_exit(&lim->pl_lock);
- if (error) {
- mutex_exit(p->p_lock);
- mutex_exit(proc_lock);
- goto done;
- }
+ if (error)
+ goto release;
/*
* On a simple filename, see if the filesystem allow us to write
@@ -173,6 +166,7 @@ coredump(struct lwp *l, const char *patt
error = EPERM;
}
+release:
mutex_exit(p->p_lock);
mutex_exit(proc_lock);
if (error)
@@ -260,6 +254,8 @@ coredump(struct lwp *l, const char *patt
if (error == 0)
error = error1;
done:
+ if (cred != NULL)
+ kauth_cred_free(cred);
if (name != NULL)
PNBUF_PUT(name);
return error;