In the Linux kernel, the following vulnerability has been resolved:
capabilities: fix potential memleak on error path from vfsgetxattralloc()
In capinodegetsecurity(), we will use vfsgetxattralloc() 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)vfsgetxattralloc(mntuserns, ...) | /* ^^^ alloc for tmpbuf */ |-- value = krealloc(*xattrvalue, 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 vfsgetxattralloc() fails to fix it.
[PM: subject line and backtrace tweaks]