From owner-freebsd-hackers Tue Jul 24 9:28:45 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mailgate.imagination.co.uk (mailgate.imagination.co.uk [212.140.144.32]) by hub.freebsd.org (Postfix) with ESMTP id 12F3F37B408 for ; Tue, 24 Jul 2001 09:28:18 -0700 (PDT) (envelope-from jonathan.laventhol@imagination.com) Received: from imagination.com (dhcp-76-145.imagination.co.uk [192.168.76.145]) by mailgate.imagination.co.uk (8.9.3/8.9.3) with ESMTP id QAA41531 for ; Tue, 24 Jul 2001 16:28:16 GMT Message-ID: <3B5DA34C.5E98F81E@imagination.com> Date: Tue, 24 Jul 2001 17:33:17 +0100 From: Jonathan Laventhol Organization: Imagination Ltd X-Mailer: Mozilla 4.76 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: is a sysctl(3) write atomic? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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