lkml.org 
[lkml]   [2014]   [Feb]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5/8] ima: skip memory allocation for empty files
    Date
    Memory allocation is unnecessary for empty files.
    This patch finalize the hash without memory allocation.

    Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
    ---
    security/integrity/ima/ima_crypto.c | 20 ++++++++++++--------
    1 file changed, 12 insertions(+), 8 deletions(-)

    diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
    index d257e36..1bde8e6 100644
    --- a/security/integrity/ima/ima_crypto.c
    +++ b/security/integrity/ima/ima_crypto.c
    @@ -87,16 +87,20 @@ static int ima_calc_file_hash_tfm(struct file *file,
    if (rc != 0)
    return rc;

    - rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
    - if (!rbuf) {
    - rc = -ENOMEM;
    + i_size = i_size_read(file_inode(file));
    +
    + if (i_size == 0)
    goto out;
    - }
    +
    + rbuf = kzalloc(PAGE_SIZE, GFP_KERNEL);
    + if (!rbuf)
    + return -ENOMEM;
    +
    if (!(file->f_mode & FMODE_READ)) {
    file->f_mode |= FMODE_READ;
    read = 1;
    }
    - i_size = i_size_read(file_inode(file));
    +
    while (offset < i_size) {
    int rbuf_len;

    @@ -113,12 +117,12 @@ static int ima_calc_file_hash_tfm(struct file *file,
    if (rc)
    break;
    }
    - kfree(rbuf);
    - if (!rc)
    - rc = crypto_shash_final(&desc.shash, hash->digest);
    if (read)
    file->f_mode &= ~FMODE_READ;
    + kfree(rbuf);
    out:
    + if (!rc)
    + rc = crypto_shash_final(&desc.shash, hash->digest);
    return rc;
    }

    --
    1.8.3.2


    \
     
     \ /
      Last update: 2014-02-28 16:41    [W:2.963 / U:0.000 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site