History

Merge tag 'lsm-pr-20260615' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm

Pull lsm update from Paul Moore: "A single LSM update the security_inode_listsecurity() hook to be able to leverage the xattr_list_one() helper function. We wanted to do this for a while, but we needed to fixup the callers in the NFS code first. With the NFS code changes shipping in Linux v7.0 and no one complaining, it seemed a good time to complete the shift" * tag 'lsm-pr-20260615' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm: security,fs,nfs,net: update security_inode_listsecurity() interface

Linus Torvalds committed 5 months ago

Commit 87599bd2 parents 5b33fc6 f71ece97 files · +29 −37Browse files

Unified · Split

7 files
  1. fs/nfs/nfs4proc.c +2 −5
  2. fs/xattr.c +7 −4
  3. include/linux/lsm_hook_defs.h +2 −2
  4. include/linux/security.h +3 −2
  5. security/security.c +8 −8
  6. security/selinux/hooks.c +3 −7
  7. security/smack/smack_lsm.c +4 −9
fs/nfs/nfs4proc.c+2−5
@@ -10564,13 +10564,10 @@ static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) · 10563 unmodified lines
1056410564 left -= error;
1056510565 }
1056610566
10567− error2 = security_inode_listsecurity(d_inode(dentry), list, left);
10567+ error2 = security_inode_listsecurity(d_inode(dentry), &list, &left);
1056810568 if (error2 < 0)
1056910569 return error2;
10570− if (list) {
10571− list += error2;
10572− left -= error2;
10573− }
10570+ error2 = size - error - left;
1057410571
1057510572 error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, left);
1057610573 if (error3 < 0)
fs/xattr.c+7−4
@@ -515,9 +515,12 @@ vfs_listxattr(struct dentry *dentry, char *list, size_t size) · 514 unmodified lines
515515 if (inode->i_op->listxattr) {
516516 error = inode->i_op->listxattr(dentry, list, size);
517517 } else {
518− error = security_inode_listsecurity(inode, list, size);
519− if (size && error > size)
520− error = -ERANGE;
518+ ssize_t remaining = size;
519+
520+ error = security_inode_listsecurity(inode, &list, &remaining);
521+ if (error)
522+ return error;
523+ error = size - remaining;
521524 }
522525 return error;
523526 }
@@ -1612,7 +1615,7 @@ ssize_t simple_xattr_list(struct inode *inode, struct list_head *xattrs, · 1088 unmodified lines
16121615 if (err)
16131616 return err;
16141617
1615− err = security_inode_listsecurity(inode, buffer, remaining_size);
1618+ err = security_inode_listsecurity(inode, &buffer, &remaining_size);
16161619 if (err < 0)
16171620 return err;
16181621
include/linux/lsm_hook_defs.h+2−2
@@ -176,8 +176,8 @@ LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct mnt_idmap *idmap, · 175 unmodified lines
176176 struct inode *inode, const char *name, void **buffer, bool alloc)
177177 LSM_HOOK(int, -EOPNOTSUPP, inode_setsecurity, struct inode *inode,
178178 const char *name, const void *value, size_t size, int flags)
179−LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer,
180− size_t buffer_size)
179+LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char **buffer,
180+ ssize_t *remaining_size)
181181 LSM_HOOK(void, LSM_RET_VOID, inode_getlsmprop, struct inode *inode,
182182 struct lsm_prop *prop)
183183 LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new)
include/linux/security.h+3−2
@@ -459,7 +459,7 @@ int security_inode_getsecurity(struct mnt_idmap *idmap, · 458 unmodified lines
459459 struct inode *inode, const char *name,
460460 void **buffer, bool alloc);
461461 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
462−int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
462+int security_inode_listsecurity(struct inode *inode, char **buffer, ssize_t *remaining_size);
463463 void security_inode_getlsmprop(struct inode *inode, struct lsm_prop *prop);
464464 int security_inode_copy_up(struct dentry *src, struct cred **new);
465465 int security_inode_copy_up_xattr(struct dentry *src, const char *name);
@@ -1097,7 +1097,8 @@ static inline int security_inode_setsecurity(struct inode *inode, const char *na · 631 unmodified lines
10971097 return -EOPNOTSUPP;
10981098 }
10991099
1100−static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
1100+static inline int security_inode_listsecurity(struct inode *inode,
1101+ char **buffer, ssize_t *remaining_size)
11011102 {
11021103 return 0;
11031104 }
security/security.c+8−8
@@ -2258,22 +2258,22 @@ int security_inode_setsecurity(struct inode *inode, const char *name, · 2257 unmodified lines
22582258 /**
22592259 * security_inode_listsecurity() - List the xattr security label names
22602260 * @inode: inode
2261− * @buffer: buffer
2262− * @buffer_size: size of buffer
2261+ * @buffer: pointer to buffer
2262+ * @remaining_size: pointer to remaining size of buffer
22632263 *
22642264 * Copy the extended attribute names for the security labels associated with
2265− * @inode into @buffer. The maximum size of @buffer is specified by
2266− * @buffer_size. @buffer may be NULL to request the size of the buffer
2267− * required.
2265+ * @inode into *(@buffer). The remaining size of @buffer is specified by
2266+ * *(@remaining_size). *(@buffer) may be NULL to request the size of the
2267+ * buffer required. Updates *(@buffer) and *(@remaining_size).
22682268 *
2269− * Return: Returns number of bytes used/required on success.
2269+ * Return: Returns 0 on success, or -errno on failure.
22702270 */
22712271 int security_inode_listsecurity(struct inode *inode,
2272− char *buffer, size_t buffer_size)
2272+ char **buffer, ssize_t *remaining_size)
22732273 {
22742274 if (unlikely(IS_PRIVATE(inode)))
22752275 return 0;
2276− return call_int_hook(inode_listsecurity, inode, buffer, buffer_size);
2276+ return call_int_hook(inode_listsecurity, inode, buffer, remaining_size);
22772277 }
22782278 EXPORT_SYMBOL(security_inode_listsecurity);
22792279
security/selinux/hooks.c+3−7
@@ -3680,16 +3680,12 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name, · 3679 unmodified lines
36803680 return 0;
36813681 }
36823682
3683−static int selinux_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
3683+static int selinux_inode_listsecurity(struct inode *inode, char **buffer,
3684+ ssize_t *remaining_size)
36843685 {
3685− const int len = sizeof(XATTR_NAME_SELINUX);
3686−
36873686 if (!selinux_initialized())
36883687 return 0;
3689−
3690− if (buffer && len <= buffer_size)
3691− memcpy(buffer, XATTR_NAME_SELINUX, len);
3692− return len;
3688+ return xattr_list_one(buffer, remaining_size, XATTR_NAME_SELINUX);
36933689 }
36943690
36953691 static void selinux_inode_getlsmprop(struct inode *inode, struct lsm_prop *prop)
security/smack/smack_lsm.c+4−9
@@ -1665,17 +1665,12 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap, · 1664 unmodified lines
16651665 * smack_inode_listsecurity - list the Smack attributes
16661666 * @inode: the object
16671667 * @buffer: where they go
1668− * @buffer_size: size of buffer
1668+ * @remaining_size: size of buffer
16691669 */
1670−static int smack_inode_listsecurity(struct inode *inode, char *buffer,
1671− size_t buffer_size)
1670+static int smack_inode_listsecurity(struct inode *inode, char **buffer,
1671+ ssize_t *remaining_size)
16721672 {
1673− int len = sizeof(XATTR_NAME_SMACK);
1674−
1675− if (buffer != NULL && len <= buffer_size)
1676− memcpy(buffer, XATTR_NAME_SMACK, len);
1677−
1678− return len;
1673+ return xattr_list_one(buffer, remaining_size, XATTR_NAME_SMACK);
16791674 }
16801675
16811676 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t