Instead of caching the PID which opened the bpf descriptor, continuously
refresh the PID which has the descriptor open. The PID is refreshed in various operations like ioctl(2), kevent(2) or poll(2). This produces more accurate information about current bpf consumers. While we are here remove the bd_pcomm member of the bpf stats structure because now that we have an accurate PID we can lookup the via the kern.proc.pid sysctl variable. This is the trick that NetBSD decided to use to deal with this issue. Special care needs to be taken when MFC'ing this change, as we have made a change to the bpf stats structure. What will end up happening is we will leave the pcomm structure but just mark it as being un-used. This way we keep the ABI in tact. MFC after: 1 month Discussed with: Rui Paulo < rpaulo at NetBSD dot org >
This commit is contained in:
parent
d536ff2edb
commit
b75a24a075
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149809
@ -390,7 +390,6 @@ bpfopen(dev, flags, fmt, td)
|
||||
d->bd_sig = SIGIO;
|
||||
d->bd_seesent = 1;
|
||||
d->bd_pid = td->td_proc->p_pid;
|
||||
strlcpy(d->bd_pcomm, td->td_proc->p_comm, MAXCOMLEN);
|
||||
#ifdef MAC
|
||||
mac_init_bpfdesc(d);
|
||||
mac_create_bpfdesc(td->td_ucred, d);
|
||||
@ -694,6 +693,10 @@ bpfioctl(dev, cmd, addr, flags, td)
|
||||
struct bpf_d *d = dev->si_drv1;
|
||||
int error = 0;
|
||||
|
||||
/*
|
||||
* Refresh PID associated with this descriptor.
|
||||
*/
|
||||
d->bd_pid = td->td_proc->p_pid;
|
||||
BPFD_LOCK(d);
|
||||
if (d->bd_state == BPF_WAITING)
|
||||
callout_stop(&d->bd_callout);
|
||||
@ -1141,6 +1144,10 @@ bpfpoll(dev, events, td)
|
||||
if (d->bd_bif == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
/*
|
||||
* Refresh PID associated with this descriptor.
|
||||
*/
|
||||
d->bd_pid = td->td_proc->p_pid;
|
||||
revents = events & (POLLOUT | POLLWRNORM);
|
||||
BPFD_LOCK(d);
|
||||
if (events & (POLLIN | POLLRDNORM)) {
|
||||
@ -1174,6 +1181,10 @@ bpfkqfilter(dev, kn)
|
||||
if (kn->kn_filter != EVFILT_READ)
|
||||
return (1);
|
||||
|
||||
/*
|
||||
* Refresh PID associated with this descriptor.
|
||||
*/
|
||||
d->bd_pid = curthread->td_proc->p_pid;
|
||||
kn->kn_fop = &bpfread_filtops;
|
||||
kn->kn_hook = d;
|
||||
knlist_add(&d->bd_sel.si_note, kn, 0);
|
||||
@ -1724,7 +1735,6 @@ bpfstats_fill_xbpf(struct xbpf_d *d, struct bpf_d *bd)
|
||||
d->bd_pid = bd->bd_pid;
|
||||
strlcpy(d->bd_ifname,
|
||||
bd->bd_bif->bif_ifp->if_xname, IFNAMSIZ);
|
||||
strlcpy(d->bd_pcomm, bd->bd_pcomm, MAXCOMLEN);
|
||||
d->bd_locked = bd->bd_locked;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,6 @@ struct bpf_d {
|
||||
struct label *bd_label; /* MAC label for descriptor */
|
||||
u_long bd_fcount; /* number of packets which matched filter */
|
||||
pid_t bd_pid; /* PID which created descriptor */
|
||||
char bd_pcomm[MAXCOMLEN + 1];
|
||||
int bd_locked; /* true if descriptor is locked */
|
||||
};
|
||||
|
||||
@ -148,7 +147,6 @@ struct xbpf_d {
|
||||
int bd_bufsize;
|
||||
pid_t bd_pid;
|
||||
char bd_ifname[IFNAMSIZ];
|
||||
char bd_pcomm[MAXCOMLEN + 1];
|
||||
int bd_locked;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user