]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ima: provide flag to identify new empty files
authorDmitry Kasatkin <d.kasatkin@samsung.com>
Fri, 27 Jun 2014 15:04:27 +0000 (18:04 +0300)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Mon, 8 Sep 2014 21:38:57 +0000 (17:38 -0400)
On ima_file_free(), newly created empty files are not labeled with
an initial security.ima value, because the iversion did not change.
Commit dff6efc "fs: fix iversion handling" introduced a change in
iversion behavior.  To verify this change use the shell command:

  $ (exec >foo)
  $ getfattr -h -e hex -d -m security foo

This patch defines the IMA_NEW_FILE flag.  The flag is initially
set, when IMA detects that a new file is created, and subsequently
checked on the ima_file_free() hook to set the initial security.ima
value.

Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: <stable@vger.kernel.org> 3.14+
security/integrity/ima/ima_appraise.c
security/integrity/ima/ima_main.c
security/integrity/integrity.h

index 86bfd5c5df85e0bec07bc6be5e7ab58bd98c945c..a4605d67724858a7e7773e2fc196bd599625cf57 100644 (file)
@@ -202,8 +202,11 @@ int ima_appraise_measurement(int func, struct integrity_iint_cache *iint,
                        goto out;
 
                cause = "missing-hash";
-               status =
-                   (inode->i_size == 0) ? INTEGRITY_PASS : INTEGRITY_NOLABEL;
+               status = INTEGRITY_NOLABEL;
+               if (inode->i_size == 0) {
+                       iint->flags |= IMA_NEW_FILE;
+                       status = INTEGRITY_PASS;
+               }
                goto out;
        }
 
index 2917f980bf3075c3dacff3531cf03d8e4e39e6f6..0a2298f90c9c017bc1e240e026eb5c517aa50a43 100644 (file)
@@ -124,11 +124,13 @@ static void ima_check_last_writer(struct integrity_iint_cache *iint,
                return;
 
        mutex_lock(&inode->i_mutex);
-       if (atomic_read(&inode->i_writecount) == 1 &&
-           iint->version != inode->i_version) {
-               iint->flags &= ~IMA_DONE_MASK;
-               if (iint->flags & IMA_APPRAISE)
-                       ima_update_xattr(iint, file);
+       if (atomic_read(&inode->i_writecount) == 1) {
+               if ((iint->version != inode->i_version) ||
+                   (iint->flags & IMA_NEW_FILE)) {
+                       iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE);
+                       if (iint->flags & IMA_APPRAISE)
+                               ima_update_xattr(iint, file);
+               }
        }
        mutex_unlock(&inode->i_mutex);
 }
index 19b8e314ca964efdff3cf7ddf30851f9f0e29d80..904e68abd49e21eee2558fdc9c82602f5b944baf 100644 (file)
@@ -31,6 +31,7 @@
 #define IMA_DIGSIG             0x01000000
 #define IMA_DIGSIG_REQUIRED    0x02000000
 #define IMA_PERMIT_DIRECTIO    0x04000000
+#define IMA_NEW_FILE           0x08000000
 
 #define IMA_DO_MASK            (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \
                                 IMA_APPRAISE_SUBMASK)