LCOV - code coverage report
Current view: top level - fs/cachefiles - security.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 0 33 0.0 %
Date: 2020-09-30 20:25:40 Functions: 0 3 0.0 %
Branches: 0 16 0.0 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0-or-later
       2                 :            : /* CacheFiles security management
       3                 :            :  *
       4                 :            :  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
       5                 :            :  * Written by David Howells (dhowells@redhat.com)
       6                 :            :  */
       7                 :            : 
       8                 :            : #include <linux/fs.h>
       9                 :            : #include <linux/cred.h>
      10                 :            : #include "internal.h"
      11                 :            : 
      12                 :            : /*
      13                 :            :  * determine the security context within which we access the cache from within
      14                 :            :  * the kernel
      15                 :            :  */
      16                 :          0 : int cachefiles_get_security_ID(struct cachefiles_cache *cache)
      17                 :            : {
      18                 :            :         struct cred *new;
      19                 :            :         int ret;
      20                 :            : 
      21                 :            :         _enter("{%s}", cache->secctx);
      22                 :            : 
      23                 :          0 :         new = prepare_kernel_cred(current);
      24         [ #  # ]:          0 :         if (!new) {
      25                 :            :                 ret = -ENOMEM;
      26                 :            :                 goto error;
      27                 :            :         }
      28                 :            : 
      29         [ #  # ]:          0 :         if (cache->secctx) {
      30                 :          0 :                 ret = set_security_override_from_ctx(new, cache->secctx);
      31         [ #  # ]:          0 :                 if (ret < 0) {
      32                 :          0 :                         put_cred(new);
      33                 :          0 :                         pr_err("Security denies permission to nominate security context: error %d\n",
      34                 :            :                                ret);
      35                 :          0 :                         goto error;
      36                 :            :                 }
      37                 :            :         }
      38                 :            : 
      39                 :          0 :         cache->cache_cred = new;
      40                 :            :         ret = 0;
      41                 :            : error:
      42                 :            :         _leave(" = %d", ret);
      43                 :          0 :         return ret;
      44                 :            : }
      45                 :            : 
      46                 :            : /*
      47                 :            :  * see if mkdir and create can be performed in the root directory
      48                 :            :  */
      49                 :          0 : static int cachefiles_check_cache_dir(struct cachefiles_cache *cache,
      50                 :            :                                       struct dentry *root)
      51                 :            : {
      52                 :            :         int ret;
      53                 :            : 
      54                 :          0 :         ret = security_inode_mkdir(d_backing_inode(root), root, 0);
      55         [ #  # ]:          0 :         if (ret < 0) {
      56                 :          0 :                 pr_err("Security denies permission to make dirs: error %d",
      57                 :            :                        ret);
      58                 :          0 :                 return ret;
      59                 :            :         }
      60                 :            : 
      61                 :          0 :         ret = security_inode_create(d_backing_inode(root), root, 0);
      62         [ #  # ]:          0 :         if (ret < 0)
      63                 :          0 :                 pr_err("Security denies permission to create files: error %d",
      64                 :            :                        ret);
      65                 :            : 
      66                 :          0 :         return ret;
      67                 :            : }
      68                 :            : 
      69                 :            : /*
      70                 :            :  * check the security details of the on-disk cache
      71                 :            :  * - must be called with security override in force
      72                 :            :  * - must return with a security override in force - even in the case of an
      73                 :            :  *   error
      74                 :            :  */
      75                 :          0 : int cachefiles_determine_cache_security(struct cachefiles_cache *cache,
      76                 :            :                                         struct dentry *root,
      77                 :            :                                         const struct cred **_saved_cred)
      78                 :            : {
      79                 :            :         struct cred *new;
      80                 :            :         int ret;
      81                 :            : 
      82                 :            :         _enter("");
      83                 :            : 
      84                 :            :         /* duplicate the cache creds for COW (the override is currently in
      85                 :            :          * force, so we can use prepare_creds() to do this) */
      86                 :          0 :         new = prepare_creds();
      87         [ #  # ]:          0 :         if (!new)
      88                 :            :                 return -ENOMEM;
      89                 :            : 
      90                 :          0 :         cachefiles_end_secure(cache, *_saved_cred);
      91                 :            : 
      92                 :            :         /* use the cache root dir's security context as the basis with
      93                 :            :          * which create files */
      94                 :          0 :         ret = set_create_files_as(new, d_backing_inode(root));
      95         [ #  # ]:          0 :         if (ret < 0) {
      96                 :          0 :                 abort_creds(new);
      97                 :            :                 cachefiles_begin_secure(cache, _saved_cred);
      98                 :            :                 _leave(" = %d [cfa]", ret);
      99                 :          0 :                 return ret;
     100                 :            :         }
     101                 :            : 
     102                 :          0 :         put_cred(cache->cache_cred);
     103                 :          0 :         cache->cache_cred = new;
     104                 :            : 
     105                 :            :         cachefiles_begin_secure(cache, _saved_cred);
     106                 :          0 :         ret = cachefiles_check_cache_dir(cache, root);
     107                 :            : 
     108         [ #  # ]:          0 :         if (ret == -EOPNOTSUPP)
     109                 :            :                 ret = 0;
     110                 :            :         _leave(" = %d", ret);
     111                 :          0 :         return ret;
     112                 :            : }

Generated by: LCOV version 1.14