]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_attr.c
[PATCH] proc: Use sane permission checks on the /proc/<pid>/fd/ symlinks
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_attr.c
index 5484eeb460c84253c59687825e34b3304c772bea..1a210104327547b77768e6fd6cd58f7618bac090 100644 (file)
@@ -15,6 +15,9 @@
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#include <linux/capability.h>
+
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_types.h"
@@ -24,7 +27,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
@@ -32,7 +34,6 @@
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
@@ -117,11 +118,6 @@ xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
             ip->i_d.di_anextents == 0))
                return(ENOATTR);
 
-       if (!(flags & (ATTR_KERNACCESS|ATTR_SECURE))) {
-               if ((error = xfs_iaccess(ip, S_IRUSR, cred)))
-                       return(XFS_ERROR(error));
-       }
-
        /*
         * Fill in the arg structure for this request.
         */
@@ -296,7 +292,7 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
        xfs_trans_ihold(args.trans, dp);
 
        /*
-        * If the attribute list is non-existant or a shortform list,
+        * If the attribute list is non-existent or a shortform list,
         * upgrade it to a single-leaf-block attribute list.
         */
        if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
@@ -425,7 +421,7 @@ xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int f
             struct cred *cred)
 {
        xfs_inode_t     *dp;
-       int             namelen, error;
+       int             namelen;
 
        namelen = strlen(name);
        if (namelen >= MAXNAMELEN)
@@ -437,14 +433,6 @@ xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int f
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return (EIO);
 
-       xfs_ilock(dp, XFS_ILOCK_SHARED);
-       if (!(flags & ATTR_SECURE) &&
-            (error = xfs_iaccess(dp, S_IWUSR, cred))) {
-               xfs_iunlock(dp, XFS_ILOCK_SHARED);
-               return(XFS_ERROR(error));
-       }
-       xfs_iunlock(dp, XFS_ILOCK_SHARED);
-
        return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
 }
 
@@ -579,7 +567,7 @@ int
 xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
 {
        xfs_inode_t         *dp;
-       int                 namelen, error;
+       int                 namelen;
 
        namelen = strlen(name);
        if (namelen >= MAXNAMELEN)
@@ -592,11 +580,7 @@ xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
                return (EIO);
 
        xfs_ilock(dp, XFS_ILOCK_SHARED);
-       if (!(flags & ATTR_SECURE) &&
-            (error = xfs_iaccess(dp, S_IWUSR, cred))) {
-               xfs_iunlock(dp, XFS_ILOCK_SHARED);
-               return(XFS_ERROR(error));
-       } else if (XFS_IFORK_Q(dp) == 0 ||
+       if (XFS_IFORK_Q(dp) == 0 ||
                   (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
                    dp->i_d.di_anextents == 0)) {
                xfs_iunlock(dp, XFS_ILOCK_SHARED);
@@ -668,12 +652,6 @@ xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
                return (EIO);
 
        xfs_ilock(dp, XFS_ILOCK_SHARED);
-       if (!(flags & ATTR_SECURE) &&
-            (error = xfs_iaccess(dp, S_IRUSR, cred))) {
-               xfs_iunlock(dp, XFS_ILOCK_SHARED);
-               return(XFS_ERROR(error));
-       }
-
        /*
         * Decide on what work routines to call based on the inode size.
         */
@@ -1147,8 +1125,7 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)
                return(error);
        ASSERT(bp != NULL);
        leaf = bp->data;
-       if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
-                                               != XFS_ATTR_LEAF_MAGIC)) {
+       if (unlikely(be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)) {
                XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
                                     context->dp->i_mount, leaf);
                xfs_da_brelse(NULL, bp);
@@ -1561,8 +1538,8 @@ xfs_attr_node_removename(xfs_da_args_t *args)
                                                     XFS_ATTR_FORK);
                if (error)
                        goto out;
