From 1de257deb3229812024de5861eb0aaa41e471448 Mon Sep 17 00:00:00 2001 From: truckman Date: Thu, 26 Feb 2004 00:27:04 +0000 Subject: Split the mlock() kernel code into two parts, mlock(), which unpacks the syscall arguments and does the suser() permission check, and kern_mlock(), which does the resource limit checking and calls vm_map_wire(). Split munlock() in a similar way. Enable the RLIMIT_MEMLOCK checking code in kern_mlock(). Replace calls to vslock() and vsunlock() in the sysctl code with calls to kern_mlock() and kern_munlock() so that the sysctl code will obey the wired memory limits. Nuke the vslock() and vsunlock() implementations, which are no longer used. Add a member to struct sysctl_req to track the amount of memory that is wired to handle the request. Modify sysctl_wire_old_buffer() to return an error if its call to kern_mlock() fails. Only wire the minimum of the length specified in the sysctl request and the length specified in its argument list. It is recommended that sysctl handlers that use sysctl_wire_old_buffer() should specify reasonable estimates for the amount of data they want to return so that only the minimum amount of memory is wired no matter what length has been specified by the request. Modify the callers of sysctl_wire_old_buffer() to look for the error return. Modify sysctl_old_user to obey the wired buffer length and clean up its implementation. Reviewed by: bms --- sys/netinet/ip_divert.c | 5 ++++- sys/netinet/tcp_subr.c | 4 +++- sys/netinet/tcp_timewait.c | 4 +++- sys/netinet/udp_usrreq.c | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'sys/netinet') diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index ee1f97c..a7097a2 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -588,7 +588,10 @@ div_pcblist(SYSCTL_HANDLER_ARGS) n = divcbinfo.ipi_count; INP_INFO_RUNLOCK(&divcbinfo); - sysctl_wire_old_buffer(req, 2 * sizeof(xig) + n*sizeof(struct xinpcb)); + error = sysctl_wire_old_buffer(req, + 2 * sizeof(xig) + n*sizeof(struct xinpcb)); + if (error != 0) + return (error); xig.xig_len = sizeof xig; xig.xig_count = n; diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 210a582..10d0cd6 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -859,8 +859,10 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS) INP_INFO_RUNLOCK(&tcbinfo); splx(s); - sysctl_wire_old_buffer(req, 2 * (sizeof xig) + error = sysctl_wire_old_buffer(req, 2 * (sizeof xig) + n * sizeof(struct xtcpcb)); + if (error != 0) + return (error); xig.xig_len = sizeof xig; xig.xig_count = n; diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c index 210a582..10d0cd6 100644 --- a/sys/netinet/tcp_timewait.c +++ b/sys/netinet/tcp_timewait.c @@ -859,8 +859,10 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS) INP_INFO_RUNLOCK(&tcbinfo); splx(s); - sysctl_wire_old_buffer(req, 2 * (sizeof xig) + error = sysctl_wire_old_buffer(req, 2 * (sizeof xig) + n * sizeof(struct xtcpcb)); + if (error != 0) + return (error); xig.xig_len = sizeof xig; xig.xig_count = n; diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index f0a01b2..adef1f8 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -604,8 +604,10 @@ udp_pcblist(SYSCTL_HANDLER_ARGS) INP_INFO_RUNLOCK(&udbinfo); splx(s); - sysctl_wire_old_buffer(req, 2 * (sizeof xig) + error = sysctl_wire_old_buffer(req, 2 * (sizeof xig) + n * sizeof(struct xinpcb)); + if (error != 0) + return (error); xig.xig_len = sizeof xig; xig.xig_count = n; -- cgit v1.1