From owner-freebsd-standards@FreeBSD.ORG Mon Aug 8 11:07:17 2011 Return-Path: Delivered-To: freebsd-standards@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA63F1065675 for ; Mon, 8 Aug 2011 11:07:17 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BF4C28FC1B for ; Mon, 8 Aug 2011 11:07:17 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p78B7H8i078679 for ; Mon, 8 Aug 2011 11:07:17 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p78B7GFJ078677 for freebsd-standards@FreeBSD.org; Mon, 8 Aug 2011 11:07:16 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 8 Aug 2011 11:07:16 GMT Message-Id: <201108081107.p78B7GFJ078677@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-standards@FreeBSD.org Cc: Subject: Current problem reports assigned to freebsd-standards@FreeBSD.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Aug 2011 11:07:18 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o stand/157050 standards OSS implementation lacks AFMT_FLOAT o stand/154842 standards invalid request authenticator in the second and subseq o stand/150093 standards C++ std::locale support is broken a stand/149980 standards [libc] [patch] negative value integer to nanosleep(2) o stand/147210 standards xmmintrin.h and cstdlib conflicts with each other with o docs/143472 standards gethostname(3) references undefined value: HOST_NAME_M s stand/141705 standards [libc] [request] libc lacks cexp (and friends) o stand/130067 standards Wrong numeric limits in system headers? o stand/124860 standards flockfile(3) doesn't work when the memory has been exh o stand/121921 standards [patch] Add leap second support to at(1), atrun(8) o stand/116477 standards rm(1): rm behaves unexpectedly when using -r and relat o bin/116413 standards incorrect getconf(1) handling of unsigned constants gi o stand/116081 standards make does not work with the directive sinclude p stand/107561 standards [libc] [patch] [request] Missing SUS function tcgetsid o stand/100017 standards [Patch] Add fuser(1) functionality to fstat(1) o stand/96236 standards [patch] [posix] sed(1) incorrectly describes a functio o stand/94729 standards [libc] fcntl() throws undocumented ENOTTY a stand/86484 standards [patch] mkfifo(1) uses wrong permissions o stand/82654 standards C99 long double math functions are missing o stand/81287 standards [patch] fingerd(8) might send a line not ending in CRL a stand/80293 standards sysconf() does not support well-defined unistd values o stand/79056 standards [feature request] [atch] regex(3) regression tests o stand/70813 standards [patch] ls(1) not Posix compliant o stand/66357 standards make POSIX conformance problem ('sh -e' & '+' command- s kern/64875 standards [libc] [patch] [request] add a system call: fdatasync( o stand/56476 standards [patch] cd9660 unicode support simple hack o stand/54410 standards one-true-awk not POSIX compliant (no extended REs) o stand/46119 standards Priority problems for SCHED_OTHER using pthreads o stand/44365 standards [headers] [patch] [request] introduce ulong and unchar a stand/41576 standards ln(1): replacing old dir-symlinks o stand/39256 standards snprintf/vsnprintf aren't POSIX-conformant for strings a docs/26003 standards getgroups(2) lists NGROUPS_MAX but not syslimits.h s stand/24590 standards timezone function not compatible witn Single Unix Spec o stand/21519 standards sys/dir.h should be deprecated some more s bin/14925 standards getsubopt isn't poisonous enough 35 problems total. From owner-freebsd-standards@FreeBSD.ORG Thu Aug 11 11:30:09 2011 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7DA1D1065675 for ; Thu, 11 Aug 2011 11:30:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 52C058FC13 for ; Thu, 11 Aug 2011 11:30:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p7BBU9uc010420 for ; Thu, 11 Aug 2011 11:30:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p7BBU99K010419; Thu, 11 Aug 2011 11:30:09 GMT (envelope-from gnats) Resent-Date: Thu, 11 Aug 2011 11:30:09 GMT Resent-Message-Id: <201108111130.p7BBU99K010419@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Gleb Smirnoff Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 660C0106566B for ; Thu, 11 Aug 2011 11:24:11 +0000 (UTC) (envelope-from glebius@behemoth.ramtel.ru) Received: from behemoth.ramtel.ru (behemoth.ramtel.ru [81.19.64.118]) by mx1.freebsd.org (Postfix) with ESMTP id F3B4B8FC12 for ; Thu, 11 Aug 2011 11:24:10 +0000 (UTC) Received: from behemoth.ramtel.ru (localhost [127.0.0.1]) by behemoth.ramtel.ru (8.14.5/8.14.5) with ESMTP id p7BBCq9d001340; Thu, 11 Aug 2011 15:12:52 +0400 (MSK) (envelope-from glebius@behemoth.ramtel.ru) Received: (from glebius@localhost) by behemoth.ramtel.ru (8.14.5/8.14.5/Submit) id p7BBCqqU001339; Thu, 11 Aug 2011 15:12:52 +0400 (MSK) (envelope-from glebius) Message-Id: <201108111112.p7BBCqqU001339@behemoth.ramtel.ru> Date: Thu, 11 Aug 2011 15:12:52 +0400 (MSK) From: Gleb Smirnoff To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Roland Olbricht Subject: standards/159679: [patch] [standards] fchmod(2) fails on descriptor referencing shared memory X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Aug 2011 11:30:09 -0000 >Number: 159679 >Category: standards >Synopsis: [patch] [standards] fchmod(2) fails on descriptor referencing shared memory >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 11 11:30:08 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Gleb Smirnoff >Release: FreeBSD 9.0-BETA1 amd64 >Organization: Rambler Internet Holding >Environment: System: FreeBSD behemoth.ramtel.ru 9.0-BETA1 FreeBSD 9.0-BETA1 #69 r224757M: Thu Aug 11 14:52:27 MSK 2011 glebius@behemoth.ramtel.ru:/usr/obj/usr/src/newcarp/sys/BEHEMOTH amd64 >Description: According to POSIX fchmod() syscall should be capable to deal with file descriptors referencing shared memory segments, with certain mask put on mode. http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmod.html In FreeBSD it returns EINVAL and doesn't change access mode. This is due to fchmod() requiring only vnode-backed filedescriptors. The attached patch fixes the problem. It makes some namespace pollution to vfs_syscalls.c, so probably a cleaner approach would be to move fchmod() to some not vfs-related file, may be kern_descrip.c? After applying this patch we also need to switch from ACCESSPERMS mask to a new mask consisting only flags mentioned in above URL. Probably mask can be called RWPERMS, defined in sys/stat.h and used in fchmod() as well as in shm_open(). #define RWPERMS (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) /* 0666 */ >How-To-Repeat: #include #include #include #include #include int main(int argc, char* args[]) { int fd; if ((fd = shm_open("/foobar", O_RDWR|O_CREAT|O_TRUNC|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) err(1, "shm_open"); /* * http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmod.html * * [SHM] If fildes references a shared memory object, the fchmod() * function need only affect the * S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH * file permission bits. */ if (fchmod(fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) != 0) { shm_unlink("/foobar"); err(1, "fchmod"); } printf("test successful\n"); shm_unlink("/foobar"); } >Fix: Index: vfs_syscalls.c =================================================================== --- vfs_syscalls.c (revision 224757) +++ vfs_syscalls.c (working copy) @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,7 @@ const struct timespec *, int, int); static int vn_access(struct vnode *vp, int user_flags, struct ucred *cred, struct thread *td); +static int getfile(struct filedesc *fdp, int fd, struct file **fpp); /* * The module initialization routine for POSIX asynchronous I/O will @@ -2931,21 +2933,40 @@ } */ *uap; { struct file *fp; - int vfslocked; int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_MODE(uap->mode); - if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) + if ((error = getfile(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); + switch (fp->f_type) { + case DTYPE_VNODE: + { + int vfslocked; + + vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); #ifdef AUDIT - vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); - AUDIT_ARG_VNODE1(fp->f_vnode); - VOP_UNLOCK(fp->f_vnode, 0); + vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); + AUDIT_ARG_VNODE1(fp->f_vnode); + VOP_UNLOCK(fp->f_vnode, 0); #endif - error = setfmode(td, fp->f_vnode, uap->mode); - VFS_UNLOCK_GIANT(vfslocked); + error = setfmode(td, fp->f_vnode, uap->mode); + VFS_UNLOCK_GIANT(vfslocked); + break; + } + case DTYPE_SHM: + { + struct shmfd *shmfd = fp->f_data; + + shmfd->shm_mode = uap->mode & ACCESSPERMS; + error = 0; + + break; + } + default: + error = EINVAL; + } + fdrop(fp, td); return (error); } @@ -4251,11 +4272,8 @@ * Convert a user file descriptor to a kernel file entry. * A reference on the file entry is held upon returning. */ -int -getvnode(fdp, fd, fpp) - struct filedesc *fdp; - int fd; - struct file **fpp; +static int +getfile(struct filedesc *fdp, int fd, struct file **fpp) { int error; struct file *fp; @@ -4264,11 +4282,24 @@ fp = NULL; if (fdp == NULL || (fp = fget_unlocked(fdp, fd)) == NULL) error = EBADF; - else if (fp->f_vnode == NULL) { + *fpp = fp; + return (error); +} + +/* + * Convert a user file descriptor to a kernel file entry, + * failing on a file that hasn't a vnode. + */ +int +getvnode(struct filedesc *fdp, int fd, struct file **fpp) +{ + int error; + + error = getfile(fdp, fd, fpp); + if (error == 0 && (*fpp)->f_vnode == NULL) { error = EINVAL; - fdrop(fp, curthread); + fdrop(*fpp, curthread); } - *fpp = fp; return (error); } >Release-Note: >Audit-Trail: >Unformatted: From owner-freebsd-standards@FreeBSD.ORG Thu Aug 11 12:00:31 2011 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4FF810656A7 for ; Thu, 11 Aug 2011 12:00:31 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A06F28FC17 for ; Thu, 11 Aug 2011 12:00:31 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p7BC0VSc041017 for ; Thu, 11 Aug 2011 12:00:31 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p7BC0VEK041016; Thu, 11 Aug 2011 12:00:31 GMT (envelope-from gnats) Date: Thu, 11 Aug 2011 12:00:31 GMT Message-Id: <201108111200.p7BC0VEK041016@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org From: Kostik Belousov Cc: Subject: Re: standards/159679: [patch] [standards] fchmod(2) fails on descriptor referencing shared memory X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Kostik Belousov List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Aug 2011 12:00:31 -0000 The following reply was made to PR standards/159679; it has been noted by GNATS. From: Kostik Belousov To: Gleb Smirnoff Cc: FreeBSD-gnats-submit@freebsd.org, Roland Olbricht Subject: Re: standards/159679: [patch] [standards] fchmod(2) fails on descriptor referencing shared memory Date: Thu, 11 Aug 2011 14:36:08 +0300 --cnq8aYAp9EJI1BEL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I do not think the patch is the right thing to do. My opinion is that struct fileops should grow another method, say fo_chmod, instead of adding yet another switch on the f_type. As a side note, f_type can move into fileops. --cnq8aYAp9EJI1BEL Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk5DvqcACgkQC3+MBN1Mb4j75ACgsPg06pG0aNYWvnDmq9iwkzIh nGsAoPNiwtW54zQxQu2PSZq/66B2FCcm =F37n -----END PGP SIGNATURE----- --cnq8aYAp9EJI1BEL-- From owner-freebsd-standards@FreeBSD.ORG Thu Aug 11 13:20:11 2011 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 85055106566B for ; Thu, 11 Aug 2011 13:20:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 729E28FC16 for ; Thu, 11 Aug 2011 13:20:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p7BDKBbC015742 for ; Thu, 11 Aug 2011 13:20:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p7BDKB8T015741; Thu, 11 Aug 2011 13:20:11 GMT (envelope-from gnats) Date: Thu, 11 Aug 2011 13:20:11 GMT Message-Id: <201108111320.p7BDKB8T015741@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org From: Kostik Belousov Cc: Subject: Re: standards/159679: [patch] [standards] fchmod(2) fails on descriptor referencing shared memory X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Kostik Belousov List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Aug 2011 13:20:11 -0000 The following reply was made to PR standards/159679; it has been noted by GNATS. From: Kostik Belousov To: Gleb Smirnoff Cc: FreeBSD-gnats-submit@freebsd.org, Roland Olbricht Subject: Re: standards/159679: [patch] [standards] fchmod(2) fails on descriptor referencing shared memory Date: Thu, 11 Aug 2011 16:15:28 +0300 --ja0vWYS1o1njzvo7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 11, 2011 at 02:36:08PM +0300, Kostik Belousov wrote: > I do not think the patch is the right thing to do. My opinion is that > struct fileops should grow another method, say fo_chmod, instead of > adding yet another switch on the f_type. I mean the following. diff --git a/sys/dev/streams/streams.c b/sys/dev/streams/streams.c index 00f65a3..4b47949 100644 --- a/sys/dev/streams/streams.c +++ b/sys/dev/streams/streams.c @@ -95,7 +95,8 @@ static struct fileops svr4_netops =3D { .fo_poll =3D soo_poll, .fo_kqfilter =3D soo_kqfilter, .fo_stat =3D soo_stat, - .fo_close =3D svr4_soo_close + .fo_close =3D svr4_soo_close, + .fo_chmod =3D badfo_chmod, }; =20 static struct cdevsw streams_cdevsw =3D { diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 955bd8b..ed6fb00 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -1665,6 +1665,7 @@ static struct fileops devfs_ops_f =3D { .fo_kqfilter =3D devfs_kqfilter_f, .fo_stat =3D devfs_stat_f, .fo_close =3D devfs_close_f, + .fo_chmod =3D vn_chmod, .fo_flags =3D DFLAG_PASSABLE | DFLAG_SEEKABLE }; =20 diff --git a/sys/fs/fifofs/fifo_vnops.c b/sys/fs/fifofs/fifo_vnops.c index e339a8a..8048f21 100644 --- a/sys/fs/fifofs/fifo_vnops.c +++ b/sys/fs/fifofs/fifo_vnops.c @@ -72,6 +72,7 @@ struct fileops fifo_ops_f =3D { .fo_kqfilter =3D fifo_kqfilter_f, .fo_stat =3D fifo_stat_f, .fo_close =3D fifo_close_f, + .fo_chmod =3D badfo_chmod, .fo_flags =3D DFLAG_PASSABLE }; =20 diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index f3f9cbc..d20c6d5 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3725,6 +3725,13 @@ badfo_close(struct file *fp, struct thread *td) return (EBADF); } =20 +int +badfo_chmod(struct file *fp, mode_t mode, struct thread *td) +{ + + return (EINVAL); +} + struct fileops badfileops =3D { .fo_read =3D badfo_readwrite, .fo_write =3D badfo_readwrite, @@ -3734,6 +3741,7 @@ struct fileops badfileops =3D { .fo_kqfilter =3D badfo_kqfilter, .fo_stat =3D badfo_stat, .fo_close =3D badfo_close, + .fo_chmod =3D badfo_chmod, }; =20 =20 diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index e14ae02..1eef3b3 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -122,6 +122,7 @@ static struct fileops kqueueops =3D { .fo_kqfilter =3D kqueue_kqfilter, .fo_stat =3D kqueue_stat, .fo_close =3D kqueue_close, + .fo_chmod =3D badfo_chmod, }; =20 static int knote_attach(struct knote *kn, struct kqueue *kq); diff --git a/sys/kern/sys_capability.c b/sys/kern/sys_capability.c index 6ca9602..35e5564 100644 --- a/sys/kern/sys_capability.c +++ b/sys/kern/sys_capability.c @@ -154,6 +154,7 @@ static struct fileops capability_ops =3D { .fo_kqfilter =3D capability_kqfilter, .fo_stat =3D capability_stat, .fo_close =3D capability_close, + .fo_chmod =3D badfo_chmod, .fo_flags =3D DFLAG_PASSABLE, }; =20 @@ -166,6 +167,7 @@ static struct fileops capability_ops_unpassable =3D { .fo_kqfilter =3D capability_kqfilter, .fo_stat =3D capability_stat, .fo_close =3D capability_close, + .fo_chmod =3D badfo_chmod, .fo_flags =3D 0, }; =20 diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 50b0389..8ff5ed2 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -155,6 +155,7 @@ static struct fileops pipeops =3D { .fo_kqfilter =3D pipe_kqfilter, .fo_stat =3D pipe_stat, .fo_close =3D pipe_close, + .fo_chmod =3D badfo_chmod, .fo_flags =3D DFLAG_PASSABLE }; =20 diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index c9b0534..4ef8506 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -64,6 +64,7 @@ struct fileops socketops =3D { .fo_kqfilter =3D soo_kqfilter, .fo_stat =3D soo_stat, .fo_close =3D soo_close, + .fo_chmod =3D badfo_chmod, .fo_flags =3D DFLAG_PASSABLE }; =20 diff --git a/sys/kern/tty_pts.c b/sys/kern/tty_pts.c index a3db59b..51704cf 100644 --- a/sys/kern/tty_pts.c +++ b/sys/kern/tty_pts.c @@ -597,6 +597,7 @@ static struct fileops ptsdev_ops =3D { .fo_kqfilter =3D ptsdev_kqfilter, .fo_stat =3D ptsdev_stat, .fo_close =3D ptsdev_close, + .fo_chmod =3D badfo_chmod, .fo_flags =3D DFLAG_PASSABLE, }; =20 diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c index 9b334ac..cfb1db5 100644 --- a/sys/kern/uipc_mqueue.c +++ b/sys/kern/uipc_mqueue.c @@ -2523,6 +2523,7 @@ static struct fileops mqueueops =3D { .fo_poll =3D mqf_poll, .fo_kqfilter =3D mqf_kqfilter, .fo_stat =3D mqf_stat, + .fo_chmod =3D badfo_chmod, .fo_close =3D mqf_close }; =20 diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c index 917c343..5bb1b1b 100644 --- a/sys/kern/uipc_sem.c +++ b/sys/kern/uipc_sem.c @@ -144,6 +144,7 @@ static struct fileops ksem_ops =3D { .fo_kqfilter =3D ksem_kqfilter, .fo_stat =3D ksem_stat, .fo_close =3D ksem_closef, + .fo_chmod =3D badfo_chmod, .fo_flags =3D DFLAG_PASSABLE }; =20 diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c index 0414f12..2a6d0f2 100644 --- a/sys/kern/uipc_shm.c +++ b/sys/kern/uipc_shm.c @@ -123,6 +123,7 @@ static fo_poll_t shm_poll; static fo_kqfilter_t shm_kqfilter; static fo_stat_t shm_stat; static fo_close_t shm_close; +static fo_chmod_t shm_chmod; =20 /* File descriptor operations. */ static struct fileops shm_ops =3D { @@ -134,6 +135,7 @@ static struct fileops shm_ops =3D { .fo_kqfilter =3D shm_kqfilter, .fo_stat =3D shm_stat, .fo_close =3D shm_close, + .fo_chmod =3D shm_chmod, .fo_flags =3D DFLAG_PASSABLE }; =20 @@ -651,3 +653,13 @@ shm_mmap(struct shmfd *shmfd, vm_size_t objsize, vm_oo= ffset_t foff, *obj =3D shmfd->shm_object; return (0); } + +static int +shm_chmod(struct file *fp, mode_t mode, struct thread *td) +{ + struct shmfd *shmfd; + + shmfd =3D fp->f_data; + shmfd->shm_mode =3D mode & ACCESSPERMS; + return (0); +} diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index b48c6e7..b0b3515 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -95,7 +95,6 @@ SDT_PROBE_ARGTYPE(vfs, , stat, reg, 1, "int"); static int chroot_refuse_vdir_fds(struct filedesc *fdp); static int getutimes(const struct timeval *, enum uio_seg, struct timespec= *); static int setfown(struct thread *td, struct vnode *, uid_t, gid_t); -static int setfmode(struct thread *td, struct vnode *, int); static int setfflags(struct thread *td, struct vnode *, int); static int setutimes(struct thread *td, struct vnode *, const struct timespec *, int, int); @@ -2792,7 +2791,7 @@ fchflags(td, uap) /* * Common implementation code for chmod(), lchmod() and fchmod(). */ -static int +int setfmode(td, vp, mode) struct thread *td; struct vnode *vp; @@ -2922,30 +2921,18 @@ struct fchmod_args { int mode; }; #endif -int -fchmod(td, uap) - struct thread *td; - register struct fchmod_args /* { - int fd; - int mode; - } */ *uap; +int fchmod(struct thread *td, struct fchmod_args *uap) { struct file *fp; - int vfslocked; int error; =20 AUDIT_ARG_FD(uap->fd); AUDIT_ARG_MODE(uap->mode); - if ((error =3D getvnode(td->td_proc->p_fd, uap->fd, &fp)) !=3D 0) + + error =3D fget(td, uap->fd, &fp); + if (error !=3D 0) return (error); - vfslocked =3D VFS_LOCK_GIANT(fp->f_vnode->v_mount); -#ifdef AUDIT - vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); - AUDIT_ARG_VNODE1(fp->f_vnode); - VOP_UNLOCK(fp->f_vnode, 0); -#endif - error =3D setfmode(td, fp->f_vnode, uap->mode); - VFS_UNLOCK_GIANT(vfslocked); + error =3D fo_chmod(fp, uap->mode, td); fdrop(fp, td); return (error); } diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index e8bcc91..9f4f4ff 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -81,6 +81,7 @@ struct fileops vnops =3D { .fo_kqfilter =3D vn_kqfilter, .fo_stat =3D vn_statfile, .fo_close =3D vn_closefile, + .fo_chmod =3D vn_chmod, .fo_flags =3D DFLAG_PASSABLE | DFLAG_SEEKABLE }; =20 @@ -1357,3 +1358,20 @@ vn_rlimit_fsize(const struct vnode *vp, const struct= uio *uio, PROC_UNLOCK(td->td_proc); return (0); } + +int +vn_chmod(struct file *fp, mode_t mode, struct thread *td) +{ + int vfslocked; + int error; + + vfslocked =3D VFS_LOCK_GIANT(fp->f_vnode->v_mount); +#ifdef AUDIT + vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); + AUDIT_ARG_VNODE1(fp->f_vnode); + VOP_UNLOCK(fp->f_vnode, 0); +#endif + error =3D setfmode(td, fp->f_vnode, mode); + VFS_UNLOCK_GIANT(vfslocked); + return (error); +} diff --git a/sys/ofed/include/linux/linux_compat.c b/sys/ofed/include/linux= /linux_compat.c index 98ad807..394a7d0 100644 --- a/sys/ofed/include/linux/linux_compat.c +++ b/sys/ofed/include/linux/linux_compat.c @@ -559,7 +559,8 @@ struct fileops linuxfileops =3D { .fo_read =3D linux_file_read, .fo_poll =3D linux_file_poll, .fo_close =3D linux_file_close, - .fo_ioctl =3D linux_file_ioctl + .fo_ioctl =3D linux_file_ioctl, + .fo_chmod =3D badfo_chmod, }; =20 /* diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index 2c0c503..802a950 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -301,7 +301,8 @@ static struct fileops cryptofops =3D { .fo_poll =3D cryptof_poll, .fo_kqfilter =3D cryptof_kqfilter, .fo_stat =3D cryptof_stat, - .fo_close =3D cryptof_close + .fo_close =3D cryptof_close, + .fo_chmod =3D badfo_chmod, }; =20 static struct csession *csefind(struct fcrypt *, u_int); diff --git a/sys/sys/file.h b/sys/sys/file.h index eea2c00..4ad7abb 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -85,6 +85,7 @@ typedef int fo_kqfilter_t(struct file *fp, struct knote *= kn); typedef int fo_stat_t(struct file *fp, struct stat *sb, struct ucred *active_cred, struct thread *td); typedef int fo_close_t(struct file *fp, struct thread *td); +typedef int fo_chmod_t(struct file *fp, mode_t mode, struct thread *td); typedef int fo_flags_t; =20 struct fileops { @@ -96,6 +97,7 @@ struct fileops { fo_kqfilter_t *fo_kqfilter; fo_stat_t *fo_stat; fo_close_t *fo_close; + fo_chmod_t *fo_chmod; fo_flags_t fo_flags; /* DFLAG_* below */ }; =20 @@ -196,6 +198,8 @@ fo_kqfilter_t soo_kqfilter; fo_stat_t soo_stat; fo_close_t soo_close; =20 +fo_chmod_t badfo_chmod; + void finit(struct file *, u_int, short, void *, struct fileops *); int fgetvp(struct thread *td, int fd, struct vnode **vpp); int fgetvp_read(struct thread *td, int fd, struct vnode **vpp); @@ -224,6 +228,7 @@ static __inline fo_poll_t fo_poll; static __inline fo_kqfilter_t fo_kqfilter; static __inline fo_stat_t fo_stat; static __inline fo_close_t fo_close; +static __inline fo_chmod_t fo_chmod; =20 static __inline int fo_read(struct file *fp, struct uio *uio, struct ucred *active_cred, @@ -287,6 +292,13 @@ fo_kqfilter(struct file *fp, struct knote *kn) return ((*fp->f_ops->fo_kqfilter)(fp, kn)); } =20 +static __inline int +fo_chmod(struct file *fp, mode_t mode, struct thread *td) +{ + + return ((*fp->f_ops->fo_chmod)(fp, mode, td)); +} + #endif /* _KERNEL */ =20 #endif /* !SYS_FILE_H */ diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 1c4c7b7..35a4133 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -778,7 +778,10 @@ void vfs_mark_atime(struct vnode *vp, struct ucred *cr= ed); struct dirent; int vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t = off); =20 -int vfs_unixify_accmode(accmode_t *accmode); +int vfs_unixify_accmode(accmode_t *accmode); + +int setfmode(struct thread *td, struct vnode *, int); +int vn_chmod(struct file *fp, mode_t mode, struct thread *td); =20 #endif /* _KERNEL */ =20 --ja0vWYS1o1njzvo7 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk5D1e8ACgkQC3+MBN1Mb4jZpQCbBPgnCYYp0jgZsA1zWxsU9Yw7 U5sAn2+eZ6fdKXRbWCcztFKhyuyG9EMh =LX6t -----END PGP SIGNATURE----- --ja0vWYS1o1njzvo7--