ktrace: use the limit of the trace initiator for file size limit on writes
Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30257
This commit is contained in:
parent
1762f674cc
commit
02645b886b
@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/namei.h>
|
||||
#include <sys/priv.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/socket.h>
|
||||
@ -148,6 +149,7 @@ static struct sx ktrace_sx;
|
||||
struct ktr_io_params {
|
||||
struct vnode *vp;
|
||||
struct ucred *cr;
|
||||
off_t lim;
|
||||
u_int refs;
|
||||
};
|
||||
|
||||
@ -465,6 +467,7 @@ ktr_io_params_alloc(struct thread *td, struct vnode *vp)
|
||||
res = malloc(sizeof(struct ktr_io_params), M_KTRACE, M_WAITOK);
|
||||
res->vp = vp;
|
||||
res->cr = crhold(td->td_ucred);
|
||||
res->lim = lim_cur(td, RLIMIT_FSIZE);
|
||||
res->refs = 1;
|
||||
return (res);
|
||||
}
|
||||
@ -1255,6 +1258,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req)
|
||||
struct uio auio;
|
||||
struct iovec aiov[3];
|
||||
struct mount *mp;
|
||||
off_t lim;
|
||||
int datalen, buflen;
|
||||
int error;
|
||||
|
||||
@ -1282,6 +1286,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req)
|
||||
|
||||
vp = kiop->vp;
|
||||
cred = kiop->cr;
|
||||
lim = kiop->lim;
|
||||
|
||||
vrefact(vp);
|
||||
KASSERT(cred != NULL, ("ktr_writerequest: cred == NULL"));
|
||||
@ -1319,6 +1324,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req)
|
||||
|
||||
vn_start_write(vp, &mp, V_WAIT);
|
||||
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
||||
td->td_ktr_io_lim = lim;
|
||||
#ifdef MAC
|
||||
error = mac_vnode_check_write(cred, NOCRED, vp);
|
||||
if (error == 0)
|
||||
|
@ -2359,18 +2359,20 @@ int
|
||||
vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio,
|
||||
struct thread *td)
|
||||
{
|
||||
off_t lim;
|
||||
|
||||
if (vp->v_type != VREG || td == NULL ||
|
||||
(td->td_pflags2 & TDP2_ACCT) != 0)
|
||||
return (0);
|
||||
if ((uoff_t)uio->uio_offset + uio->uio_resid >
|
||||
lim_cur(td, RLIMIT_FSIZE)) {
|
||||
PROC_LOCK(td->td_proc);
|
||||
kern_psignal(td->td_proc, SIGXFSZ);
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
return (EFBIG);
|
||||
}
|
||||
return (0);
|
||||
ktr_write = (td->td_pflags & TDP_INKTRACE) != 0;
|
||||
lim = ktr_write ? td->td_ktr_io_lim : lim_cur(td, RLIMIT_FSIZE);
|
||||
if ((uoff_t)uio->uio_offset + uio->uio_resid < lim)
|
||||
return (0);
|
||||
|
||||
PROC_LOCK(td->td_proc);
|
||||
kern_psignal(td->td_proc, SIGXFSZ);
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
return (EFBIG);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -378,6 +378,7 @@ struct thread {
|
||||
void *td_lkpi_task; /* LinuxKPI task struct pointer */
|
||||
int td_pmcpend;
|
||||
void *td_coredump; /* (c) coredump request. */
|
||||
off_t td_ktr_io_lim; /* (k) limit for ktrace file size */
|
||||
#ifdef EPOCH_TRACE
|
||||
SLIST_HEAD(, epoch_tracker) td_epochs;
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user