-               ASSERT(INT_GET(((xfs_attr_leafblock_t *)
-                                     bp->data)->hdr.info.magic, ARCH_CONVERT)
+               ASSERT(be16_to_cpu(((xfs_attr_leafblock_t *)
+                                     bp->data)->hdr.info.magic)
                                                       == XFS_ATTR_LEAF_MAGIC);
 
                if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
@@ -1605,7 +1582,7 @@ out:
  * Fill in the disk block numbers in the state structure for the buffers
  * that are attached to the state structure.
  * This is done so that we can quickly reattach ourselves to those buffers
- * after some set of transaction commit's has released these buffers.
+ * after some set of transaction commits have released these buffers.
  */
 STATIC int
 xfs_attr_fillstate(xfs_da_state_t *state)
@@ -1652,7 +1629,7 @@ xfs_attr_fillstate(xfs_da_state_t *state)
 /*
  * Reattach the buffers to the state structure based on the disk block
  * numbers stored in the state structure.
- * This is done after some set of transaction commit's has released those
+ * This is done after some set of transaction commits have released those
  * buffers from our grip.
  */
 STATIC int
@@ -1783,7 +1760,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                        return(error);
                if (bp) {
                        node = bp->data;
-                       switch (INT_GET(node->hdr.info.magic, ARCH_CONVERT)) {
+                       switch (be16_to_cpu(node->hdr.info.magic)) {
                        case XFS_DA_NODE_MAGIC:
                                xfs_attr_trace_l_cn("wrong blk", context, node);
                                xfs_da_brelse(NULL, bp);
@@ -1791,18 +1768,14 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                                break;
                        case XFS_ATTR_LEAF_MAGIC:
                                leaf = bp->data;
-                               if (cursor->hashval >
-                                   INT_GET(leaf->entries[
-                                        INT_GET(leaf->hdr.count,
-                                               ARCH_CONVERT)-1].hashval,
-                                                       ARCH_CONVERT)) {
+                               if (cursor->hashval > be32_to_cpu(leaf->entries[
+                                   be16_to_cpu(leaf->hdr.count)-1].hashval)) {
                                        xfs_attr_trace_l_cl("wrong blk",
                                                           context, leaf);
                                        xfs_da_brelse(NULL, bp);
                                        bp = NULL;
                                } else if (cursor->hashval <=
-                                            INT_GET(leaf->entries[0].hashval,
-                                                       ARCH_CONVERT)) {
+                                            be32_to_cpu(leaf->entries[0].hashval)) {
                                        xfs_attr_trace_l_cl("maybe wrong blk",
                                                           context, leaf);
                                        xfs_da_brelse(NULL, bp);
@@ -1837,10 +1810,10 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                                return(XFS_ERROR(EFSCORRUPTED));
                        }
                        node = bp->data;
-                       if (INT_GET(node->hdr.info.magic, ARCH_CONVERT)
+                       if (be16_to_cpu(node->hdr.info.magic)
                                                        == XFS_ATTR_LEAF_MAGIC)
                                break;
-                       if (unlikely(INT_GET(node->hdr.info.magic, ARCH_CONVERT)
+                       if (unlikely(be16_to_cpu(node->hdr.info.magic)
                                                        != XFS_DA_NODE_MAGIC)) {
                                XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
                                                     XFS_ERRLEVEL_LOW,
@@ -1850,19 +1823,17 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                                return(XFS_ERROR(EFSCORRUPTED));
                        }
                        btree = node->btree;
-                       for (i = 0;
-                               i < INT_GET(node->hdr.count, ARCH_CONVERT);
+                       for (i = 0; i < be16_to_cpu(node->hdr.count);
                                                                btree++, i++) {
                                if (cursor->hashval
-                                               <= INT_GET(btree->hashval,
-                                                           ARCH_CONVERT)) {
-                                       cursor->blkno = INT_GET(btree->before, ARCH_CONVERT);
+                                               <= be32_to_cpu(btree->hashval)) {
+                                       cursor->blkno = be32_to_cpu(btree->before);
                                        xfs_attr_trace_l_cb("descending",
                                                            context, btree);
                                        break;
                                }
                        }
-                       if (i == INT_GET(node->hdr.count, ARCH_CONVERT)) {
+                       if (i == be16_to_cpu(node->hdr.count)) {
                                xfs_da_brelse(NULL, bp);
                                return(0);
                        }
@@ -1878,7 +1849,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
         */
        for (;;) {
                leaf = bp->data;
-               if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
+               if (unlikely(be16_to_cpu(leaf->hdr.info.magic)
                                                != XFS_ATTR_LEAF_MAGIC)) {
                        XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
                                             XFS_ERRLEVEL_LOW,
@@ -1889,7 +1860,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                error = xfs_attr_leaf_list_int(bp, context);
                if (error || !leaf->hdr.info.forw)
                        break;  /* not really an error, buffer full or EOF */
-               cursor->blkno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
+               cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
                xfs_da_brelse(NULL, bp);
                error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
                                              &bp, XFS_ATTR_FORK);
@@ -1937,7 +1908,7 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
                error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
                                  args->rmtblkcnt,
                                  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
-                                 NULL, 0, map, &nmap, NULL);
+                                 NULL, 0, map, &nmap, NULL, NULL);
                if (error)
                        return(error);
                ASSERT(nmap >= 1);
@@ -2015,7 +1986,7 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
                                  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
                                                        XFS_BMAPI_WRITE,
                                  args->firstblock, args->total, &map, &nmap,
-                                 args->flist);
+                                 args->flist, NULL);
                if (!error) {
                        error = xfs_bmap_finish(&args->trans, args->flist,
                                                *args->firstblock, &committed);
@@ -2066,7 +2037,8 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
                error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
                                  args->rmtblkcnt,
                                  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
-                                 args->firstblock, 0, &map, &nmap, NULL);
+                                 args->firstblock, 0, &map, &nmap,
+                                 NULL, NULL);
                if (error) {
                        return(error);
                }
@@ -2131,7 +2103,7 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
                                        args->rmtblkcnt,
                                        XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
                                        args->firstblock, 0, &map, &nmap,
-                                       args->flist);
+                                       args->flist, NULL);
                if (error) {
                        return(error);
                }
@@ -2169,7 +2141,8 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
                XFS_BMAP_INIT(args->flist, args->firstblock);
                error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
                                    XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
-                                   1, args->firstblock, args->flist, &done);
+                                   1, args->firstblock, args->flist,
+                                   NULL, &done);
                if (!error) {
                        error = xfs_bmap_finish(&args->trans, args->flist,
                                                *args->firstblock, &committed);
@@ -2252,9 +2225,10 @@ xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
                                : 0,
                (__psunsigned_t)context->dupcnt,
                (__psunsigned_t)context->flags,
-               (__psunsigned_t)INT_GET(node->hdr.count, ARCH_CONVERT),
-               (__psunsigned_t)INT_GET(node->btree[0].hashval, ARCH_CONVERT),
-               (__psunsigned_t)INT_GET(node->btree[INT_GET(node->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
+               (__psunsigned_t)be16_to_cpu(node->hdr.count),
+               (__psunsigned_t)be32_to_cpu(node->btree[0].hashval),
+               (__psunsigned_t)be32_to_cpu(node->btree[
+                                   be16_to_cpu(node->hdr.count)-1].hashval));
 }
 
 /*
@@ -2281,8 +2255,8 @@ xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
                                : 0,
                (__psunsigned_t)context->dupcnt,
                (__psunsigned_t)context->flags,
-               (__psunsigned_t)INT_GET(btree->hashval, ARCH_CONVERT),
-               (__psunsigned_t)INT_GET(btree->before, ARCH_CONVERT),
+               (__psunsigned_t)be32_to_cpu(btree->hashval),
+               (__psunsigned_t)be32_to_cpu(btree->before),
                (__psunsigned_t)NULL);
 }
 
@@ -2310,9 +2284,10 @@ xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
                                : 0,
                (__psunsigned_t)context->dupcnt,
                (__psunsigned_t)context->flags,
-               (__psunsigned_t)INT_GET(leaf->hdr.count, ARCH_CONVERT),
-               (__psunsigned_t)INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
-               (__psunsigned_t)INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
+               (__psunsigned_t)be16_to_cpu(leaf->hdr.count),
+               (__psunsigned_t)be32_to_cpu(leaf->entries[0].hashval),
+               (__psunsigned_t)be32_to_cpu(leaf->entries[
+                               be16_to_cpu(leaf->hdr.count)-1].hashval));
 }
 
 /*
@@ -2347,56 +2322,56 @@ xfs_attr_trace_enter(int type, char *where,
 
 STATIC int
 posix_acl_access_set(
-       vnode_t *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
 }
 
 STATIC int
 posix_acl_access_remove(
-       struct vnode *vp, char *name, int xflags)
+       bhv_vnode_t *vp, char *name, int xflags)
 {
        return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
 }
 
 STATIC int
 posix_acl_access_get(
-       vnode_t *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
 }
 
 STATIC int
 posix_acl_access_exists(
-       vnode_t *vp)
+       bhv_vnode_t *vp)
 {
        return xfs_acl_vhasacl_access(vp);
 }
 
 STATIC int
 posix_acl_default_set(
-       vnode_t *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
 }
 
 STATIC int
 posix_acl_default_get(
-       vnode_t *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
 }
 
 STATIC int
 posix_acl_default_remove(
-       struct vnode *vp, char *name, int xflags)
+       bhv_vnode_t *vp, char *name, int xflags)
 {
        return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
 }
 
 STATIC int
 posix_acl_default_exists(
-       vnode_t *vp)
+       bhv_vnode_t *vp)
 {
        return xfs_acl_vhasacl_default(vp);
 }
@@ -2429,21 +2404,18 @@ STATIC struct attrnames *attr_system_names[] =
 
 STATIC int
 attr_generic_set(
-       struct vnode *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
-       int     error;
-
-       VOP_ATTR_SET(vp, name, data, size, xflags, NULL, error);
-       return -error;
+       return -bhv_vop_attr_set(vp, name, data, size, xflags, NULL);
 }
 
 STATIC int
 attr_generic_get(
-       struct vnode *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        int     error, asize = size;
 
-       VOP_ATTR_GET(vp, name, data, &asize, xflags, NULL, error);
+       error = bhv_vop_attr_get(vp, name, data, &asize, xflags, NULL);
        if (!error)
                return asize;
        return -error;
@@ -2451,12 +2423,9 @@ attr_generic_get(
 
 STATIC int
 attr_generic_remove(
-       struct vnode *vp, char *name, int xflags)
+       bhv_vnode_t *vp, char *name, int xflags)
 {
-       int     error;
-
-       VOP_ATTR_REMOVE(vp, name, xflags, NULL, error);
-       return -error;
+       return -bhv_vop_attr_remove(vp, name, xflags, NULL);
 }
 
 STATIC int
@@ -2484,7 +2453,7 @@ attr_generic_listadd(
 
 STATIC int
 attr_system_list(
-       struct vnode            *vp,
+       bhv_vnode_t             *vp,
        void                    *data,
        size_t                  size,
        ssize_t                 *result)
@@ -2506,12 +2475,12 @@ attr_system_list(
 
 int
 attr_generic_list(
-       struct vnode *vp, void *data, size_t size, int xflags, ssize_t *result)
+       bhv_vnode_t *vp, void *data, size_t size, int xflags, ssize_t *result)
 {
        attrlist_cursor_kern_t  cursor = { 0 };
        int                     error;
 
-       VOP_ATTR_LIST(vp, data, size, xflags, &cursor, NULL, error);
+       error = bhv_vop_attr_list(vp, data, size, xflags, &cursor, NULL);
        if (error > 0)
                return -error;
        *result = -error;
@@ -2539,10 +2508,10 @@ attr_lookup_namespace(
  */
 STATIC int
 attr_user_capable(
-       struct vnode    *vp,
+       bhv_vnode_t     *vp,
        cred_t          *cred)
 {
-       struct inode    *inode = LINVFS_GET_IP(vp);
+       struct inode    *inode = vn_to_inode(vp);
 
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
                return -EPERM;
@@ -2557,10 +2526,10 @@ attr_user_capable(
 
 STATIC int
 attr_trusted_capable(
-       struct vnode    *vp,
+       bhv_vnode_t     *vp,
        cred_t          *cred)
 {
-       struct inode    *inode = LINVFS_GET_IP(vp);
+       struct inode    *inode = vn_to_inode(vp);
 
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
                return -EPERM;
@@ -2571,7 +2540,7 @@ attr_trusted_capable(
 
 STATIC int
 attr_secure_capable(
-       struct vnode    *vp,
+       bhv_vnode_t     *vp,
        cred_t          *cred)
 {
        return -ENOSECURITY;
@@ -2579,7 +2548,7 @@ attr_secure_capable(
 
 STATIC int
 attr_system_set(
-       struct vnode *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        attrnames_t     *namesp;
        int             error;
@@ -2598,7 +2567,7 @@ attr_system_set(
 
 STATIC int
 attr_system_get(
-       struct vnode *vp, char *name, void *data, size_t size, int xflags)
+       bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
 {
        attrnames_t     *namesp;
 
@@ -2610,7 +2579,7 @@ attr_system_get(
 
 STATIC int
 attr_system_remove(
-       struct vnode *vp, char *name, int xflags)
+       bhv_vnode_t *vp, char *name, int xflags)
 {
        attrnames_t     *namesp;