Skip to content

Commit 7ac512a

Browse files
dhowellstorvalds
authored andcommitted
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>
1 parent 91af708 commit 7ac512a

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎fs/cachefiles/security.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static int cachefiles_check_cache_dir(struct cachefiles_cache *cache,
7777
/*
7878
* check the security details of the on-disk cache
7979
* - 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
8082
*/
8183
int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
8284
struct dentry *root,
@@ -99,6 +101,8 @@ int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
99101
* which create files */
100102
ret = set_create_files_as(new, root->d_inode);
101103
if (ret < 0) {
104+
abort_creds(new);
105+
cachefiles_begin_secure(cache, _saved_cred);
102106
_leave(" = %d [cfa]", ret);
103107
return ret;
104108
}

0 commit comments

Comments
 (0)