NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/59147: sysctl: bounded-memory lookups by name



The following reply was made to PR kern/59147; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/59147: sysctl: bounded-memory lookups by name
Date: Fri, 07 Mar 2025 03:03:27 +0700

     Date:        Thu,  6 Mar 2025 14:25:00 +0000 (UTC)
     From:        campbell+netbsd%mumble.net@localhost
     Message-ID:  <20250306142500.B73421A923E%mollari.NetBSD.org@localhost>
 
   | This probably requires writing a new kernel interface,
   | say CTL_QUERYBYNAME that takes a string on input and returns
   | a MIB number on output.
 
 Or just make a sysctlbyname() (approx) system call, and just use
 that instead of sysctl()  (put the user code implementation in the
 kernel, where it is trivial).
 
 The "approx" is because I'd make its signature be
 
 int whatevername(const char *sname, void *oldp, size_t *oldlenp,
          const void *newp, size_t newlen, int *name, u_int *namelenp.
 	 size_t snamelen);
 
 where the first 5 args are exactly what they are in sysctlbyname()
 and the last three are a pointer to an array of ints to hold the numeric
 MIB number, a set/alter pointer to an int which contains the number of
 elements in that array (on call) and the number that were required (on return)
 which might be larger than it was on entry, in which case only the first N
 are actually stored in *name (those two work just the same way as oldp/oldlenp
 do), and last the the length of sname (strlen(sname)) so the kernel doesn't
 need to guess how much to copyin.
 
 Whether we would use u_int or size_t for namelenp isn't all that important,
 some of the sysctl*() functions use one, and others the other.   u_int
 seems more sensible to me (could even use u_short) - its max value should
 be well under 1000.   Probably always < 100.
 
 The order of the args needn't be that necessarily, just easier here
 for me to cut&paste!
 
 That way the same thing can be also used to implement sysctlnametomib().
 
 I think that's cleaner than butchering sysctl() to have a query type
 which uses different data types for the input & output.
 
 kre
 


Home | Main Index | Thread Index | Old Index