Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2001 17:33:17 +0100
From:      Jonathan Laventhol <jonathan.laventhol@imagination.com>
To:        freebsd-hackers@freebsd.org
Subject:   is a sysctl(3) write atomic?
Message-ID:  <3B5DA34C.5E98F81E@imagination.com>

next in thread | raw e-mail | index | archive | help
Hello FreeBSD Kernel People --

I have a kernel mod which we are using for a site-specific
purpose.  It requires an approx 1 Mbyte data structure to
be passed into the kernel from user side, and I'm concerned
about the atomicity of the write.  If my kernel mods see
a half-written structure they will misbehave and I want to know
do I need to re-write them to be safe against this. 

Manual sysctl(3) page says:
     Unless explicitly noted below, sysctl() returns a consistent
snapshot of
     the data requested.  Consistency is obtained by locking the
destination
     buffer into memory so that the data may be copied out without
blocking.
     Calls to sysctl() are serialized to avoid deadlock.

I'm afraid I've been unable to determine the exact detail.
So: is the kernel prevented from accessing the data
during a sysctl(3) write of an OPAQUE?  

SYSCTL_OPAQUE(_biggroups, OID_AUTO, entries, CTLFLAG_RW,
&biggroups_entries,
           sizeof(biggroups_entries), "S", "");

Details:
	I've modified /usr/src/sys/ufs/ufs/ufs_vnops.c to
	have a modified ufs_access() procedure, which
	esentially puts the user's group list in the kernel,
	rather than in each process.

	The test for group permissions now has additional code:
		if member(file's group, kernel's set of this user's groups) then
			do bit test against file's mode
			return EACCESS or 0
		endif

	And it's the kernel's list of user's groups that I set with
	a sysctl(3) call.  The membership test is binary chop on sorted
	uid-gids:
		struct ugbox = {
			int nmembers;
			struct {
				uid_t u;
				gid_t g;
			} data[100000];
		}

	I'm hoping that the kernel is locked during sysctl's write, so that
	the whole table and nmembers get's updated atomically.

	The purpose of this is to enable a given user to be in a large
(hundreds)
	number of groups.  The actual size of nmembers is about 25,000.

	(If anybody's interested in using this let me know and I'll send a
patch.)


Best regards,
Jonathan.
-- 
____________________________________________________________________
Imagination  25 Store Street South Crescent London WC1E 7BL England |
             Tel +44 20 7323 3300    Fax +44 20 7323 5801           |
             _______________________________________________________|

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B5DA34C.5E98F81E>