Skip to content

Commit a3fe8d8

Browse files
committed
xattr: make the xattr array itself const
As it is currently declared, the xattr_handler structs are const but the array containing their pointers is not. This patch makes it so that fs modules can place them in .rodata, which makes it harder for accidental/malicious modifications at runtime. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent a7135d1 commit a3fe8d8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

fs/xattr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ strcmp_prefix(const char *a, const char *a_prefix)
5656
static const struct xattr_handler *
5757
xattr_resolve_name(struct inode *inode, const char **name)
5858
{
59-
const struct xattr_handler **handlers = inode->i_sb->s_xattr;
59+
const struct xattr_handler *const *handlers = inode->i_sb->s_xattr;
6060
const struct xattr_handler *handler;
6161

6262
if (!(inode->i_opflags & IOP_XATTR)) {
@@ -162,7 +162,7 @@ xattr_permission(struct mnt_idmap *idmap, struct inode *inode,
162162
int
163163
xattr_supports_user_prefix(struct inode *inode)
164164
{
165-
const struct xattr_handler **handlers = inode->i_sb->s_xattr;
165+
const struct xattr_handler *const *handlers = inode->i_sb->s_xattr;
166166
const struct xattr_handler *handler;
167167

168168
if (!(inode->i_opflags & IOP_XATTR)) {
@@ -999,7 +999,7 @@ int xattr_list_one(char **buffer, ssize_t *remaining_size, const char *name)
999999
ssize_t
10001000
generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
10011001
{
1002-
const struct xattr_handler *handler, **handlers = dentry->d_sb->s_xattr;
1002+
const struct xattr_handler *handler, *const *handlers = dentry->d_sb->s_xattr;
10031003
ssize_t remaining_size = buffer_size;
10041004
int err = 0;
10051005

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ struct super_block {
12061206
#ifdef CONFIG_SECURITY
12071207
void *s_security;
12081208
#endif
1209-
const struct xattr_handler **s_xattr;
1209+
const struct xattr_handler *const *s_xattr;
12101210
#ifdef CONFIG_FS_ENCRYPTION
12111211
const struct fscrypt_operations *s_cop;
12121212
struct fscrypt_keyring *s_master_keys; /* master crypto keys in use */

0 commit comments

Comments
 (0)