[PATCH v2 -next 0/2] security: Fix call security_backing_file_free second time
Cai Xinchen
caixinchen1 at huawei.com
Tue Jul 7 08:06:13 UTC 2026
v2: Move the call_void_hook(backing_file_free, ...) call in
security_backing_file_free() into the if-statment true block before we
set the backing file's LSM blob pointer to NULL and free the LSM blob.
I found the following path:
alloc_empty_backing-file
init_file(&ff->file, xxx)
-> file_ref_init(&f->f_ref, 1); // only 1
error = init_backing_file
-> security_backing_file_alloc
-> rc = call_int_hook(backing_file_alloc, ...)
if (unlikely(rc))
security_backing_file_free(backing_file); // first call
if (unlikely(error)) {
fput(&ff->file);
-> if (unlikely(file_ref_put(&file->f_ref))) // zero
__fput_deferred(file);
-> ____fput -> __fput -> file_free(file);
-> backing_file_free(backing_file(f));
-> security_backing_file_free(&ff->file); // second call
Currently, only SELinux has the lsm backing_file_alloc hook, and it always
return 0. When security_backing_file_free is called for the first time,
the blobs pointer is set to NULL. Therefore, double free will not occur in
the code.
Cai Xinchen (2):
security: Delete dumplicate assignment
security: Fix call security_backing_file_free second time
security/lsm_init.c | 1 -
security/security.c | 3 +--
2 files changed, 1 insertion(+), 3 deletions(-)
--
2.34.1
More information about the Linux-security-module-archive
mailing list