提交 8cf0a1bc 编写于 作者: G Gaosheng Cui 提交者: Paul Moore

capabilities: fix potential memleak on error path from vfs_getxattr_alloc()

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: 8db6c34f ("Introduce v3 namespaced file capabilities")
Signed-off-by: NGaosheng Cui <cuigaosheng1@huawei.com>
Acked-by: NSerge Hallyn <serge@hallyn.com>
[PM: subject line and backtrace tweaks]
Signed-off-by: NPaul Moore <paul@paul-moore.com>
上级 9abf2313
...@@ -401,8 +401,10 @@ int cap_inode_getsecurity(struct user_namespace *mnt_userns, ...@@ -401,8 +401,10 @@ int cap_inode_getsecurity(struct user_namespace *mnt_userns,
&tmpbuf, size, GFP_NOFS); &tmpbuf, size, GFP_NOFS);
dput(dentry); dput(dentry);
if (ret < 0 || !tmpbuf) if (ret < 0 || !tmpbuf) {
return ret; size = ret;
goto out_free;
}
fs_ns = inode->i_sb->s_user_ns; fs_ns = inode->i_sb->s_user_ns;
cap = (struct vfs_cap_data *) tmpbuf; cap = (struct vfs_cap_data *) tmpbuf;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册