From owner-freebsd-bugs@FreeBSD.ORG Tue Jul 4 02:50:20 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 739EE16A4E7 for ; Tue, 4 Jul 2006 02:50:20 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C2E7643D53 for ; Tue, 4 Jul 2006 02:50:15 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k642oFRt052286 for ; Tue, 4 Jul 2006 02:50:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k642oF81052281; Tue, 4 Jul 2006 02:50:15 GMT (envelope-from gnats) Resent-Date: Tue, 4 Jul 2006 02:50:15 GMT Resent-Message-Id: <200607040250.k642oF81052281@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Atsuo Ohki Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0BFDD16A4E0 for ; Tue, 4 Jul 2006 02:42:07 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id A9F4C43D45 for ; Tue, 4 Jul 2006 02:42:06 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k642g6gE099463 for ; Tue, 4 Jul 2006 02:42:06 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k642g6BG099462; Tue, 4 Jul 2006 02:42:06 GMT (envelope-from nobody) Message-Id: <200607040242.k642g6BG099462@www.freebsd.org> Date: Tue, 4 Jul 2006 02:42:06 GMT From: Atsuo Ohki To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: kern/99758: chown/chmod pty slave side in kernel X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jul 2006 02:50:20 -0000 >Number: 99758 >Category: kern >Synopsis: chown/chmod pty slave side in kernel >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Jul 04 02:50:14 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Atsuo Ohki >Release: FreeBSD 6.1 >Organization: GSSM, University of Tsukuba, Tokyo >Environment: FreeBSD smr01 6.1-RELEASE-p2 FreeBSD 6.1-RELEASE-p2 #3: Mon Jul 3 15:55:22 JST 2006 ohki@smr01:/usr/src/sys/i386/compile/SMP i386 >Description: I know that the ownership and permission of the pty slave side can be controlled by `grantpt()' (with a set-uided helper program /usr/libexec/pt_chown), but all programs which manipulate control/slave pair of pty do not use `grantpt()'. More over, `grantpt()' leave the onwership of pty slave as those of user who used the slave last time. I though it is better to control the ownership and permission of the pty slave as follow: 1) when the control side is opened, set the ownership of the corresponding slave to those who opend the control side, and the permission as 0620. 2) when the control side is closed, restore the ownership/permission of the corresponding slave to root/wheel, 0666. Included patch modifies kern/tty_pty.c, fs/devfs/devfs_devs.c, fs/devfs/devfs_vfsops.c >How-To-Repeat: >Fix: --- kern/tty_pty.c-ORIG Fri Mar 31 01:46:56 2006 +++ kern/tty_pty.c Sun Jul 2 22:49:29 2006 @@ -265,6 +265,8 @@ } } +extern void devfs_update(struct cdev *dev, uid_t uid, gid_t gid, int mode); + static int ptcopen(struct cdev *dev, int flag, int devtype, struct thread *td) { @@ -288,6 +290,9 @@ pt->pt_flags = 0; pt->pt_send = 0; pt->pt_ucntl = 0; + + devfs_update(pt->devs, td->td_ucred->cr_ruid, 4, 0620); + return (0); } @@ -311,6 +316,11 @@ tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED); tp->t_state |= TS_ZOMBIE; ttyflush(tp, FREAD | FWRITE); + } + + { + struct ptsc *pt = dev->si_drv1; + devfs_update(pt->devs, UID_ROOT, GID_WHEEL, 0666); } tp->t_oproc = 0; /* mark closed */ --- fs/devfs/devfs_devs.c-ORIG Mon Mar 13 12:05:06 2006 +++ fs/devfs/devfs_devs.c Mon Jul 3 10:45:18 2006 @@ -490,6 +490,43 @@ devfs_generation++; } +extern int devfs_sx_xlock(u_int idx); +extern void devfs_sx_xunlock(u_int idx); +void devfs_update(struct cdev *dev, uid_t uid, gid_t gid, int mode); + +void +devfs_update(struct cdev *dev, uid_t uid, gid_t gid, int mode) +{ + struct cdev_priv *cdp; + struct devfs_dirent *de; + u_int i; + + cdp = dev->si_priv; + dev_lock(); + if (dev != &cdp->cdp_c || cdp->cdp_dirents == NULL) + goto out; + + dev->si_uid = uid; + dev->si_gid = gid; + dev->si_mode = mode; + + for (i=0; i <= cdp->cdp_maxdirent; i++) { + if ((de = cdp->cdp_dirents[i]) != NULL && + de->de_cdp == cdp && de->de_dirent->d_type == DT_CHR) { + dev_unlock(); + if (devfs_sx_xlock(i)) { + de->de_uid = uid; + de->de_gid = gid; + de->de_mode =mode; + devfs_sx_xunlock(i); + } + dev_lock(); + } + } +out: + dev_unlock(); +} + static void devfs_devs_init(void *junk __unused) { --- fs/devfs/devfs_vfsops.c-ORIG Mon Sep 26 23:36:52 2005 +++ fs/devfs/devfs_vfsops.c Mon Jul 3 15:53:37 2006 @@ -61,6 +61,68 @@ static vfs_statfs_t devfs_statfs; /* + * stuff for devfs_update() + */ +#define DEVFS_IDX2MOUNTP_SIZE 16 +static struct devfs_mount *devfs_mountps[DEVFS_IDX2MOUNTP_SIZE]; + +static inline void +put_fmp(struct devfs_mount *dm) +{ + int i; + + for (i=0; idm_idx == idx) { + sx_xlock(&(devfs_mountps[i]->dm_lock)); + return (1); + } + } + return (0); +} + +void +devfs_sx_xunlock(u_int idx) { + int i; + + for (i=0; idm_idx == idx) { + sx_xunlock(&(devfs_mountps[i]->dm_lock)); + return; + } + } +} + +/* * Mount the filesystem */ static int @@ -105,6 +167,8 @@ vfs_mountedfrom(mp, "devfs"); + put_fmp(fmp); /* XXX */ + return (0); } @@ -121,6 +185,7 @@ if (error) return (error); sx_xlock(&fmp->dm_lock); + clear_fmp(fmp); /* XXX */ devfs_cleanup(fmp); devfs_rules_cleanup(fmp); sx_xunlock(&fmp->dm_lock); >Release-Note: >Audit-Trail: >Unformatted: