Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

CacheFiles: Fix error handling in cachefiles_determine_cache_security()

cachefiles_determine_cache_security() is expected to return with a
security override in place. However, if set_create_files_as() fails, we
fail to do this. In this case, we should just reinstate the security
override that was set by the caller.

Furthermore, if set_create_files_as() fails, we should dispose of the
new credentials we were in the process of creating.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Howells and committed by
Linus Torvalds
7ac512aa 91af7081

+4
+4
fs/cachefiles/security.c
··· 77 77 /* 78 78 * check the security details of the on-disk cache 79 79 * - must be called with security override in force 80 + * - must return with a security override in force - even in the case of an 81 + * error 80 82 */ 81 83 int cachefiles_determine_cache_security(struct cachefiles_cache *cache, 82 84 struct dentry *root, ··· 101 99 * which create files */ 102 100 ret = set_create_files_as(new, root->d_inode); 103 101 if (ret < 0) { 102 + abort_creds(new); 103 + cachefiles_begin_secure(cache, _saved_cred); 104 104 _leave(" = %d [cfa]", ret); 105 105 return ret; 106 106 }