Skip to content

Commit 66cd757

Browse files
Mark Salyzyncyberknight777
authored andcommitted
FROMLIST: Add flags option to get xattr method paired to __vfs_getxattr
Add a flag option to get xattr method that could have a bit flag of XATTR_NOSECURITY passed to it. XATTR_NOSECURITY is generally then set in the __vfs_getxattr path when called by security infrastructure. This handles the case of a union filesystem driver that is being requested by the security layer to report back the xattr data. For the use case where access is to be blocked by the security layer. The path then could be security(dentry) -> __vfs_getxattr(dentry...XATTR_NOSECURITY) -> handler->get(dentry...XATTR_NOSECURITY) -> __vfs_getxattr(lower_dentry...XATTR_NOSECURITY) -> lower_handler->get(lower_dentry...XATTR_NOSECURITY) which would report back through the chain data and success as expected, the logging security layer at the top would have the data to determine the access permissions and report back the target context that was blocked. Without the get handler flag, the path on a union filesystem would be the errant security(dentry) -> __vfs_getxattr(dentry) -> handler->get(dentry) -> vfs_getxattr(lower_dentry) -> nested -> security(lower_dentry, log off) -> lower_handler->get(lower_dentry) which would report back through the chain no data, and -EACCES. For selinux for both cases, this would translate to a correctly determined blocked access. In the first case with this change a correct avc log would be reported, in the second legacy case an incorrect avc log would be reported against an uninitialized u:object_r:unlabeled:s0 context making the logs cosmetically useless for audit2allow. This patch series is inert and is the wide-spread addition of the flags option for xattr functions, and a replacement of __vfs_getxattr with __vfs_getxattr(...XATTR_NOSECURITY). Signed-off-by: Mark Salyzyn <salyzyn@android.com> Reviewed-by: Jan Kara <jack@suse.cz> Acked-by: Jan Kara <jack@suse.cz> Acked-by: Jeff Layton <jlayton@kernel.org> Acked-by: David Sterba <dsterba@suse.com> Acked-by: Darrick J. Wong <darrick.wong@oracle.com> Acked-by: Mike Marshall <hubcap@omnibond.com> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: linux-kernel@vger.kernel.org Cc: kernel-team@android.com Cc: linux-security-module@vger.kernel.org (cherry picked from (rejected from archive because of too many recipients)) Signed-off-by: Mark Salyzyn <salyzyn@google.com> Bug: 133515582 Bug: 136124883 Bug: 129319403 Change-Id: Iabbb8771939d5f66667a26bb23ddf4c562c349a1 Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com> Signed-off-by: Jebaitedneko <Jebaitedneko@gmail.com>
1 parent 4fd5f95 commit 66cd757

48 files changed

Lines changed: 121 additions & 84 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

fs/9p/acl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
214214

215215
static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
216216
struct dentry *dentry, struct inode *inode,
217-
const char *name, void *buffer, size_t size)
217+
const char *name, void *buffer, size_t size,
218+
int flags)
218219
{
219220
struct v9fs_session_info *v9ses;
220221
struct posix_acl *acl;

fs/9p/xattr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
139139

140140
static int v9fs_xattr_handler_get(const struct xattr_handler *handler,
141141
struct dentry *dentry, struct inode *inode,
142-
const char *name, void *buffer, size_t size)
142+
const char *name, void *buffer, size_t size,
143+
int flags)
143144
{
144145
const char *full_name = xattr_full_name(handler, name);
145146

fs/btrfs/xattr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
377377

378378
static int btrfs_xattr_handler_get(const struct xattr_handler *handler,
379379
struct dentry *unused, struct inode *inode,
380-
const char *name, void *buffer, size_t size)
380+
const char *name, void *buffer, size_t size,
381+
int flags)
381382
{
382383
name = xattr_full_name(handler, name);
383384
return __btrfs_getxattr(inode, name, buffer, size);

fs/ceph/xattr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,8 @@ int __ceph_setxattr(struct inode *inode, const char *name,
10851085

10861086
static int ceph_get_xattr_handler(const struct xattr_handler *handler,
10871087
struct dentry *dentry, struct inode *inode,
1088-
const char *name, void *value, size_t size)
1088+
const char *name, void *value, size_t size,
1089+
int flags)
10891090
{
10901091
if (!ceph_is_valid_xattr(name))
10911092
return -EOPNOTSUPP;

fs/cifs/xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int cifs_creation_time_get(struct dentry *dentry, struct inode *inode,
193193

194194
static int cifs_xattr_get(const struct xattr_handler *handler,
195195
struct dentry *dentry, struct inode *inode,
196-
const char *name, void *value, size_t size)
196+
const char *name, void *value, size_t size, int flags)
197197
{
198198
ssize_t rc = -EOPNOTSUPP;
199199
unsigned int xid;

fs/ecryptfs/inode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,8 @@ ecryptfs_getxattr_lower(struct dentry *lower_dentry, struct inode *lower_inode,
10391039
goto out;
10401040
}
10411041
inode_lock(lower_inode);
1042-
rc = __vfs_getxattr(lower_dentry, lower_inode, name, value, size);
1042+
rc = __vfs_getxattr(lower_dentry, lower_inode, name, value, size,
1043+
XATTR_NOSECURITY);
10431044
inode_unlock(lower_inode);
10441045
out:
10451046
return rc;
@@ -1124,7 +1125,8 @@ const struct inode_operations ecryptfs_main_iops = {
11241125

11251126
static int ecryptfs_xattr_get(const struct xattr_handler *handler,
11261127
struct dentry *dentry, struct inode *inode,
1127-
const char *name, void *buffer, size_t size)
1128+
const char *name, void *buffer, size_t size,
1129+
int flags)
11281130
{
11291131
return ecryptfs_getxattr(dentry, inode, name, buffer, size);
11301132
}

fs/ecryptfs/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
438438
}
439439
inode_lock(lower_inode);
440440
size = __vfs_getxattr(lower_dentry, lower_inode, ECRYPTFS_XATTR_NAME,
441-
xattr_virt, PAGE_SIZE);
441+
xattr_virt, PAGE_SIZE, XATTR_NOSECURITY);
442442
if (size < 0)
443443
size = 8;
444444
put_unaligned_be64(i_size_read(ecryptfs_inode), xattr_virt);

fs/ext2/xattr_security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
static int
1212
ext2_xattr_security_get(const struct xattr_handler *handler,
1313
struct dentry *unused, struct inode *inode,
14-
const char *name, void *buffer, size_t size)
14+
const char *name, void *buffer, size_t size, int flags)
1515
{
1616
return ext2_xattr_get(inode, EXT2_XATTR_INDEX_SECURITY, name,
1717
buffer, size);

fs/ext2/xattr_trusted.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ext2_xattr_trusted_list(struct dentry *dentry)
1818
static int
1919
ext2_xattr_trusted_get(const struct xattr_handler *handler,
2020
struct dentry *unused, struct inode *inode,
21-
const char *name, void *buffer, size_t size)
21+
const char *name, void *buffer, size_t size, int flags)
2222
{
2323
return ext2_xattr_get(inode, EXT2_XATTR_INDEX_TRUSTED, name,
2424
buffer, size);

fs/ext2/xattr_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ext2_xattr_user_list(struct dentry *dentry)
2020
static int
2121
ext2_xattr_user_get(const struct xattr_handler *handler,
2222
struct dentry *unused, struct inode *inode,
23-
const char *name, void *buffer, size_t size)
23+
const char *name, void *buffer, size_t size, int flags)
2424
{
2525
if (!test_opt(inode->i_sb, XATTR_USER))
2626
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)