NetBSD Problem Report #40167

From paul@whooppee.com  Sun Dec 14 14:10:47 2008
Return-Path: <paul@whooppee.com>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 81ED263B121
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 14 Dec 2008 14:10:47 +0000 (UTC)
Message-Id: <20081214141046.DF7525985@quicky.whooppee.com>
Date: Sun, 14 Dec 2008 06:10:46 -0800 (PST)
From: paul@whooppee.com
Reply-To: paul@whooppee.com
To: gnats-bugs@gnats.NetBSD.org
Subject: compat32's shadow sysctl tree is non-functional
X-Send-Pr-Version: 3.95

>Number:         40167
>Category:       kern
>Synopsis:       compat32's shadow sysctl tree is non-functional
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 14 14:15:01 +0000 2008
>Closed-Date:    Fri Dec 19 17:39:16 +0000 2008
>Last-Modified:  Fri Dec 19 17:39:16 +0000 2008
>Originator:     Paul Goyette
>Release:        NetBSD 5.99.5
>Organization:
----------------------------------------------------------------------
|   Paul Goyette   | PGP DSS Key fingerprint: |  E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 |  paul@whooppee.com   |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette@juniper.net |
----------------------------------------------------------------------
>Environment:


System: NetBSD quicky.whooppee.com 5.99.5 NetBSD 5.99.5 (QUICKY (ASUS M2N32 WS) 2008-12-13 16:13:04) #3: Sat Dec 13 08:19:58 PST 2008 paul@speedy.whooppee.com:/build/netbsd-local/obj/amd64/sys/arch/amd64/compile/QUICKY amd64
Architecture: x86_64
Machine: amd64
>Description:
With the introduction of modular kernels, the netbsd32 "shadow" sysctl tree
is non-functional.  Routine netbsd32_sysctl_init() is called long after the
"real" sysctl tree has been initialized and "frozen" (by setting the
CTLFLAGS_PERMANENT bit in its root node), which causes sysctl_create() to
reject creation of the nodes _in_any_tree_ with error EPERM.

This can be seen by booting a modular kernel with options COMPAT_NETBSD32
and observe the following console messages:
	sysctl_createv: sysctl_create(kern) returned 1
	sysctl_createv: sysctl_locate(boottime) returned 2
	sysctl_createv: sysctl_create(vm) returned 1
	sysctl_createv: sysctl_locate(loadavg) returned 2
	sysctl_createv: sysctl_create(hw) returned 1
	sysctl_createv: sysctl_locate(machine) returned 2
	sysctl_createv: sysctl_locate(machine_arch) returned 2
>How-To-Repeat:
Boot a modular kernel and watch for the above messages.
>Fix:
The following patch changes sysctl_create() to examine the PERMANENT flag
in the root of the tree being modified, rather than in the default tree.
It therefore checks if the tree being modified has previously been locked,
rather than checking the default tree.

Index: kern/kern_sysctl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.219
diff -u -p -r1.219 kern_sysctl.c
--- kern/kern_sysctl.c	12 Nov 2008 12:36:16 -0000	1.219
+++ kern/kern_sysctl.c	14 Dec 2008 14:01:33 -0000
@@ -733,7 +733,7 @@ sysctl_create(SYSCTLFN_ARGS)
 	 * the tree itself is not writeable or
 	 * the entire sysctl system is not writeable
 	 */
-	if ((sysctl_root.sysctl_flags & CTLFLAG_PERMANENT) &&
+	if ((sysctl_rootof(rnode)->sysctl_flags & CTLFLAG_PERMANENT) &&
 	    (!(sysctl_rootof(rnode)->sysctl_flags & CTLFLAG_READWRITE) ||
 	     !(sysctl_root.sysctl_flags & CTLFLAG_READWRITE)))
 		return (EPERM);

>Release-Note:

>Audit-Trail:
From: Paul Goyette <pgoyette@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/40167 CVS commit: src
Date: Fri, 19 Dec 2008 17:11:57 +0000 (UTC)

 Module Name:	src
 Committed By:	pgoyette
 Date:		Fri Dec 19 17:11:57 UTC 2008

 Modified Files:
 	src/sys/arch/hp300/hp300: autoconf.c
 	src/sys/arch/hpcarm/hpcarm: hpc_machdep.c
 	src/sys/arch/hpcmips/hpcmips: machdep.c
 	src/sys/arch/hpcsh/hpcsh: machdep.c
 	src/sys/kern: kern_subr.c vfs_subr.c
 	src/sys/rump/librump/rumpvfs: vfsops_stub.c
 	src/sys/sys: systm.h
 	src/sys/ufs/mfs: mfs_vfsops.c
 	src/usr.bin/config: mkswap.c

 Log Message:
 Store config(1)'s root filesystem type as a text string rather than
 embedding the address of its xxx_mountroot() in swapnetbsd.c.  This
 permits booting of kernels with hard-wired filesystem type even if the
 filesystem is in a loadable module (ie, not linked into the kernel
 image).

 Discussed on current-users.  Tested on amd64 and i386 with both hard-
 wired and '?' filesystem times, and on both modular and monolithic
 kernels.

 Thanks to pooka@ for code review and suggestions.

 Addresses my PR kern/40167


 To generate a diff of this commit:
 cvs rdiff -r1.91 -r1.92 src/sys/arch/hp300/hp300/autoconf.c
 cvs rdiff -r1.89 -r1.90 src/sys/arch/hpcarm/hpcarm/hpc_machdep.c
 cvs rdiff -r1.99 -r1.100 src/sys/arch/hpcmips/hpcmips/machdep.c
 cvs rdiff -r1.65 -r1.66 src/sys/arch/hpcsh/hpcsh/machdep.c
 cvs rdiff -r1.196 -r1.197 src/sys/kern/kern_subr.c
 cvs rdiff -r1.361 -r1.362 src/sys/kern/vfs_subr.c
 cvs rdiff -r1.3 -r1.4 src/sys/rump/librump/rumpvfs/vfsops_stub.c
 cvs rdiff -r1.231 -r1.232 src/sys/sys/systm.h
 cvs rdiff -r1.99 -r1.100 src/sys/ufs/mfs/mfs_vfsops.c
 cvs rdiff -r1.4 -r1.5 src/usr.bin/config/mkswap.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Paul Goyette <pgoyette@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/40167 CVS commit: src/sys/kern
Date: Fri, 19 Dec 2008 17:28:59 +0000 (UTC)

 Module Name:	src
 Committed By:	pgoyette
 Date:		Fri Dec 19 17:28:59 UTC 2008

 Modified Files:
 	src/sys/kern: kern_sysctl.c

 Log Message:
 When checking for "set-up is complete", look for the CTLFLAGS_PERMANENT
 in the root of the tree being modified, rather than in the system default
 tree.  This permits module compat_netbsd32 to initialize its shadow tree
 at load time.

 Discussed on tech-kern, with no objections.

 Addresses my PR kern/40167


 To generate a diff of this commit:
 cvs rdiff -r1.219 -r1.220 src/sys/kern/kern_sysctl.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Fri, 19 Dec 2008 17:39:16 +0000
State-Changed-Why:
Patch applied with minor edits.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.