From f61b34ee2c98d2b10e8fd6d1dff8f9984763ae10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Mon, 20 Aug 2012 12:45:21 +0200 Subject: [PATCH] Ignored permissions when listing xattrs for special files Special files (FIFOs, SOCKETs, etc.) are not allowed to have user extended attributes. When listing their extended attributes, return none without checking whether the calling process is allowed to access these files. --- src/lowntfs-3g.c | 36 ++++++++++++++++++++++++++++++++++-- src/ntfs-3g.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 0c9af18c..561a2f29 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -2743,8 +2743,11 @@ static void ntfs_fuse_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) ret = -errno; goto out; } + /* Return with no result for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) + goto exit; + /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) - /* file must be readable */ if (!ntfs_allowed_access(&security,ni,S_IREAD)) { ret = -EACCES; goto exit; @@ -2890,8 +2893,13 @@ static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, res = -errno; goto out; } + /* Return with no result for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + res = -ENODATA; + goto exit; + } + /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) - /* file must be readable */ if (!ntfs_allowed_access(&security, ni, S_IREAD)) { res = -errno; goto exit; @@ -3074,12 +3082,24 @@ static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, } break; default : + /* User xattr not allowed for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + res = -EPERM; + goto exit; + } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } +#else + /* User xattr not allowed for symlinks, fifo, etc. */ + if ((namespace == XATTRNS_USER) + && (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { + res = -EPERM; + goto exit; + } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if ((lename_len == -1) @@ -3296,12 +3316,24 @@ static void ntfs_fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *na } break; default : + /* User xattr not allowed for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + res = -EPERM; + goto exit; + } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } +#else + /* User xattr not allowed for symlinks, fifo, etc. */ + if ((namespace == XATTRNS_USER) + && (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { + res = -EPERM; + goto exit; + } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if (lename_len == -1) { diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index d6974a96..b2c2bb36 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -2604,8 +2604,11 @@ static int ntfs_fuse_listxattr(const char *path, char *list, size_t size) ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; + /* Return with no result for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) + goto exit; + /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) - /* file must be readable */ if (!ntfs_allowed_access(&security,ni,S_IREAD)) { ret = -EACCES; goto exit; @@ -2803,8 +2806,13 @@ static int ntfs_fuse_getxattr(const char *path, const char *name, ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; + /* Return with no result for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + res = -ENODATA; + goto exit; + } + /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) - /* file must be readable */ if (!ntfs_allowed_access(&security, ni, S_IREAD)) { res = -errno; goto exit; @@ -2966,12 +2974,24 @@ static int ntfs_fuse_setxattr(const char *path, const char *name, } break; default : + /* User xattr not allowed for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + res = -EPERM; + goto exit; + } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } +#else + /* User xattr not allowed for symlinks, fifo, etc. */ + if ((namespace == XATTRNS_USER) + && (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { + res = -EPERM; + goto exit; + } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if ((lename_len == -1) @@ -3180,12 +3200,24 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) } break; default : + /* User xattr not allowed for symlinks, fifo, etc. */ + if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + res = -EPERM; + goto exit; + } if (!ntfs_allowed_access(&security,ni,S_IWRITE)) { res = -EACCES; goto exit; } break; } +#else + /* User xattr not allowed for symlinks, fifo, etc. */ + if ((namespace == XATTRNS_USER) + && (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { + res = -EPERM; + goto exit; + } #endif lename_len = fix_xattr_prefix(name, namespace, &lename); if (lename_len == -1) {