linux-stable/security
Gaosheng Cui 7480aeff00 capabilities: fix potential memleak on error path from vfs_getxattr_alloc()
commit 8cf0a1bc12 upstream.

In cap_inode_getsecurity(), we will use vfs_getxattr_alloc() to
complete the memory allocation of tmpbuf, if we have completed
the memory allocation of tmpbuf, but failed to call handler->get(...),
there will be a memleak in below logic:

  |-- ret = (int)vfs_getxattr_alloc(mnt_userns, ...)
    |           /* ^^^ alloc for tmpbuf */
    |-- value = krealloc(*xattr_value, error + 1, flags)
    |           /* ^^^ alloc memory */
    |-- error = handler->get(handler, ...)
    |           /* error! */
    |-- *xattr_value = value
    |           /* xattr_value is &tmpbuf (memory leak!) */

So we will try to free(tmpbuf) after vfs_getxattr_alloc() fails to fix it.

Cc: stable@vger.kernel.org
Fixes: 8db6c34f1d ("Introduce v3 namespaced file capabilities")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Acked-by: Serge Hallyn <serge@hallyn.com>
[PM: subject line and backtrace tweaks]
Signed-off-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-11-10 18:17:33 +01:00
..
apparmor apparmor: correct config reference to intended one 2022-07-20 13:22:19 -07:00
bpf bpf: Implement task local storage 2020-11-06 08:08:37 -08:00
integrity ima: fix blocking of security.ima xattrs of unsupported algorithms 2022-10-21 12:37:58 +02:00
keys KEYS: trusted: tpm2: Fix migratable logic 2022-06-08 14:12:13 +03:00
landlock landlock: Fix file reparenting without explicit LANDLOCK_ACCESS_FS_REFER 2022-09-02 15:29:08 +02:00
loadpin LoadPin: Fix Kconfig doc about format of file with verity digests 2022-10-21 12:37:44 +02:00
lockdown Merge branch 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security 2020-06-02 17:36:24 -07:00
safesetid LSM: SafeSetID: Add setgroups() security policy handling 2022-07-15 18:24:42 +00:00
selinux selinux: enable use of both GFP_KERNEL and GFP_ATOMIC in convert_context() 2022-10-29 10:08:29 +02:00
smack Smack: Provide read control for io_uring_cmd 2022-08-26 14:56:35 -04:00
tomoyo LSM: Remove double path_rename hook calls for RENAME_EXCHANGE 2022-05-23 13:27:58 +02:00
yama task_work: cleanup notification modes 2020-10-17 15:05:30 -06:00
Kconfig x86/retbleed: Add fine grained Kconfig knobs 2022-06-29 17:43:41 +02:00
Kconfig.hardening hardening: Remove Clang's enable flag for -ftrivial-auto-var-init=zero 2022-10-12 09:39:04 +02:00
Makefile security: remove unneeded subdir-$(CONFIG_...) 2021-09-03 08:17:20 +09:00
commoncap.c capabilities: fix potential memleak on error path from vfs_getxattr_alloc() 2022-11-10 18:17:33 +01:00
device_cgroup.c bpf: Make BPF_PROG_RUN_ARRAY return -err instead of allow boolean 2022-01-19 12:51:30 -08:00
inode.c Merge branch 'work.mount0' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2019-07-19 10:42:02 -07:00
lsm_audit.c selinux: log anon inode class name 2022-05-03 16:09:03 -04:00
min_addr.c sysctl: pass kernel pointers to ->proc_handler 2020-04-27 02:07:40 -04:00
security.c lsm,io_uring: add LSM hooks for the new uring_cmd file op 2022-08-26 11:19:43 -04:00